Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use of array float[4] as datatype for SparseArray #769

Open
FlyingCat2023 opened this issue Sep 13, 2024 · 2 comments
Open

use of array float[4] as datatype for SparseArray #769

FlyingCat2023 opened this issue Sep 13, 2024 · 2 comments
Assignees

Comments

@FlyingCat2023
Copy link

Here is the datatype being used.
using DataTypes = Cabana::MemberTypes< float[4],
int,>;
The SparseArray is created and its data is visited by codes below.
auto grid_array = Cabana::Grid::Experimental::createSparseArrayKokkos::OpenMP("grid data structure", layout );
int tile_id = 0;
int cell_id = 0;
auto&& data = grid_array->get<0>(tile_id, cell_id);
The compilation error is below.
/usr/local/cabana/include/Cabana_SoA.hpp: In instantiation of ‘typename std::enable_if<Cabana::is_soa<SoA_t>::value, typename SoA_t::member_reference_type >::type Cabana::get(SoA_t&, std::size_t) [with long unsigned int M = 0; SoA_t = Cabana::SoA<Cabana::MemberTypes<float [4], int>, 64>; typename std::enable_if<Cabana::is_soa<SoA_t>::value, typename SoA_t::member_reference_type >::type = float&; typename SoA_t::member_reference_type = float&; std::size_t = long unsigned int]’:
/usr/local/cabana/include/Cabana_Grid_SparseArray.hpp:651:30: required from ‘typename Cabana::Grid::Experimental::SparseArray<DataTypes, MemorySpace, EntityType, MeshType, SparseMapType>::soa_type::member_reference_type Cabana::Grid::Experimental::SparseArray<DataTypes, MemorySpace, EntityType, MeshType, SparseMapType>::get(int, int) const [with long unsigned int M = 0; DataTypes = Cabana::MemberTypes<float [4], int>; MemorySpace = Kokkos::OpenMP; EntityType = Cabana::Grid::Node; MeshType = Cabana::Grid::SparseMesh<double, 3>; SparseMapType = Cabana::Grid::SparseMap<Kokkos::HostSpace, 4, Cabana::Grid::HashTypes::Morton>; typename Cabana::Grid::Experimental::SparseArray<DataTypes, MemorySpace, EntityType, MeshType, SparseMapType>::soa_type::member_reference_type = float&; Cabana::Grid::Experimental::SparseArray<DataTypes, MemorySpace, EntityType, MeshType, SparseMapType>::soa_type = Cabana::SoA<Cabana::MemberTypes<float [4], int>, 64>]’
/home/jianl/projects/Zeros_MPM/cabana_thgrid/unit_test/grid_array/utest_grid_array.cpp:63:37: required from here
/usr/local/cabana/include/Cabana_SoA.hpp:182:47: error: invalid initialization of non-const reference of type ‘std::enable_if<true, float&>::type’ {aka ‘float&’} from an rvalue of type ‘Cabana::Impl::InnerArrayTypeImpl<float [4], 1, 64>::value_type
’ {aka ‘float*’}
182 | return Impl::soaMemberCast( soa )._data[a];
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
make[2]: *** [unit_test/grid_array/CMakeFiles/test_grid_array.dir/build.make:76: unit_test/grid_array/CMakeFiles/test_grid_array.dir/utest_grid_array.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:456: unit_test/grid_array/CMakeFiles/test_grid_array.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

@FlyingCat2023
Copy link
Author

Complete codes.

using exec_space = Kokkos::DefaultHostExecutionSpace;
using device_type = exec_space::device_type;
using MemorySpace = Kokkos::HostSpace;
using DataTypes = Cabana::MemberTypes<  float[4], 
                                        int>;
using SparseMapType = Cabana::Grid::SparseMap<MemorySpace, 4, Cabana::Grid::HashTypes::Morton>;
Cabana::Grid::DimBlockPartitioner<3> partitioner;
int cell_num_per_tile_dim = 128;
int halo_width = 2;
int dofs_per_node = 4;
double cell_size = 0.50;
std::array<int, 3> block_size = {4, 4, 4};
std::array<int, 3> global_num_cell = { 37, 15, 20 };
std::array<bool, 3> is_dim_periodic = { false, false, false };
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_num_cell[0],
    global_low_corner[1] + cell_size * global_num_cell[1],
    global_low_corner[2] + cell_size * global_num_cell[2] };
auto sparse_mesh = Cabana::Grid::createSparseGlobalMesh(
    global_low_corner, global_high_corner, global_num_cell );
auto sparse_grid = Cabana::Grid::createGlobalGrid(
                                        MPI_COMM_WORLD, sparse_mesh, is_dim_periodic, partitioner );    
SparseMapType sparse_map(block_size, 1600);
auto local_grid = Cabana::Grid::Experimental::createSparseLocalGrid( sparse_grid,
                                         halo_width,
                                         cell_num_per_tile_dim );     
auto layout = Cabana::Grid::Experimental::createSparseArrayLayout<DataTypes>(
                                local_grid, 
                                sparse_map, 
                                Cabana::Grid::Node());                                
auto grid_array = Cabana::Grid::Experimental::createSparseArray<Kokkos::OpenMP>("grid data structure", *layout );  
int tile_id = 0; 
int cell_id = 0;
auto&& data = grid_array->get<0>(tile_id, cell_id); 

@streeve streeve self-assigned this Sep 26, 2024
@streeve
Copy link
Member

streeve commented Sep 26, 2024

Sorry, I missed this (I think I conflated it with your next issue).

I'll see if I can reproduce and get back to you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants