|
| 1 | +using Test |
| 2 | +using MPI |
| 3 | +using SafePETSc |
| 4 | +SafePETSc.Init() |
| 5 | +using PETSc |
| 6 | +using SafePETSc.SafeMPI |
| 7 | +include(joinpath(@__DIR__, "mpi_test_harness.jl")) |
| 8 | +using .MPITestHarness: QuietTestSet |
| 9 | + |
| 10 | +comm = MPI.COMM_WORLD |
| 11 | +rank = MPI.Comm_rank(comm) |
| 12 | +nranks = MPI.Comm_size(comm) |
| 13 | + |
| 14 | +if rank == 0 |
| 15 | + println("[DEBUG] Vec min/max test starting") |
| 16 | + flush(stdout) |
| 17 | +end |
| 18 | + |
| 19 | +ts = @testset QuietTestSet "Vec min/max tests" begin |
| 20 | + |
| 21 | +if rank == 0 |
| 22 | + println("[DEBUG] Test 1: Basic maximum and minimum") |
| 23 | + flush(stdout) |
| 24 | +end |
| 25 | + |
| 26 | +# Test 1: Basic maximum and minimum |
| 27 | +v = Vec_uniform([1.0, 4.0, 2.0, 3.0]) |
| 28 | +@test sum(v) ≈ 10.0 |
| 29 | +@test maximum(v) ≈ 4.0 |
| 30 | +@test minimum(v) ≈ 1.0 |
| 31 | + |
| 32 | +SafeMPI.check_and_destroy!() |
| 33 | +MPI.Barrier(comm) |
| 34 | + |
| 35 | +if rank == 0 |
| 36 | + println("[DEBUG] Test 2: Negative values") |
| 37 | + flush(stdout) |
| 38 | +end |
| 39 | + |
| 40 | +# Test 2: Negative values |
| 41 | +v2 = Vec_uniform([-5.0, 2.0, -1.0, 3.0]) |
| 42 | +@test maximum(v2) ≈ 3.0 |
| 43 | +@test minimum(v2) ≈ -5.0 |
| 44 | + |
| 45 | +SafeMPI.check_and_destroy!() |
| 46 | +MPI.Barrier(comm) |
| 47 | + |
| 48 | +if rank == 0 |
| 49 | + println("[DEBUG] Test 3: All same values") |
| 50 | + flush(stdout) |
| 51 | +end |
| 52 | + |
| 53 | +# Test 3: All same values |
| 54 | +v3 = Vec_uniform([7.0, 7.0, 7.0, 7.0]) |
| 55 | +@test maximum(v3) ≈ 7.0 |
| 56 | +@test minimum(v3) ≈ 7.0 |
| 57 | + |
| 58 | +SafeMPI.check_and_destroy!() |
| 59 | +MPI.Barrier(comm) |
| 60 | + |
| 61 | +if rank == 0 |
| 62 | + println("[DEBUG] Test 4: Single element") |
| 63 | + flush(stdout) |
| 64 | +end |
| 65 | + |
| 66 | +# Test 4: Single element |
| 67 | +v4 = Vec_uniform([42.0]) |
| 68 | +@test maximum(v4) ≈ 42.0 |
| 69 | +@test minimum(v4) ≈ 42.0 |
| 70 | + |
| 71 | +SafeMPI.check_and_destroy!() |
| 72 | +MPI.Barrier(comm) |
| 73 | + |
| 74 | +if rank == 0 |
| 75 | + println("[DEBUG] Test 5: Larger vector") |
| 76 | + flush(stdout) |
| 77 | +end |
| 78 | + |
| 79 | +# Test 5: Larger vector distributed across ranks |
| 80 | +v5 = Vec_uniform(collect(1.0:16.0)) |
| 81 | +@test maximum(v5) ≈ 16.0 |
| 82 | +@test minimum(v5) ≈ 1.0 |
| 83 | +@test sum(v5) ≈ 136.0 # 16*17/2 |
| 84 | + |
| 85 | +SafeMPI.check_and_destroy!() |
| 86 | +MPI.Barrier(comm) |
| 87 | + |
| 88 | +end # End of QuietTestSet |
| 89 | + |
| 90 | +# Aggregate per-rank counts and print a single summary on root |
| 91 | +local_counts = [ |
| 92 | + get(ts.counts, :pass, 0), |
| 93 | + get(ts.counts, :fail, 0), |
| 94 | + get(ts.counts, :error, 0), |
| 95 | + get(ts.counts, :broken, 0), |
| 96 | + get(ts.counts, :skip, 0), |
| 97 | +] |
| 98 | + |
| 99 | +global_counts = similar(local_counts) |
| 100 | +MPI.Allreduce!(local_counts, global_counts, +, comm) |
| 101 | + |
| 102 | +if rank == 0 |
| 103 | + println("Test Summary: Vec min/max tests (aggregated across $(nranks) ranks)") |
| 104 | + println(" Pass: $(global_counts[1]) Fail: $(global_counts[2]) Error: $(global_counts[3]) Broken: $(global_counts[4]) Skip: $(global_counts[5])") |
| 105 | +end |
| 106 | + |
| 107 | +MPI.Barrier(comm) |
| 108 | + |
| 109 | +if global_counts[2] > 0 || global_counts[3] > 0 |
| 110 | + Base.exit(1) |
| 111 | +end |
| 112 | + |
| 113 | +MPI.Barrier(comm) |
| 114 | + |
| 115 | +if rank == 0 |
| 116 | + println("[DEBUG] Vec min/max test file completed successfully") |
| 117 | + flush(stdout) |
| 118 | +end |
0 commit comments