-
Notifications
You must be signed in to change notification settings - Fork 50
Grid SparseIndexSpace
Sam Reeve edited this page Sep 12, 2024
·
2 revisions
The Cabana::Grid SparseIndexSpace creates an index space for a sparse grid during each simulation iteration, in which way one can store data from the activated grid only. One can register(insert) occupied grid tiles in each simulation iteration in the sparse index space, which will map a 3D grid index (i, j, k)
to a 1D value in either Lexicographical order or Morton curve order. One can also search if a given tile is touched.
Header File: Cabana_Grid_SparseIndexSpace.hpp
Usage: Store information of valid/occupied grid tiles; insert and search for specific tiles/cells.
- Register all the uniform grid tiles into the
sparseMap
using namespace Cabana::Grid;
// some basic settings related to the domain size
int size_per_dim = 64;
double cell_size = 0.1;
int pre_alloc_size = size_per_dim * size_per_dim;
std::array<double, 3> global_low_corner = { 1.2, 3.3, -2.8 };
std::array<double, 3> global_high_corner = {
global_low_corner[0] + cell_size * global_cells_per_dim[0],
global_low_corner[1] + cell_size * global_cells_per_dim[1],
global_low_corner[2] + cell_size * global_cells_per_dim[2] };
// create a sparse global mesh
auto global_mesh = createSparseGlobalMesh(
global_low_corner, global_high_corner, global_cells_per_dim );
// create a new sparseMap
auto sis = createSparseMap<TEST_EXECSPACE>( global_mesh, pre_alloc_size );
// register tiles to the sparseMap
// all the tiles are registered in the sparseMap
Kokkos::parallel_for(
"insert_cell_to_sparse_map",
Kokkos::RangePolicy<TEST_EXECSPACE>( 0, size_per_dim ),
KOKKOS_LAMBDA( int i ) {
for ( int j = 0; j < size_per_dim; j++ )
for ( int k = 0; k < size_per_dim; k++ )
{
sis.insertCell( i, j, k );
}
} );
- Register chosen grid tiles into the
sparseMap
// randomly choose some grid tiles on HOST
typedef typename TEST_EXECSPACE::array_layout layout;
Kokkos::View<int* [3], layout, Kokkos::HostSpace> tiles_view_host(
"tiles_view_host", tiles_set.size() );
int i = 0;
for ( auto it = tiles_set.begin(); it != tiles_set.end(); ++it )
{
for ( int d = 0; d < 3; ++d )
tiles_view_host( i, d ) = ( *it )[d];
i++;
}
// copy the randomly chosen tiles to the DEVICE
Kokkos::View<int* [3], TEST_MEMSPACE> tiles_view =
Kokkos::create_mirror_view_and_copy( TEST_MEMSPACE(), tiles_view_host );
// initialize sparseMap, register selected tiles on every MPI rank
// settings related to the domain size
double cell_size = 0.1;
int pre_alloc_size = size_per_dim * size_per_dim;
std::array<double, 3> global_low_corner = { 1.2, 3.3, -2.8 };
std::array<double, 3> global_high_corner = {
global_low_corner[0] + cell_size * global_cells_per_dim[0],
global_low_corner[1] + cell_size * global_cells_per_dim[1],
global_low_corner[2] + cell_size * global_cells_per_dim[2] };
// create a sparse global mesh
auto global_mesh = createSparseGlobalMesh(
global_low_corner, global_high_corner, global_cells_per_dim );
// create a new sparseMap
auto sis = createSparseMap<TEST_EXECSPACE>( global_mesh, pre_alloc_size );
// register tiles to the sparseMap
Kokkos::parallel_for(
"insert_tile_to_sparse_map",
Kokkos::RangePolicy<TEST_EXECSPACE>( 0, tiles_set.size() ),
KOKKOS_LAMBDA( int id ) {
sis.insertTile( tiles_view( id, 0 ), tiles_view( id, 1 ),
tiles_view( id, 2 ) );
} );
This is part of the Programming Guide series
Cabana - A Co-Designed Library for Exascale Particle Simulations