From 11c13113bfd9f5963ce05d99a7429159def68426 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Fri, 19 Oct 2018 19:10:53 +0200 Subject: [PATCH] Add broadcast unit tests --- tests/mpi_test_Messenger.cpp | 60 +++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/tests/mpi_test_Messenger.cpp b/tests/mpi_test_Messenger.cpp index d422cf20f..88a8122d0 100644 --- a/tests/mpi_test_Messenger.cpp +++ b/tests/mpi_test_Messenger.cpp @@ -93,7 +93,7 @@ TEST_CASE("Messenger", "[mpi]") { REQUIRE(size == commSize()); } - SECTION("allToAll") { + SECTION("all to all") { // chars mpi_check::test_allToAll<char>(); mpi_check::test_allToAll<wchar_t>(); @@ -124,4 +124,62 @@ TEST_CASE("Messenger", "[mpi]") { // compound trivial type mpi_check::test_allToAll<mpi_check::tri_int>(); } + + SECTION("broadcast value") { + { + // simple type + int value{(3+commRank())*2}; + broadcast(value, 0); + REQUIRE(value == 6); + } + + { + // trivial simple type + mpi_check::integer value{(3+commRank())*2}; + broadcast(value, 0); + REQUIRE((value == 6)); + } + + { + // compound trivial type + mpi_check::tri_int value{(3+commRank())*2, 2+commRank(), 4-commRank()}; + broadcast(value, 0); + REQUIRE((value == mpi_check::tri_int{6,2,4})); + } + } + + SECTION("broadcast array") { + { + // simple type + Array<int> array(3); + array[0] = (3+commRank())*2; + array[1] = 2+commRank(); + array[2] = 4-commRank(); + broadcast(array, 0); + REQUIRE(((array[0]==6) and (array[1]==2) and (array[2]==4))); + } + + { + // trivial simple type + Array<mpi_check::integer> array(3); + array[0] = (3+commRank())*2; + array[1] = 2+commRank(); + array[2] = 4-commRank(); + broadcast(array, 0); + REQUIRE(((array[0]==6) and (array[1]==2) and (array[2]==4))); + } + + { + // compound trivial type + Array<mpi_check::tri_int> array(3); + array[0] = mpi_check::tri_int{(3+commRank())*2, 2+commRank(), 4-commRank()}; + array[1] = mpi_check::tri_int{(2+commRank())*4, 3+commRank(), 1-commRank()}; + array[2] = mpi_check::tri_int{(5+commRank()), -3+commRank(), commRank()}; + broadcast(array, 0); + REQUIRE(((array[0] == mpi_check::tri_int{6, 2,4}) and + (array[1] == mpi_check::tri_int{8, 3,1}) and + (array[2] == mpi_check::tri_int{5,-3,0}))); + } + } + } -- GitLab