Loading...
Searching...
No Matches
bit_masks.hpp
Go to the documentation of this file.
1
2
3#pragma once
7
8namespace terra::grid {
9
10/// @brief \ref FlagLike enum class that indicates whether a node is owned on a subdomain.
11///
12/// Each node of the grid is either owned or not owned. Nodes that are duplicated due to the domain partitioning
13/// into subdomains must somehow be treated properly in kernels like dot products etc. Values at duplicate nodes
14/// typically must not be added twice. This enum shall mark exactly one node of each set of duplicated nodes (and all
15/// the non-duplicated nodes in the subdomain interior) as owned.
16///
17enum class NodeOwnershipFlag : uint8_t
18{
19 NO_FLAG = 0,
20 OWNED = 1
21};
22
24
25/// @brief Set up mask data for a distributed shell domain.
26/// The mask encodes ownership information for each grid node.
27/// @param domain Distributed shell domain.
28/// @return Mask data grid.
30{
32 grid::shell::allocate_scalar_grid< NodeOwnershipFlag >( "mask_data_node_ownership", domain );
33
34 auto tmp_data_for_global_subdomain_indices =
35 grid::shell::allocate_scalar_grid< int64_t >( "tmp_data_for_global_subdomain_indices", domain );
36
39
40 // Interpolate the unique subdomain ID.
41 for ( const auto& [subdomain_info, value] : domain.subdomains() )
42 {
43 const auto& [local_subdomain_id, neighborhood] = value;
44
45 const auto global_subdomain_id = subdomain_info.global_id();
46
47 Kokkos::parallel_for(
48 "set_global_subdomain_id",
49 Kokkos::MDRangePolicy(
50 { 0, 0, 0 }, { mask_data.extent( 1 ), mask_data.extent( 2 ), mask_data.extent( 3 ) } ),
51 KOKKOS_LAMBDA( const int x, const int y, const int r ) {
52 tmp_data_for_global_subdomain_indices( local_subdomain_id, x, y, r ) = global_subdomain_id;
53 } );
54 }
55
56 // Communicate and reduce with minimum.
58 domain, tmp_data_for_global_subdomain_indices, send_buffers, recv_buffers );
59
61 domain, tmp_data_for_global_subdomain_indices, recv_buffers, communication::CommunicationReduction::MIN );
62
63 // Set all nodes to 1 if the global_subdomain_id matches - 0 otherwise.
64 for ( const auto& [subdomain_info, value] : domain.subdomains() )
65 {
66 const auto& [local_subdomain_id, neighborhood] = value;
67
68 const auto global_subdomain_id = subdomain_info.global_id();
69
70 Kokkos::parallel_for(
71 "set_node_owner_flags",
72 Kokkos::MDRangePolicy(
73 { 0, 0, 0 }, { mask_data.extent( 1 ), mask_data.extent( 2 ), mask_data.extent( 3 ) } ),
74 KOKKOS_LAMBDA( const int x, const int y, const int r ) {
75 if ( tmp_data_for_global_subdomain_indices( local_subdomain_id, x, y, r ) == global_subdomain_id )
76 {
77 mask_data( local_subdomain_id, x, y, r ) = NodeOwnershipFlag::OWNED;
78 }
79 } );
80
81 Kokkos::fence();
82 }
83
84 return mask_data;
85}
86
87} // namespace terra::grid
Send and receive buffers for all process-local subdomain boundaries.
Definition communication.hpp:56
Parallel data structure organizing the thick spherical shell metadata for distributed (MPI parallel) ...
Definition spherical_shell.hpp:2498
const std::map< SubdomainInfo, std::tuple< LocalSubdomainIdx, SubdomainNeighborhood > > & subdomains() const
Definition spherical_shell.hpp:2580
Concept for types that behave like bitmask flags.
Definition bit_masking.hpp:17
void unpack_and_reduce_local_subdomain_boundaries(const grid::shell::DistributedDomain &domain, const GridDataType &data, SubdomainNeighborhoodSendRecvBuffer< typename GridDataType::value_type, grid::grid_data_vec_dim< GridDataType >() > &boundary_recv_buffers, CommunicationReduction reduction=CommunicationReduction::SUM)
Unpacks and reduces local subdomain boundaries.
Definition communication.hpp:672
void pack_send_and_recv_local_subdomain_boundaries(const grid::shell::DistributedDomain &domain, const GridDataType &data, SubdomainNeighborhoodSendRecvBuffer< typename GridDataType::value_type, grid::grid_data_vec_dim< GridDataType >() > &boundary_send_buffers, SubdomainNeighborhoodSendRecvBuffer< typename GridDataType::value_type, grid::grid_data_vec_dim< GridDataType >() > &boundary_recv_buffers)
Packs, sends and recvs local subdomain boundaries using two sets of buffers.
Definition communication.hpp:242
@ MIN
Stores the min of all received values during receive.
Definition bit_masks.hpp:8
Grid4DDataScalar< NodeOwnershipFlag > setup_node_ownership_mask_data(const shell::DistributedDomain &domain)
Set up mask data for a distributed shell domain. The mask encodes ownership information for each grid...
Definition bit_masks.hpp:29
Kokkos::View< ScalarType ****, Layout > Grid4DDataScalar
Definition grid_types.hpp:25
NodeOwnershipFlag
FlagLike enum class that indicates whether a node is owned on a subdomain.
Definition bit_masks.hpp:18