From ee6aae6176e374f8dd41baf34657013cb462ba2a Mon Sep 17 00:00:00 2001 From: Sebastian Eibl <sebastian.eibl@fau.de> Date: Tue, 18 Jul 2017 10:53:16 +0200 Subject: [PATCH] minimal working example for issue 20 --- src/blockforest/BlockForest.cpp | 2 +- tests/blockforest/CMakeLists.txt | 13 ++++- tests/blockforest/SaveLoadTest.cpp | 94 ++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 tests/blockforest/SaveLoadTest.cpp diff --git a/src/blockforest/BlockForest.cpp b/src/blockforest/BlockForest.cpp index dc67a03e3..9a95eaf21 100644 --- a/src/blockforest/BlockForest.cpp +++ b/src/blockforest/BlockForest.cpp @@ -355,7 +355,7 @@ BlockForest::BlockForest( const uint_t process, const char* const filename, cons uint_t offset = 0; std::vector< uint8_t > buffer; - if( broadcastFile ) + if( broadcastFile && (mpi::MPIManager::instance()->numProcesses() > 1) ) { std::ifstream file; uint_t length = 0; diff --git a/tests/blockforest/CMakeLists.txt b/tests/blockforest/CMakeLists.txt index 0e590e8aa..cdadb523d 100644 --- a/tests/blockforest/CMakeLists.txt +++ b/tests/blockforest/CMakeLists.txt @@ -13,6 +13,17 @@ waLBerla_execute_test( NAME SetupBlockForestTest LABELS longrun CONFIGURATIONS R waLBerla_compile_test( FILES BlockForestTest.cpp ) waLBerla_execute_test( NAME BlockForestTest PROCESSES 4 ) +waLBerla_compile_test( NAME SaveLoad FILES SaveLoadTest.cpp DEPENDS core blockforest ) +waLBerla_execute_test( NAME SaveLoad01 COMMAND $<TARGET_FILE:SaveLoad> PROCESSES 1 ) +waLBerla_execute_test( NAME SaveLoad02 COMMAND $<TARGET_FILE:SaveLoad> PROCESSES 2 ) +waLBerla_execute_test( NAME SaveLoad04 COMMAND $<TARGET_FILE:SaveLoad> PROCESSES 4 ) +waLBerla_execute_test( NAME SaveLoad08 COMMAND $<TARGET_FILE:SaveLoad> PROCESSES 8 ) +if( WALBERLA_BUILD_WITH_MPI ) +set_property( TEST SaveLoad02 PROPERTY DEPENDS SaveLoad01 ) #serialize runs of tets to avoid i/o conflicts when running ctest with -jN +set_property( TEST SaveLoad04 PROPERTY DEPENDS SaveLoad02 ) #serialize runs of tets to avoid i/o conflicts when running ctest with -jN +set_property( TEST SaveLoad08 PROPERTY DEPENDS SaveLoad04 ) #serialize runs of tets to avoid i/o conflicts when running ctest with -jN +endif() + waLBerla_compile_test( FILES StructuredBlockForestTest.cpp ) waLBerla_execute_test( NAME StructuredBlockForestTest ) @@ -36,4 +47,4 @@ waLBerla_execute_test( NAME GhostLayerCommTest8 COMMAND $<TARGET_FILE:GhostLayer waLBerla_compile_test( FILES communication/DirectionBasedReduceCommTest.cpp DEPENDS field timeloop ) waLBerla_execute_test( NAME DirectionBasedReduceCommTest1 COMMAND $<TARGET_FILE:DirectionBasedReduceCommTest> ) waLBerla_execute_test( NAME DirectionBasedReduceCommTest3 COMMAND $<TARGET_FILE:DirectionBasedReduceCommTest> PROCESSES 3 ) -waLBerla_execute_test( NAME DirectionBasedReduceCommTest8 COMMAND $<TARGET_FILE:DirectionBasedReduceCommTest> PROCESSES 8 ) \ No newline at end of file +waLBerla_execute_test( NAME DirectionBasedReduceCommTest8 COMMAND $<TARGET_FILE:DirectionBasedReduceCommTest> PROCESSES 8 ) diff --git a/tests/blockforest/SaveLoadTest.cpp b/tests/blockforest/SaveLoadTest.cpp new file mode 100644 index 000000000..87e083633 --- /dev/null +++ b/tests/blockforest/SaveLoadTest.cpp @@ -0,0 +1,94 @@ +//====================================================================================================================== +// +// This file is part of waLBerla. waLBerla is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// waLBerla 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 General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file SaveLoadTest.cpp +//! \author Sebastian Eibl <sebastian.eibl@fau.de> +// +//====================================================================================================================== + + +#include "blockforest/all.h" +#include "core/all.h" +#include "core/math/IntegerFactorization.h" +#include "domain_decomposition/all.h" + +#include "core/debug/TestSubsystem.h" + +using namespace walberla; +using namespace walberla::blockforest; + +int main( int argc, char ** argv ) +{ + std::vector< uint64_t > dump; + std::vector< uint64_t > check; + + walberla::debug::enterTestMode(); + + WALBERLA_MPI_SECTION() + { + walberla::MPIManager::instance()->initializeMPI( &argc, &argv ); + } + + WALBERLA_LOG_DEVEL_ON_ROOT("*** DUMPING ***"); + + dump.clear(); + + auto proc = math::getFactors3D(uint_c( MPIManager::instance()->numProcesses() )); + + auto forestDump = createUniformBlockGrid( math::AABB(0,0,0,60,60,60), // domain + 2,2,2, // number of blocks + 1,1,1, // cells + proc[0],proc[1],proc[2]); // on block per prozess + forestDump->getBlockForest().saveToFile("SerializeDeserialize.sbf"); + + for (auto blockIt = forestDump->begin(); blockIt != forestDump->end(); ++blockIt) + { + WALBERLA_LOG_DEVEL("DUMPING BLOCK (" << blockIt->getId() << ") " << blockIt->getAABB() ); + dump.push_back( blockIt->getId().getID() ); + } + + WALBERLA_MPI_SECTION() + { + WALBERLA_MPI_BARRIER(); + } + + WALBERLA_LOG_DEVEL_ON_ROOT("*** CHECKING ***"); + + check.clear(); + + auto forestCheck = shared_ptr< BlockForest >( new BlockForest( uint_c( MPIManager::instance()->rank() ), "SerializeDeserialize.sbf" ) ); + + for (auto blockIt = forestCheck->begin(); blockIt != forestCheck->end(); ++blockIt) + { + WALBERLA_LOG_DEVEL("CHECKING BLOCK (" << blockIt->getId() << ") " << blockIt->getAABB() ); + check.push_back( blockIt->getId().getID() ); + } + + WALBERLA_CHECK_EQUAL(forestDump->getBlockIdBytes(), forestCheck->getBlockIdBytes()); + WALBERLA_CHECK_EQUAL(forestDump->getDepth(), forestCheck->getDepth()); + WALBERLA_CHECK_EQUAL(forestDump->getDomain(), forestCheck->getDomain()); + WALBERLA_CHECK_EQUAL(forestDump->getNumberOfBlocks(), forestCheck->getNumberOfBlocks()); + + std::sort(dump.begin(), dump.end()); + std::sort(check.begin(), check.end()); + + WALBERLA_CHECK_EQUAL( dump.size(), check.size() ); + for (size_t i = 0; i < dump.size(); ++i) + { + WALBERLA_CHECK_EQUAL(dump[i], check[i]); + } + + return EXIT_SUCCESS; +} -- GitLab