1
1
#pragma once
2
2
3
3
#include " miniWeather_common.hpp"
4
- #include < Kokkos_Core.hpp>
4
+ #include " Kokkos_Core.hpp"
5
5
6
- using kokkos_execution_policy = Kokkos::DefaultExecutionSpace;
6
+ #if defined(MINIWEATHER_KOKKOS_OPENACC)
7
+ # if ! defined(KOKKOS_ENABLE_OPENACC)
8
+ # error "Kokkos OpenACC is not enabled"
9
+ # endif
10
+
11
+ // Users aren't allowed to include OpenACC/Kokkos_OpenACC.hpp directly.
12
+ // #include "OpenACC/Kokkos_OpenACC.hpp"
13
+ using kokkos_execution_policy = Kokkos::Experimental::OpenACC;
14
+
15
+ #elif defined(MINIWEATHER_KOKKOS_SERIAL)
16
+ # if ! defined(KOKKOS_ENABLE_SERIAL)
17
+ # error "Kokkos Serial is not enabled"
18
+ # endif
19
+
20
+ // Users aren't allowed to include Serial/Kokkos_Serial.hpp directly.
21
+ // #include "Serial/Kokkos_Serial.hpp"
22
+ using kokkos_execution_policy = Kokkos::Serial;
23
+
24
+ #else
25
+ # error "No Kokkos execution policy defined"
26
+ #endif
7
27
8
28
template <int MyRank>
9
29
using md_range_policy = Kokkos::MDRangePolicy<
@@ -369,9 +389,28 @@ reduction_result local_reductions(
369
389
auto hy_dens_cell = const_arrays.hy_dens_cell ();
370
390
auto hy_dens_theta_cell = const_arrays.hy_dens_theta_cell ();
371
391
392
+ // Kokkos doesn't currently implement parallel_reduce(MDRangePolicy) for OpenACC.
393
+ #if defined(MINIWEATHER_KOKKOS_OPENACC)
394
+ # if defined(KOKKOS_ENABLE_CUDA)
395
+ auto my_exec_policy = Kokkos::Cuda{};
396
+ # elif defined(KOKKOS_ENABLE_SERIAL)
397
+ auto my_exec_policy = Kokkos::Serial{};
398
+ # else
399
+ # error "No fall-back execution policy defined"
400
+ # endif
401
+ #else
402
+ auto my_exec_policy = exec_policy;
403
+ #endif
404
+
405
+ Kokkos::MDRangePolicy<
406
+ std::remove_cvref_t <decltype (my_exec_policy)>,
407
+ Kokkos::Rank<2 >,
408
+ Kokkos::IndexType<int >>
409
+ range (my_exec_policy, {0 , 0 }, {nz, nx});
410
+
372
411
Kokkos::parallel_reduce (
373
412
" local_reductions" ,
374
- md_range_policy< 2 >(exec_policy, { 0 , 0 }, {nz, nx}) ,
413
+ range ,
375
414
KOKKOS_LAMBDA (int k, int i, reduction_result& thread_local_result) {
376
415
double r = state (ID_DENS, k+hs, i+hs) + hy_dens_cell[hs+k]; // Density
377
416
double u = state (ID_UMOM, k+hs, i+hs) / r; // U-wind
@@ -384,7 +423,6 @@ reduction_result local_reductions(
384
423
thread_local_result.mass += r *dx*dz; // Accumulate domain mass
385
424
thread_local_result.te += (ke + ie)*dx*dz; // Accumulate domain total energy
386
425
}, result);
387
-
388
426
return result;
389
427
}
390
428
0 commit comments