Nalu
Nalu: a generalized unstructured massively parallel low Mach flow code designed to support a variety of energy applications of interest (most notably Wind ECP) built on the Sierra Toolkit and Trilinos solver Tpetra/Epetra stack. The open source BSD, clause 3 license model has been chosen for the code base. See LICENSE for more information. http://NaluCFD.org
UnitTestKokkosUtils.h
Go to the documentation of this file.
1 #ifndef _UnitTestKokkosUtils_h_
2 #define _UnitTestKokkosUtils_h_
3 
5 #include <stk_mesh/base/Types.hpp>
6 #include <stk_mesh/base/Bucket.hpp>
7 #include <Kokkos_Core.hpp>
8 
9 #include <KokkosInterface.h>
10 #include "UnitTestUtils.h"
11 
12 template<class OUTER_LOOP_BODY, class INNER_LOOP_BODY>
13 void bucket_loop_serial_only(const stk::mesh::BucketVector& buckets, const OUTER_LOOP_BODY& outer_loop_body, const INNER_LOOP_BODY& inner_loop_body)
14 {
15  for(const stk::mesh::Bucket* bptr : buckets)
16  {
17  const stk::mesh::Bucket& bkt = *bptr;
18  stk::topology topo = bkt.topology();
20 
21  outer_loop_body(topo,*meSCS);
22 
23  for(size_t j=0; j<bkt.size(); ++j)
24  {
25  inner_loop_body(bkt[j], topo, *meSCS);
26  }
27  }
28 }
29 
30 template<class LOOP_BODY>
31 void kokkos_bucket_loop(const stk::mesh::BucketVector& buckets, LOOP_BODY inner_loop_body)
32 {
33  Kokkos::parallel_for(buckets.size(), [&](const size_t& i)
34  {
35  const stk::mesh::Bucket& bkt = *buckets[i];
36  for(size_t j=0; j<bkt.size(); ++j)
37  {
38  inner_loop_body(bkt[j]);
39  }
40  });
41 }
42 
43 template<class LOOP_BODY>
44 void kokkos_thread_team_bucket_loop(const stk::mesh::BucketVector& buckets, LOOP_BODY inner_loop_body)
45 {
46  Kokkos::parallel_for(sierra::nalu::DeviceTeamPolicy(buckets.size(), Kokkos::AUTO), KOKKOS_LAMBDA(const sierra::nalu::TeamHandleType& team)
47  {
48  const stk::mesh::Bucket& bkt = *buckets[team.league_rank()];
49  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, bkt.size()), [&](const size_t& j)
50  {
51  inner_loop_body(bkt[j]);
52  });
53  });
54 }
55 
56 template<class LOOP_BODY>
58  const LOOP_BODY& inner_loop_body)
59 {
60  Kokkos::parallel_for(sierra::nalu::DeviceTeamPolicy(buckets.size(), Kokkos::AUTO), KOKKOS_LAMBDA(const sierra::nalu::TeamHandleType& team)
61  {
62  const stk::mesh::Bucket& bkt = *buckets[team.league_rank()];
63  stk::topology topo = bkt.topology();
65  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, bkt.size()), [&](const size_t& j)
66  {
67  inner_loop_body(bkt[j], topo, *meSCS);
68  });
69  });
70 }
71 
72 #endif
73 
Definition: MasterElement.h:53
void kokkos_thread_team_bucket_loop(const stk::mesh::BucketVector &buckets, LOOP_BODY inner_loop_body)
Definition: UnitTestKokkosUtils.h:44
static MasterElement * get_surface_master_element(const stk::topology &theTopo, int dimension=0, std::string quadType="GaussLegendre")
Definition: MasterElementFactory.C:208
void kokkos_thread_team_bucket_loop_with_topo(const stk::mesh::BucketVector &buckets, const LOOP_BODY &inner_loop_body)
Definition: UnitTestKokkosUtils.h:57
void bucket_loop_serial_only(const stk::mesh::BucketVector &buckets, const OUTER_LOOP_BODY &outer_loop_body, const INNER_LOOP_BODY &inner_loop_body)
Definition: UnitTestKokkosUtils.h:13
Kokkos::TeamPolicy< DeviceSpace > DeviceTeamPolicy
Definition: KokkosInterface.h:27
void kokkos_bucket_loop(const stk::mesh::BucketVector &buckets, LOOP_BODY inner_loop_body)
Definition: UnitTestKokkosUtils.h:31
std::vector< Bucket * > BucketVector
Definition: PromotedPartHelper.h:21
Kokkos::TeamPolicy< DeviceSpace, DynamicScheduleType >::member_type TeamHandleType
Definition: KokkosInterface.h:22