|
6 | 6 | int MyMain(); |
7 | 7 |
|
8 | 8 | int main(int argc, char** argv) { |
9 | | -#ifdef AMREX_USE_MPI |
10 | | - MPI_Init(&argc, &argv); |
11 | | -#else |
12 | | - amrex::ignore_unused(argc,argv); |
13 | | -#endif |
| 9 | + amrex::Initialize(argc, argv); |
14 | 10 | // Let me throw exceptions for triggering my debugger |
15 | | - amrex::Initialize(MPI_COMM_WORLD, std::cout, std::cerr, [](const char* msg) { throw std::runtime_error(msg); }); |
| 11 | + amrex::SetErrorHandler([](const char* msg) { throw std::runtime_error(msg); }); |
16 | 12 | int ret = MyMain(); |
17 | 13 | amrex::Finalize(); |
18 | | -#ifdef AMREX_USE_MPI |
19 | | - MPI_Finalize(); |
20 | | -#endif |
21 | 14 | return ret; |
22 | 15 | } |
23 | 16 |
|
@@ -51,19 +44,23 @@ bool ParallelCopyWithItselfIsCorrect(amrex::iMultiFab& mf, const amrex::Box& dom |
51 | 44 | const int nx = domain.length(0); |
52 | 45 | const int ny = domain.length(1); |
53 | 46 | int fails = 0; |
| 47 | + amrex::ReduceOps<amrex::ReduceOpSum> reduce_op; |
| 48 | + amrex::ReduceData<int> reduce_data(reduce_op); |
| 49 | + using ReduceTuple = amrex::GpuTuple<int>; |
54 | 50 | for (amrex::MFIter mfi(mf); mfi.isValid(); ++mfi) { |
55 | 51 | const amrex::Box section = dest_box & mfi.tilebox(); |
56 | 52 | if (section.isEmpty()) { continue; } |
57 | 53 | auto array = mf.const_array(mfi); |
58 | | - amrex::LoopOnCpu(section, [&](int i, int j, int k) |
| 54 | + reduce_op.eval(section, reduce_data, |
| 55 | + [=] AMREX_GPU_DEVICE (int i, int j, int k) -> ReduceTuple |
59 | 56 | { |
60 | 57 | amrex::Dim3 si = dtos(amrex::Dim3{i,j,k}); |
61 | 58 | int value = si.x + si.y*nx + si.z*nx*ny; |
62 | | - fails += (array(i,j,k) != value); |
63 | | - |
64 | | - AMREX_ASSERT(fails==0); // If DEBUG, crash on first error. |
| 59 | + auto r = int(array(i,j,k) != value); |
| 60 | + return { r }; |
65 | 61 | }); |
66 | 62 | } |
| 63 | + fails += amrex::get<0>(reduce_data.value()); |
67 | 64 | return fails == 0; |
68 | 65 | } |
69 | 66 |
|
@@ -113,19 +110,23 @@ bool ParallelCopyFaceToFace(amrex::iMultiFab& dest, const amrex::Box& domain_des |
113 | 110 | int fails = 0; |
114 | 111 | const int nx = domain_src.length(0); |
115 | 112 | const int ny = domain_src.length(1); |
| 113 | + amrex::ReduceOps<amrex::ReduceOpSum> reduce_op; |
| 114 | + amrex::ReduceData<int> reduce_data(reduce_op); |
| 115 | + using ReduceTuple = amrex::GpuTuple<int>; |
116 | 116 | for (amrex::MFIter mfi(dest); mfi.isValid(); ++mfi) { |
117 | 117 | const amrex::Box section = dest_box & mfi.tilebox(); |
118 | 118 | if (section.isEmpty()) { continue; } |
119 | 119 | auto darray = dest.const_array(mfi); |
120 | | - amrex::LoopOnCpu(section, [&](int i, int j, int k) |
| 120 | + reduce_op.eval(section, reduce_data, |
| 121 | + [=] AMREX_GPU_DEVICE (int i, int j, int k) -> ReduceTuple |
121 | 122 | { |
122 | 123 | amrex::Dim3 si = dtos(amrex::Dim3{i,j,k}); |
123 | 124 | int value = si.x + si.y*nx + si.z*nx*ny; |
124 | | - fails += (darray(i,j,k) != value); |
125 | | - |
126 | | - AMREX_ASSERT(fails==0); // If in debug, crash on first error. |
| 125 | + auto r = int(darray(i,j,k) != value); |
| 126 | + return { r }; |
127 | 127 | }); |
128 | 128 | } |
| 129 | + fails += amrex::get<0>(reduce_data.value()); |
129 | 130 | return fails == 0; |
130 | 131 | } |
131 | 132 |
|
|
0 commit comments