diff --git a/test/test_synchronizer/CMakeLists.txt b/test/test_synchronizer/CMakeLists.txt index 3d24088fc..7c58ea337 100644 --- a/test/test_synchronizer/CMakeLists.txt +++ b/test/test_synchronizer/CMakeLists.txt @@ -1,77 +1,83 @@ #=============================================================================== # @file CMakeLists.txt # # @author Nicolas Richart # # @date creation: Fri Sep 03 2010 # @date last modification: Fri Jan 26 2018 # # @brief configuration for synchronizer tests # # @section LICENSE # # Copyright (©) 2010-2018 EPFL (Ecole Polytechnique Fédérale de Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # Akantu is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License along with Akantu. If not, see . # # @section DESCRIPTION # #=============================================================================== add_mesh(test_synchronizer_communication_mesh cube.geo 3 2) register_test(test_dof_synchronizer SOURCES test_dof_synchronizer.cc test_data_accessor.hh FILES_TO_COPY bar.msh PACKAGE parallel PARALLEL ) # if(DEFINED AKANTU_DAMAGE_NON_LOCAL) # add_executable(test_grid_synchronizer_check_neighbors test_grid_synchronizer_check_neighbors.cc test_grid_tools.hh) # target_link_libraries(test_grid_synchronizer_check_neighbors akantu) # if(AKANTU_EXTRA_CXX_FLAGS) # set_target_properties(test_grid_synchronizer_check_neighbors PROPERTIES COMPILE_FLAGS ${AKANTU_EXTRA_CXX_FLAGS}) # endif() # endif() # register_test(test_grid_synchronizer # SOURCES test_grid_synchronizer.cc test_data_accessor.hh # DEPENDS test_synchronizer_communication_mesh test_grid_synchronizer_check_neighbors # EXTRA_FILES test_grid_synchronizer_check_neighbors.cc test_grid_tools.hh # PACKAGE damage_non_local # ) +register_gtest_sources( + SOURCES test_communicator.cc + PACKAGE core + ) + + register_gtest_sources( SOURCES test_synchronizer_communication.cc test_data_accessor.hh test_synchronizers_fixture.hh PACKAGE parallel ) register_gtest_sources( SOURCES test_node_synchronizer.cc test_synchronizers_fixture.hh PACKAGE parallel ) register_gtest_sources( SOURCES test_data_distribution.cc test_synchronizers_fixture.hh DEPENDS test_synchronizer_communication_mesh PACKAGE parallel ) add_mesh(test_facet_synchronizer_mesh facet.geo 3 2) register_gtest_sources( SOURCES test_facet_synchronizer.cc test_data_accessor.hh test_synchronizers_fixture.hh DEPENDS test_facet_synchronizer_mesh PACKAGE parallel cohesive_element ) register_gtest_test(test_synchronizers DEPENDS test_synchronizer_communication_mesh PARALLEL) diff --git a/test/test_synchronizer/test_communicator.cc b/test/test_synchronizer/test_communicator.cc new file mode 100644 index 000000000..8ca8209cb --- /dev/null +++ b/test/test_synchronizer/test_communicator.cc @@ -0,0 +1,138 @@ +/** + * @file test_communicator.cc + * + * @author Nicolas Richart + * + * @date creation Thu Feb 21 2019 + * + * @brief A Documented file. + * + * @section LICENSE + * + * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ +/* -------------------------------------------------------------------------- */ +#include +#include +#include +/* -------------------------------------------------------------------------- */ +#include +#include +/* -------------------------------------------------------------------------- */ + +using namespace akantu; + +TEST(Communicator, Bcast) { + auto r = 0xdeadbeef; + + auto & c = Communicator::getStaticCommunicator(); + c.broadcast(r); + + EXPECT_EQ(r, 0xdeadbeef); +} + +TEST(Communicator, ReceiveAny) { + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(1, 10); + std::vector reqs; + + auto & c = Communicator::getStaticCommunicator(); + auto && rank = c.whoAmI(); + auto && size = c.getNbProc(); + + for (auto n : arange(100)) { + AKANTU_DEBUG_INFO("ROUND " << n); + auto tag = Tag::genTag(0, 1, 0); + + if (rank == 0) { + std::vector sends(size - 1); + for (auto & s : sends) { + s = dis(gen); + } + + c.broadcast(sends); + AKANTU_DEBUG_INFO("Messages " << [&]() { + std::string msgs; + for (auto s : enumerate(sends)) { + if (std::get<0>(s) != 0) + msgs += ", "; + msgs += std::to_string(std::get<0>(s) + 1) + ": " + + std::to_string(std::get<1>(s)); + } + return msgs; + }()); + + int nb_recvs = 0; + for (auto && data : enumerate(sends)) { + auto & send = std::get<1>(data); + int p = std::get<0>(data) + 1; + + if (send > 5) { + reqs.push_back( + c.asyncSend(send, p, tag, CommunicationMode::_synchronous)); + } + + if (p <= send) { + ++nb_recvs; + } + } + + c.receiveAnyNumber(reqs, + [&](auto && proc, auto && msg) { + EXPECT_EQ(msg[0], sends[proc - 1] + 100 * proc); + EXPECT_LE(proc, sends[proc - 1]); + --nb_recvs; + }, + tag); + EXPECT_EQ(nb_recvs, 0); + } else { + std::vector recv(size - 1); + c.broadcast(recv); + + AKANTU_DEBUG_INFO("Messages " << [&]() { + std::string msgs; + for (auto s : enumerate(recv)) { + if (std::get<0>(s) != 0) + msgs += ", "; + msgs += std::to_string(std::get<0>(s) + 1) + ": " + + std::to_string(std::get<1>(s)); + } + return msgs; + }()); + auto send = recv[rank - 1] + 100 * rank; + if (rank <= recv[rank - 1]) { + reqs.push_back( + c.asyncSend(send, 0, tag, CommunicationMode::_synchronous)); + } + + bool has_recv = false; + c.receiveAnyNumber(reqs, + [&](auto && proc, auto && msg) { + EXPECT_EQ(msg[0], recv[rank - 1]); + EXPECT_EQ(proc, 0); + has_recv = true; + }, + tag); + + bool should_recv = (recv[rank - 1] > 5); + EXPECT_EQ(has_recv, should_recv); + } + reqs.clear(); + } +}