From 107882db1f78b096ebe45d824cb4e59361466bdb Mon Sep 17 00:00:00 2001 From: lkotipal Date: Tue, 12 Mar 2024 16:06:22 +0200 Subject: [PATCH 01/12] Unit testing hello world --- UnitTests/makefile | 21 +++++++++++++++++++++ UnitTests/simple.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 UnitTests/makefile create mode 100644 UnitTests/simple.cpp diff --git a/UnitTests/makefile b/UnitTests/makefile new file mode 100644 index 0000000..1106a87 --- /dev/null +++ b/UnitTests/makefile @@ -0,0 +1,21 @@ +ARCH=${VLASIATOR_ARCH} +include ../../../MAKE/Makefile.${ARCH} + +# These should be in Makefile.${ARCH} +# INC_GTEST=-I/projappl/project_2005018/lkotipal/libraries/gtest/include +# LIB_GTEST=-L/projappl/project_2005018/lkotipal/libraries/gtest/lib64 -lgtest -Wl,-rpath=/projappl/project_2005018/lkotipal/libraries/gtest/lib64 + +CXXFLAGS+=$(INC_MPI) $(INC_BOOST) $(INC_ZOLTAN) $(INC_GTEST) -DGTEST_HAS_MPI +LDFLAGS+=$(LIB_BOOST) $(LIB_ZOLTAN) $(LIB_GTEST) + +all: simple.exe + +simple.exe: simple.o + $(CMP) $(CXXFLAGS) simple.o -o $@ $(LDFLAGS) + +simple.o: simple.cpp common.hpp + $(CMP) $(CXXFLAGS) -c simple.cpp + +clean: + rm *.exe + rm *.o \ No newline at end of file diff --git a/UnitTests/simple.cpp b/UnitTests/simple.cpp new file mode 100644 index 0000000..5a32f7a --- /dev/null +++ b/UnitTests/simple.cpp @@ -0,0 +1,36 @@ +#include "common.hpp" +#include +#include + +int main(int argc, char* argv[]) +{ + int mpiError = MPI_Init(&argc, &argv); + ::testing::InitGoogleTest(&argc, argv); + int ret {RUN_ALL_TESTS()}; + mpiError = MPI_Finalize(); + return ret; +} + +TEST(hello, passes_on_all) +{ + int myRank {0}; + MPI_Comm_rank(MPI_COMM_WORLD, &myRank); + std::cout << "Hello from " << myRank << std::endl; + ASSERT_EQ_MPI(0, 0); +} + +TEST(hello, fails_on_all) +{ + int myRank {0}; + MPI_Comm_rank(MPI_COMM_WORLD, &myRank); + std::cout << "Hello from " << myRank << std::endl; + ASSERT_EQ_MPI(myRank, -1); +} + +TEST(hello, fails_on_one) +{ + int myRank {0}; + MPI_Comm_rank(MPI_COMM_WORLD, &myRank); + std::cout << "Hello from " << myRank << std::endl; + ASSERT_NE_MPI(myRank, 0); +} From 30a42804665fc7350ede81bcec57568780f518a0 Mon Sep 17 00:00:00 2001 From: lkotipal Date: Thu, 14 Mar 2024 12:52:52 +0200 Subject: [PATCH 02/12] Improve makefile, add simple MPI test --- UnitTests/makefile | 14 +++++---- UnitTests/simple.cpp | 36 ----------------------- UnitTests/validation.cpp | 63 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 42 deletions(-) delete mode 100644 UnitTests/simple.cpp create mode 100644 UnitTests/validation.cpp diff --git a/UnitTests/makefile b/UnitTests/makefile index 1106a87..8840bcb 100644 --- a/UnitTests/makefile +++ b/UnitTests/makefile @@ -8,14 +8,16 @@ include ../../../MAKE/Makefile.${ARCH} CXXFLAGS+=$(INC_MPI) $(INC_BOOST) $(INC_ZOLTAN) $(INC_GTEST) -DGTEST_HAS_MPI LDFLAGS+=$(LIB_BOOST) $(LIB_ZOLTAN) $(LIB_GTEST) -all: simple.exe +TESTS=validation.exe -simple.exe: simple.o - $(CMP) $(CXXFLAGS) simple.o -o $@ $(LDFLAGS) +all: $(TESTS) -simple.o: simple.cpp common.hpp - $(CMP) $(CXXFLAGS) -c simple.cpp +%.exe: %.o + $(CMP) $(CXXFLAGS) $< -o $@ $(LDFLAGS) + +%.o: %.cpp + $(CMP) -c $(CXXFLAGS) $< -o $@ clean: - rm *.exe + rm $(TESTS) rm *.o \ No newline at end of file diff --git a/UnitTests/simple.cpp b/UnitTests/simple.cpp deleted file mode 100644 index 5a32f7a..0000000 --- a/UnitTests/simple.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "common.hpp" -#include -#include - -int main(int argc, char* argv[]) -{ - int mpiError = MPI_Init(&argc, &argv); - ::testing::InitGoogleTest(&argc, argv); - int ret {RUN_ALL_TESTS()}; - mpiError = MPI_Finalize(); - return ret; -} - -TEST(hello, passes_on_all) -{ - int myRank {0}; - MPI_Comm_rank(MPI_COMM_WORLD, &myRank); - std::cout << "Hello from " << myRank << std::endl; - ASSERT_EQ_MPI(0, 0); -} - -TEST(hello, fails_on_all) -{ - int myRank {0}; - MPI_Comm_rank(MPI_COMM_WORLD, &myRank); - std::cout << "Hello from " << myRank << std::endl; - ASSERT_EQ_MPI(myRank, -1); -} - -TEST(hello, fails_on_one) -{ - int myRank {0}; - MPI_Comm_rank(MPI_COMM_WORLD, &myRank); - std::cout << "Hello from " << myRank << std::endl; - ASSERT_NE_MPI(myRank, 0); -} diff --git a/UnitTests/validation.cpp b/UnitTests/validation.cpp new file mode 100644 index 0000000..7826b1f --- /dev/null +++ b/UnitTests/validation.cpp @@ -0,0 +1,63 @@ +#include +#include + +int main(int argc, char* argv[]) +{ + int mpiError{MPI_SUCCESS}; + mpiError = MPI_Init(&argc, &argv); + ::testing::InitGoogleTest(&argc, argv); + int ret {RUN_ALL_TESTS()}; + mpiError = MPI_Finalize(); + return ret; +} + +TEST(hello, passes_on_all) +{ + int myRank {0}; + int mpiError {MPI_SUCCESS}; + + mpiError = MPI_Comm_rank(MPI_COMM_WORLD, &myRank); + ASSERT_EQ_MPI(mpiError, MPI_SUCCESS); + ASSERT_EQ_MPI(0, 0); +} + +TEST(hello, fails_on_all) +{ + int myRank {0}; + int mpiError {MPI_SUCCESS}; + + mpiError = MPI_Comm_rank(MPI_COMM_WORLD, &myRank); + ASSERT_EQ_MPI(mpiError, MPI_SUCCESS); + ASSERT_EQ_MPI(myRank, -1); +} + +TEST(hello, fails_on_one) +{ + int myRank {0}; + int mpiError {MPI_SUCCESS}; + + mpiError = MPI_Comm_rank(MPI_COMM_WORLD, &myRank); + ASSERT_EQ_MPI(mpiError, MPI_SUCCESS); + ASSERT_NE_MPI(myRank, 0); +} + +TEST(MPI, sendrecv) +{ + int myRank{0}; + int size{0}; + int mpiError{MPI_SUCCESS}; + + mpiError = MPI_Comm_rank(MPI_COMM_WORLD, &myRank); + ASSERT_EQ_MPI(mpiError, MPI_SUCCESS); + mpiError = MPI_Comm_size(MPI_COMM_WORLD, &size); + ASSERT_EQ_MPI(mpiError, MPI_SUCCESS); + + int dest {myRank < size - 1 ? myRank + 1 : 0}; + int source {myRank > 0 ? myRank - 1 : size - 1}; + int send {myRank}; + int recv {-1}; + + mpiError = MPI_Sendrecv(&send, 1, MPI_INT, dest, 0, &recv, 1, MPI_INT, source, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + ASSERT_EQ_MPI(mpiError, MPI_SUCCESS); + ASSERT_EQ_MPI(source, recv); +} From 763afd4ecd3be48f1e4039e5309ec27130b2d264 Mon Sep 17 00:00:00 2001 From: lkotipal Date: Thu, 14 Mar 2024 14:22:49 +0200 Subject: [PATCH 03/12] Gitignore for compiled tests --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0393442 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +*.exe \ No newline at end of file From 0443ce7b44b3c6542bdb392e3521aff05081d948 Mon Sep 17 00:00:00 2001 From: lkotipal Date: Thu, 14 Mar 2024 14:23:43 +0200 Subject: [PATCH 04/12] Better validation --- UnitTests/validation.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/UnitTests/validation.cpp b/UnitTests/validation.cpp index 7826b1f..e205ad1 100644 --- a/UnitTests/validation.cpp +++ b/UnitTests/validation.cpp @@ -1,3 +1,7 @@ +// Validation for MPI functionality and gtest +// hello.fails_on_all, hello.fails_on_first and hello.fails_on_last should fail +// And the other tests should pass + #include #include @@ -31,16 +35,34 @@ TEST(hello, fails_on_all) ASSERT_EQ_MPI(myRank, -1); } -TEST(hello, fails_on_one) +TEST(hello, fails_on_first) { int myRank {0}; + int size{0}; int mpiError {MPI_SUCCESS}; mpiError = MPI_Comm_rank(MPI_COMM_WORLD, &myRank); ASSERT_EQ_MPI(mpiError, MPI_SUCCESS); + mpiError = MPI_Comm_size(MPI_COMM_WORLD, &size); + ASSERT_EQ_MPI(mpiError, MPI_SUCCESS); + ASSERT_NE_MPI(myRank, 0); } +TEST(hello, fails_on_last) +{ + int myRank {0}; + int size{0}; + int mpiError {MPI_SUCCESS}; + + mpiError = MPI_Comm_rank(MPI_COMM_WORLD, &myRank); + ASSERT_EQ_MPI(mpiError, MPI_SUCCESS); + mpiError = MPI_Comm_size(MPI_COMM_WORLD, &size); + ASSERT_EQ_MPI(mpiError, MPI_SUCCESS); + + ASSERT_NE_MPI(myRank, size - 1); +} + TEST(MPI, sendrecv) { int myRank{0}; From ab99a8bf5d7d28f8e49cb6ce5782ddea753f14da Mon Sep 17 00:00:00 2001 From: lkotipal Date: Thu, 14 Mar 2024 14:24:06 +0200 Subject: [PATCH 05/12] Simple consistency tests for dccrg --- UnitTests/makefile | 6 ++-- UnitTests/simple.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 UnitTests/simple.cpp diff --git a/UnitTests/makefile b/UnitTests/makefile index 8840bcb..23f716f 100644 --- a/UnitTests/makefile +++ b/UnitTests/makefile @@ -5,10 +5,10 @@ include ../../../MAKE/Makefile.${ARCH} # INC_GTEST=-I/projappl/project_2005018/lkotipal/libraries/gtest/include # LIB_GTEST=-L/projappl/project_2005018/lkotipal/libraries/gtest/lib64 -lgtest -Wl,-rpath=/projappl/project_2005018/lkotipal/libraries/gtest/lib64 -CXXFLAGS+=$(INC_MPI) $(INC_BOOST) $(INC_ZOLTAN) $(INC_GTEST) -DGTEST_HAS_MPI -LDFLAGS+=$(LIB_BOOST) $(LIB_ZOLTAN) $(LIB_GTEST) +CXXFLAGS+=$(INC_MPI) $(INC_BOOST) $(INC_ZOLTAN) $(INC_PROFILE) $(INC_GTEST) -DGTEST_HAS_MPI +LDFLAGS+=$(LIB_BOOST) $(LIB_ZOLTAN) $(LIB_GTEST) $(LIB_PROFILE) -TESTS=validation.exe +TESTS=validation.exe simple.exe all: $(TESTS) diff --git a/UnitTests/simple.cpp b/UnitTests/simple.cpp new file mode 100644 index 0000000..b932562 --- /dev/null +++ b/UnitTests/simple.cpp @@ -0,0 +1,82 @@ +// Validation for MPI functionality and gtest +// hello.fails_on_all and hello.fails_on_last should fail +// And the other tests should pass + +#include +#include +#include "../dccrg.hpp" +#include "../dccrg_cartesian_geometry.hpp" + +int main(int argc, char* argv[]) +{ + int mpiError{MPI_SUCCESS}; + mpiError = MPI_Init(&argc, &argv); + ::testing::InitGoogleTest(&argc, argv); + int ret {RUN_ALL_TESTS()}; + mpiError = MPI_Finalize(); + return ret; +} + +class SimpleGrid : public testing::Test { + protected: + SimpleGrid() + { + // Defaults should be fine for everything + grid.set_initial_length({4, 4, 4}).initialize(MPI_COMM_WORLD).set_load_balancing_method("RANDOM").balance_load(); + + // Simple data we can check + for (auto cell : grid.get_cells()) { + *grid[cell] = cell; + } + + grid.update_copies_of_remote_neighbors(); + } + + dccrg::Dccrg grid; +}; + +TEST_F(SimpleGrid, contents) +{ + for (auto cell : grid.get_cells()) { + EXPECT_EQ_MPI(*grid[cell], cell); + } +} + +TEST_F(SimpleGrid, contents_after_loadbalance) +{ + grid.balance_load(); + for (auto cell : grid.get_cells()) { + EXPECT_EQ_MPI(*grid[cell], cell); + } +} + +// TODO: currently only checks consistency between local cells +TEST_F(SimpleGrid, consistent_neighbors) +{ + auto cells = grid.get_cells(); + for (auto cell : grid.get_cells()) { + auto* my_neighbors_of {grid.get_neighbors_of(cell)}; + EXPECT_NE_MPI(my_neighbors_of, nullptr); + auto* my_neighbors_to {grid.get_neighbors_to(cell)}; + EXPECT_NE_MPI(my_neighbors_to, nullptr); + + for (auto [neighbor, dir] : *my_neighbors_of) { + if (neighbor != dccrg::error_cell) { + EXPECT_NE_MPI(grid[neighbor], nullptr); + if (std::find(cells.begin(), cells.end(), neighbor) != cells.end()) { + auto* other_neighbors_to {grid.get_neighbors_to(neighbor)}; + EXPECT_NE_MPI(other_neighbors_to, nullptr); + EXPECT_NE_MPI(std::find_if(other_neighbors_to->begin(), other_neighbors_to->end(), [&cell](const std::pair> pair){return pair.first == cell;}), other_neighbors_to->end()); + } + } + } + + for (auto [neighbor, dir] : *my_neighbors_to) { + if (std::find(cells.begin(), cells.end(), neighbor) != cells.end()) { + auto* other_neighbors_of {grid.get_neighbors_of(neighbor)}; + EXPECT_NE_MPI(other_neighbors_of, nullptr); + EXPECT_NE_MPI(std::find_if(other_neighbors_of->begin(), other_neighbors_of->end(), [&cell](const std::pair> pair){return pair.first == cell;}), other_neighbors_of->end()); + } + } + } +} From 627af00d5dc7c1a080d1dad569c33af62136041d Mon Sep 17 00:00:00 2001 From: lkotipal Date: Thu, 14 Mar 2024 14:36:01 +0200 Subject: [PATCH 06/12] Rudimentary copy test --- UnitTests/simple.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/UnitTests/simple.cpp b/UnitTests/simple.cpp index b932562..1669a7c 100644 --- a/UnitTests/simple.cpp +++ b/UnitTests/simple.cpp @@ -38,6 +38,7 @@ class SimpleGrid : public testing::Test { TEST_F(SimpleGrid, contents) { for (auto cell : grid.get_cells()) { + EXPECT_NE_MPI(grid[cell], nullptr); EXPECT_EQ_MPI(*grid[cell], cell); } } @@ -46,6 +47,7 @@ TEST_F(SimpleGrid, contents_after_loadbalance) { grid.balance_load(); for (auto cell : grid.get_cells()) { + EXPECT_NE_MPI(grid[cell], nullptr); EXPECT_EQ_MPI(*grid[cell], cell); } } @@ -80,3 +82,28 @@ TEST_F(SimpleGrid, consistent_neighbors) } } } + +// TODO test proper copies and frees of dccrg.comm +// Right now this can't be done because the getter is not a getter +TEST_F(SimpleGrid, copy) +{ + auto other_grid = grid; + + // Local cells should be identical immediately after copy + for (auto cell : grid.get_cells()) { + EXPECT_NE_MPI(other_grid[cell], nullptr); + EXPECT_EQ_MPI(*other_grid[cell], cell); + } + + other_grid.balance_load(); + for (auto cell : other_grid.get_cells()) { + EXPECT_NE_MPI(other_grid[cell], nullptr); + EXPECT_EQ_MPI(*other_grid[cell], cell); + } + + // Load balancing copy shouldn't affect original + for (auto cell : grid.get_cells()) { + EXPECT_NE_MPI(grid[cell], nullptr); + EXPECT_EQ_MPI(*grid[cell], cell); + } +} From 6b3e26eb97b0d439ba6046a71e2cca0d9c3c3030 Mon Sep 17 00:00:00 2001 From: lkotipal Date: Thu, 14 Mar 2024 14:51:07 +0200 Subject: [PATCH 07/12] Newlines --- .gitignore | 2 +- UnitTests/makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0393442..25a7384 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ *.o -*.exe \ No newline at end of file +*.exe diff --git a/UnitTests/makefile b/UnitTests/makefile index 23f716f..dfa09c3 100644 --- a/UnitTests/makefile +++ b/UnitTests/makefile @@ -20,4 +20,4 @@ all: $(TESTS) clean: rm $(TESTS) - rm *.o \ No newline at end of file + rm *.o From 23ddbd78914f79c8c1cbf0be9eff075bd62cae41 Mon Sep 17 00:00:00 2001 From: lkotipal Date: Fri, 15 Mar 2024 12:27:40 +0200 Subject: [PATCH 08/12] Check consistency for remote neighbors as well --- UnitTests/simple.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/UnitTests/simple.cpp b/UnitTests/simple.cpp index 1669a7c..0027814 100644 --- a/UnitTests/simple.cpp +++ b/UnitTests/simple.cpp @@ -65,20 +65,33 @@ TEST_F(SimpleGrid, consistent_neighbors) for (auto [neighbor, dir] : *my_neighbors_of) { if (neighbor != dccrg::error_cell) { EXPECT_NE_MPI(grid[neighbor], nullptr); + std::vector>> other_neighbors_to; if (std::find(cells.begin(), cells.end(), neighbor) != cells.end()) { - auto* other_neighbors_to {grid.get_neighbors_to(neighbor)}; - EXPECT_NE_MPI(other_neighbors_to, nullptr); - EXPECT_NE_MPI(std::find_if(other_neighbors_to->begin(), other_neighbors_to->end(), [&cell](const std::pair> pair){return pair.first == cell;}), other_neighbors_to->end()); + auto* p {grid.get_neighbors_to(neighbor)}; + EXPECT_NE_MPI(p, nullptr); + other_neighbors_to = *p; + } else { + // Warning: giga jank + std::vector found_neighbors; + for (auto& [neigh, dir] : grid.find_neighbors_of(neighbor, grid.get_neighborhood_of(), grid.get_max_ref_lvl_diff())) { + found_neighbors.push_back(neigh); + } + other_neighbors_to = grid.find_neighbors_to(neighbor, found_neighbors); } + EXPECT_NE_MPI(std::find_if(other_neighbors_to.begin(), other_neighbors_to.end(), [&cell](const std::pair> pair){return pair.first == cell;}), other_neighbors_to.end()); } } for (auto [neighbor, dir] : *my_neighbors_to) { + std::vector>> other_neighbors_of; if (std::find(cells.begin(), cells.end(), neighbor) != cells.end()) { - auto* other_neighbors_of {grid.get_neighbors_of(neighbor)}; - EXPECT_NE_MPI(other_neighbors_of, nullptr); - EXPECT_NE_MPI(std::find_if(other_neighbors_of->begin(), other_neighbors_of->end(), [&cell](const std::pair> pair){return pair.first == cell;}), other_neighbors_of->end()); + auto* p {grid.get_neighbors_of(neighbor)}; + EXPECT_NE_MPI(p, nullptr); + other_neighbors_of = *p; + } else { + other_neighbors_of = grid.find_neighbors_of(neighbor, grid.get_neighborhood_of(), grid.get_max_ref_lvl_diff()); } + EXPECT_NE_MPI(std::find_if(other_neighbors_of.begin(), other_neighbors_of.end(), [&cell](const std::pair> pair){return pair.first == cell;}), other_neighbors_of.end()); } } } From cf03b7b162694a726ad3d200d38100b89b224f86 Mon Sep 17 00:00:00 2001 From: lkotipal Date: Fri, 15 Mar 2024 13:45:33 +0200 Subject: [PATCH 09/12] Test user neighborhood consistency --- UnitTests/{simple.cpp => grid.cpp} | 105 ++++++++++++++++++++++++++--- UnitTests/makefile | 3 +- 2 files changed, 96 insertions(+), 12 deletions(-) rename UnitTests/{simple.cpp => grid.cpp} (50%) diff --git a/UnitTests/simple.cpp b/UnitTests/grid.cpp similarity index 50% rename from UnitTests/simple.cpp rename to UnitTests/grid.cpp index 0027814..0f29b56 100644 --- a/UnitTests/simple.cpp +++ b/UnitTests/grid.cpp @@ -17,25 +17,73 @@ int main(int argc, char* argv[]) return ret; } -class SimpleGrid : public testing::Test { +enum class GridType { + simple, + vlasovian, + magnetospheric +}; + +class GridTest : public testing::TestWithParam { protected: - SimpleGrid() + void SetUp() override { - // Defaults should be fine for everything - grid.set_initial_length({4, 4, 4}).initialize(MPI_COMM_WORLD).set_load_balancing_method("RANDOM").balance_load(); + typedef dccrg::Types<3>::neighborhood_item_t neigh_t; + std::vector neighborhood; + + grid.set_initial_length({10, 10, 10}).set_neighborhood_length(stencil_width).initialize(MPI_COMM_WORLD); + switch (GetParam()) { + case GridType::simple: + break; // Defaults should be fine for everything + case GridType::vlasovian: + // Extended sysboundaries + for (int x = -stencil_width; x <= stencil_width; ++x) { + for (int y = -stencil_width; y <= stencil_width; ++y) { + for (int z = -stencil_width; z <= stencil_width; ++z) { + if (x || y || z) { + neighborhood.push_back({x, y, z}); + } + } + } + } + grid.add_neighborhood(neighborhoods++, neighborhood); + + // Vlasov solver + for (int d = -stencil_width; d <= stencil_width; ++d) { + if (d) { + neighborhood.push_back({d, 0, 0}); + neighborhood.push_back({0, d, 0}); + neighborhood.push_back({0, 0, d}); + } + } + grid.add_neighborhood(neighborhoods++, neighborhood); + + break; + default: + FAIL() << "Grid type not implemented!"; + break; + } + + grid.set_load_balancing_method("RANDOM").balance_load(); // Simple data we can check for (auto cell : grid.get_cells()) { *grid[cell] = cell; } - grid.update_copies_of_remote_neighbors(); + for (int neighborhood = 0; neighborhood < neighborhoods; ++neighborhood) { + grid.update_copies_of_remote_neighbors(neighborhood); + } } dccrg::Dccrg grid; + int neighborhoods {0}; + const int stencil_width {3}; }; -TEST_F(SimpleGrid, contents) +INSTANTIATE_TEST_SUITE_P(Simple, GridTest, testing::Values(GridType::simple)); +INSTANTIATE_TEST_SUITE_P(Vlasovian, GridTest, testing::Values(GridType::vlasovian)); + +TEST_P(GridTest, contents) { for (auto cell : grid.get_cells()) { EXPECT_NE_MPI(grid[cell], nullptr); @@ -43,7 +91,7 @@ TEST_F(SimpleGrid, contents) } } -TEST_F(SimpleGrid, contents_after_loadbalance) +TEST_P(GridTest, contents_after_loadbalance) { grid.balance_load(); for (auto cell : grid.get_cells()) { @@ -52,8 +100,7 @@ TEST_F(SimpleGrid, contents_after_loadbalance) } } -// TODO: currently only checks consistency between local cells -TEST_F(SimpleGrid, consistent_neighbors) +TEST_P(GridTest, consistent_neighbors) { auto cells = grid.get_cells(); for (auto cell : grid.get_cells()) { @@ -96,9 +143,47 @@ TEST_F(SimpleGrid, consistent_neighbors) } } +// TODO: cannot test consistency of remote neighbors without dccrg changes +TEST_P(GridTest, consistent_user_neighbors) +{ + auto cells = grid.get_cells(); + for (auto cell : grid.get_cells()) { + for (int neighborhood = 0; neighborhood < neighborhoods; ++neighborhood) { + auto* my_neighbors_of {grid.get_neighbors_of(cell, neighborhood)}; + EXPECT_NE_MPI(my_neighbors_of, nullptr); + + for (auto [neighbor, dir] : *my_neighbors_of) { + if (neighbor != dccrg::error_cell) { + EXPECT_NE_MPI(grid[neighbor], nullptr); + std::vector>> other_neighbors_to; + if (std::find(cells.begin(), cells.end(), neighbor) != cells.end()) { + auto* p {grid.get_neighbors_to(neighbor, neighborhood)}; + EXPECT_NE_MPI(p, nullptr); + other_neighbors_to = *p; + EXPECT_NE_MPI(std::find_if(other_neighbors_to.begin(), other_neighbors_to.end(), [&cell](const std::pair> pair){return pair.first == cell;}), other_neighbors_to.end()); + } + } + } + + auto* my_neighbors_to {grid.get_neighbors_to(cell, neighborhood)}; + EXPECT_NE_MPI(my_neighbors_to, nullptr); + + for (auto [neighbor, dir] : *my_neighbors_to) { + std::vector>> other_neighbors_of; + if (std::find(cells.begin(), cells.end(), neighbor) != cells.end()) { + auto* p {grid.get_neighbors_of(neighbor, neighborhood)}; + EXPECT_NE_MPI(p, nullptr); + other_neighbors_of = *p; + EXPECT_NE_MPI(std::find_if(other_neighbors_of.begin(), other_neighbors_of.end(), [&cell](const std::pair> pair){return pair.first == cell;}), other_neighbors_of.end()); + } + } + } + } +} + // TODO test proper copies and frees of dccrg.comm // Right now this can't be done because the getter is not a getter -TEST_F(SimpleGrid, copy) +TEST_P(GridTest, copy) { auto other_grid = grid; diff --git a/UnitTests/makefile b/UnitTests/makefile index dfa09c3..9b0b460 100644 --- a/UnitTests/makefile +++ b/UnitTests/makefile @@ -8,7 +8,7 @@ include ../../../MAKE/Makefile.${ARCH} CXXFLAGS+=$(INC_MPI) $(INC_BOOST) $(INC_ZOLTAN) $(INC_PROFILE) $(INC_GTEST) -DGTEST_HAS_MPI LDFLAGS+=$(LIB_BOOST) $(LIB_ZOLTAN) $(LIB_GTEST) $(LIB_PROFILE) -TESTS=validation.exe simple.exe +TESTS=validation.exe grid.exe all: $(TESTS) @@ -20,4 +20,3 @@ all: $(TESTS) clean: rm $(TESTS) - rm *.o From deba8397df4197ea57bde05446216ed3be0f3ee4 Mon Sep 17 00:00:00 2001 From: lkotipal Date: Fri, 15 Mar 2024 14:29:42 +0200 Subject: [PATCH 10/12] Tests with refinement --- UnitTests/grid.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/UnitTests/grid.cpp b/UnitTests/grid.cpp index 0f29b56..c73a1bf 100644 --- a/UnitTests/grid.cpp +++ b/UnitTests/grid.cpp @@ -30,10 +30,16 @@ class GridTest : public testing::TestWithParam { typedef dccrg::Types<3>::neighborhood_item_t neigh_t; std::vector neighborhood; - grid.set_initial_length({10, 10, 10}).set_neighborhood_length(stencil_width).initialize(MPI_COMM_WORLD); + grid.set_initial_length({size, size, size}).set_neighborhood_length(stencil_width).set_maximum_refinement_level(reflevel).initialize(MPI_COMM_WORLD); switch (GetParam()) { case GridType::simple: break; // Defaults should be fine for everything + case GridType::magnetospheric: + for (int i = 0; i < reflevel; ++i) { + grid.refine_completely_at({static_cast(size) / 2.0, static_cast(size) / 2.0, static_cast(size) / 2.0}); + grid.stop_refining(); + } + // Fallthrough case GridType::vlasovian: // Extended sysboundaries for (int x = -stencil_width; x <= stencil_width; ++x) { @@ -78,10 +84,13 @@ class GridTest : public testing::TestWithParam { dccrg::Dccrg grid; int neighborhoods {0}; const int stencil_width {3}; + const uint64_t size {10}; + int reflevel {2}; }; INSTANTIATE_TEST_SUITE_P(Simple, GridTest, testing::Values(GridType::simple)); INSTANTIATE_TEST_SUITE_P(Vlasovian, GridTest, testing::Values(GridType::vlasovian)); +INSTANTIATE_TEST_SUITE_P(Magnetospheric, GridTest, testing::Values(GridType::magnetospheric)); TEST_P(GridTest, contents) { From 280b6ec9f9dce098a5b204313e59a20bbfc1d6c9 Mon Sep 17 00:00:00 2001 From: lkotipal Date: Mon, 25 Mar 2024 14:32:03 +0200 Subject: [PATCH 11/12] Test contents of remote neighbors --- UnitTests/grid.cpp | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/UnitTests/grid.cpp b/UnitTests/grid.cpp index c73a1bf..21e31fa 100644 --- a/UnitTests/grid.cpp +++ b/UnitTests/grid.cpp @@ -69,7 +69,7 @@ class GridTest : public testing::TestWithParam { break; } - grid.set_load_balancing_method("RANDOM").balance_load(); + grid.balance_load(); // Simple data we can check for (auto cell : grid.get_cells()) { @@ -95,16 +95,40 @@ INSTANTIATE_TEST_SUITE_P(Magnetospheric, GridTest, testing::Values(GridType::mag TEST_P(GridTest, contents) { for (auto cell : grid.get_cells()) { - EXPECT_NE_MPI(grid[cell], nullptr); + ASSERT_NE_MPI(grid[cell], nullptr); EXPECT_EQ_MPI(*grid[cell], cell); } } +TEST_P(GridTest, remote_contents) +{ + for (auto cell : grid.get_cells()) { + ASSERT_NE_MPI(grid[cell], nullptr); + + for (auto& [neighbor, dir] : *grid.get_neighbors_of(cell)) { + if (neighbor != dccrg::error_cell) { + ASSERT_NE_MPI(grid[neighbor], nullptr); + EXPECT_EQ_MPI(*grid[neighbor], neighbor); + } + } + + for (int neighborhood = 0; neighborhood < neighborhoods; ++neighborhood) { + for (auto& [neighbor, dir] : *grid.get_neighbors_of(cell, neighborhood)) { + if (neighbor != dccrg::error_cell) { + ASSERT_NE_MPI(grid[neighbor], nullptr); + EXPECT_EQ_MPI(*grid[neighbor], neighbor); + } + } + } + } +} + TEST_P(GridTest, contents_after_loadbalance) { + grid.set_load_balancing_method("RANDOM").balance_load(); grid.balance_load(); for (auto cell : grid.get_cells()) { - EXPECT_NE_MPI(grid[cell], nullptr); + ASSERT_NE_MPI(grid[cell], nullptr); EXPECT_EQ_MPI(*grid[cell], cell); } } @@ -120,7 +144,7 @@ TEST_P(GridTest, consistent_neighbors) for (auto [neighbor, dir] : *my_neighbors_of) { if (neighbor != dccrg::error_cell) { - EXPECT_NE_MPI(grid[neighbor], nullptr); + ASSERT_NE_MPI(grid[neighbor], nullptr); std::vector>> other_neighbors_to; if (std::find(cells.begin(), cells.end(), neighbor) != cells.end()) { auto* p {grid.get_neighbors_to(neighbor)}; @@ -142,7 +166,7 @@ TEST_P(GridTest, consistent_neighbors) std::vector>> other_neighbors_of; if (std::find(cells.begin(), cells.end(), neighbor) != cells.end()) { auto* p {grid.get_neighbors_of(neighbor)}; - EXPECT_NE_MPI(p, nullptr); + ASSERT_NE_MPI(p, nullptr); other_neighbors_of = *p; } else { other_neighbors_of = grid.find_neighbors_of(neighbor, grid.get_neighborhood_of(), grid.get_max_ref_lvl_diff()); @@ -167,7 +191,7 @@ TEST_P(GridTest, consistent_user_neighbors) std::vector>> other_neighbors_to; if (std::find(cells.begin(), cells.end(), neighbor) != cells.end()) { auto* p {grid.get_neighbors_to(neighbor, neighborhood)}; - EXPECT_NE_MPI(p, nullptr); + ASSERT_NE_MPI(p, nullptr); other_neighbors_to = *p; EXPECT_NE_MPI(std::find_if(other_neighbors_to.begin(), other_neighbors_to.end(), [&cell](const std::pair> pair){return pair.first == cell;}), other_neighbors_to.end()); } @@ -181,7 +205,7 @@ TEST_P(GridTest, consistent_user_neighbors) std::vector>> other_neighbors_of; if (std::find(cells.begin(), cells.end(), neighbor) != cells.end()) { auto* p {grid.get_neighbors_of(neighbor, neighborhood)}; - EXPECT_NE_MPI(p, nullptr); + ASSERT_NE_MPI(p, nullptr); other_neighbors_of = *p; EXPECT_NE_MPI(std::find_if(other_neighbors_of.begin(), other_neighbors_of.end(), [&cell](const std::pair> pair){return pair.first == cell;}), other_neighbors_of.end()); } From ef561fb055d2a2aad0953eebdba622666f378807 Mon Sep 17 00:00:00 2001 From: lkotipal Date: Mon, 25 Mar 2024 16:09:40 +0200 Subject: [PATCH 12/12] -lnophiprof example so AMR works --- UnitTests/makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/UnitTests/makefile b/UnitTests/makefile index 9b0b460..f6eeab1 100644 --- a/UnitTests/makefile +++ b/UnitTests/makefile @@ -4,9 +4,10 @@ include ../../../MAKE/Makefile.${ARCH} # These should be in Makefile.${ARCH} # INC_GTEST=-I/projappl/project_2005018/lkotipal/libraries/gtest/include # LIB_GTEST=-L/projappl/project_2005018/lkotipal/libraries/gtest/lib64 -lgtest -Wl,-rpath=/projappl/project_2005018/lkotipal/libraries/gtest/lib64 +# LIB_NOPROFILE = -L$(LIBRARY_PREFIX)/phiprof/lib -lnophiprof -Wl,-rpath=$(LIBRARY_PREFIX)/phiprof/lib CXXFLAGS+=$(INC_MPI) $(INC_BOOST) $(INC_ZOLTAN) $(INC_PROFILE) $(INC_GTEST) -DGTEST_HAS_MPI -LDFLAGS+=$(LIB_BOOST) $(LIB_ZOLTAN) $(LIB_GTEST) $(LIB_PROFILE) +LDFLAGS+=$(LIB_BOOST) $(LIB_ZOLTAN) $(LIB_GTEST) $(LIB_NOPROFILE) TESTS=validation.exe grid.exe