Skip to content

Commit

Permalink
smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelyr committed Nov 24, 2024
1 parent b20b7e5 commit e2aaf60
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions particle_structs/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ function(make_test exename srcname)
target_link_libraries(${exename} particleStructs)
endfunction(make_test)

make_test(smoke_test_particle smoke_test_particle.cpp)

make_test(typeTest typeTest.cpp)

make_test(sortTest sortTest.cpp)
Expand Down
85 changes: 85 additions & 0 deletions particle_structs/test/smoke_test_particle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include <particle_structs.hpp>
#include "read_particles.hpp"
#include "team_policy.hpp"

int main(int argc, char* argv[]) {
Kokkos::initialize(argc, argv);
MPI_Init(&argc, &argv);
int test_failed = 1;
{
int comm_rank, comm_size;
MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
MPI_Comm_size(MPI_COMM_WORLD, &comm_size);


int num_elems = 5;
int num_ptcls = 5;
kkLidView ppe = kkLidView("particles_per_element", num_elems);
kkGidView element_gids = kkGidView("elemnt_gids", num_elems);
kkLidView particle_elements = kkLidView("element_of_particle", num_ptcls);
PS::MTVs particle_info = ps::createMemberViews<Types>(num_ptcls);

lid_t ppe_h[num_elems] = {1,1,1,1,1};
lid_t element_gids_h[num_elems] = {0,1,2,3,4};
lid_t particle_elements_h[num_ptcls] = {0,1,2,3,4};
ps::hostToDevice(ppe, ppe_h);
ps::hostToDevice(element_gids, element_gids_h);
ps::hostToDevice(particle_elements, particle_elements_h);
kkLidView failures("fails", 1);

//Init
Kokkos::TeamPolicy<ExeSpace> policy = pumipic::TeamPolicyAuto(num_elems,32);
PS* structure = new ps::DPS<Types, MemSpace>(policy, num_elems, num_ptcls, ppe,
element_gids, particle_elements, particle_info);

auto checkInit = PS_LAMBDA(const lid_t& e, const lid_t& p, const bool& mask) {
if (mask && e != p){
printf("Structure not initalized at Elm: %d, Particle: %d\n", e, p);
failures(0) = 1;
}
};
ps::parallel_for(structure, checkInit, "checkInit");

//Rebuild
kkLidView new_element("new_element", structure->capacity());
auto setNewElm = PS_LAMBDA(const lid_t& e, const lid_t& p, const bool& mask) {
if (mask) new_element(p) = comm_rank;
else new_element(p) = -1;
};
ps::parallel_for(structure, setNewElm, "setNewElm");
structure->rebuild(new_element);

auto checkRebuild = PS_LAMBDA(const lid_t& e, const lid_t& p, const bool& mask) {
if (mask && e != comm_rank){
printf("Particle not set to correct element at Ptcl: %d, Elm: %d\n", p, e);
failures(0) = 1;
}
};
ps::parallel_for(structure, checkRebuild, "checkRebuild");

//Migrate
kkLidView new_process("new_process", structure->capacity());
auto setNewProcess = PS_LAMBDA(const lid_t& e, const lid_t& p, const bool& mask) {
if (mask) new_process(p) = (comm_rank + 1) % comm_size;
else new_process(p) = comm_rank;
};
ps::parallel_for(structure, setNewProcess, "setNewProcess");
structure->migrate(new_element, new_process);

auto checkMigrate = PS_LAMBDA(const lid_t& e, const lid_t& p, const bool& mask) {
if (mask && e == comm_rank){
printf("Particle in correct rank at Ptcl: %d, Elm: %d\n", p, e);
failures(0) = 1;
}
};
ps::parallel_for(structure, checkMigrate, "checkMigrate");

test_failed = ps::getLastValue(failures);
delete structure;
ps::destroyViews<Types>(particle_info);
}
Kokkos::finalize();
MPI_Finalize();

if (test_failed) exit(1);
}
2 changes: 2 additions & 0 deletions particle_structs/test/testing.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mpi_test(smoke_test_particle 4 ./smoke_test_particle)

mpi_test(type_test 1 ./typeTest)

mpi_test(sort_test 1 ./sortTest 5000)
Expand Down

0 comments on commit e2aaf60

Please sign in to comment.