From 754758386e3f556afca7aacf95be32065ced7575 Mon Sep 17 00:00:00 2001 From: Lukas Werner <lks.werner@fau.de> Date: Wed, 21 Mar 2018 20:52:54 +0100 Subject: [PATCH] Change handling of non-MPI builds --- src/core/mpi/MPIWrapper.h | 6 ++++++ src/pe/raytracing/Raytracer.cpp | 31 +++++++++++++++---------------- src/pe/raytracing/Raytracer.h | 8 +------- tests/pe/Raytracing.cpp | 7 ++----- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/core/mpi/MPIWrapper.h b/src/core/mpi/MPIWrapper.h index f97cb06b1..112e59d9f 100644 --- a/src/core/mpi/MPIWrapper.h +++ b/src/core/mpi/MPIWrapper.h @@ -107,6 +107,7 @@ struct MPI_Status int MPI_ERROR; }; +typedef void (MPI_User_function) (void * a, void * b, int * len, MPI_Datatype * ); const int MPI_COMM_NULL = 0; @@ -265,6 +266,11 @@ inline int MPI_Error_string ( int, char*, int* ) { WALBERLA_MPI_FUNCTION_ERROR } inline double MPI_Wtime() { WALBERLA_MPI_FUNCTION_ERROR } +inline int MPI_Op_create(MPI_User_function*, int, MPI_Op*) { WALBERLA_MPI_FUNCTION_ERROR }; +inline int MPI_Type_create_struct(int, const int[], MPI_Aint[], MPI_Datatype[], MPI_Datatype*) { WALBERLA_MPI_FUNCTION_ERROR }; +inline int MPI_Type_create_resized(MPI_Datatype, MPI_Aint, MPI_Aint, MPI_Datatype*) { WALBERLA_MPI_FUNCTION_ERROR }; +int MPI_Type_commit(MPI_Datatype*) { WALBERLA_MPI_FUNCTION_ERROR }; + #undef WALBERLA_MPI_FUNCTION_ERROR } // namespace mpistubs diff --git a/src/pe/raytracing/Raytracer.cpp b/src/pe/raytracing/Raytracer.cpp index 9f6bf4b46..2edf38d51 100644 --- a/src/pe/raytracing/Raytracer.cpp +++ b/src/pe/raytracing/Raytracer.cpp @@ -20,12 +20,12 @@ #include "Raytracer.h" #include "geometry/structured/extern/lodepng.h" +#include "core/mpi/all.h" namespace walberla { namespace pe { namespace raytracing { -#ifdef WALBERLA_BUILD_WITH_MPI void BodyIntersectionInfo_Comparator_MPI_OP( BodyIntersectionInfo *in, BodyIntersectionInfo *inout, int *len, MPI_Datatype *dptr) { WALBERLA_UNUSED(dptr); for (int i = 0; i < *len; ++i) { @@ -48,7 +48,6 @@ void BodyIntersectionInfo_Comparator_MPI_OP( BodyIntersectionInfo *in, BodyInter inout++; } } -#endif /*!\brief Instantiation constructor for the Raytracer class. * @@ -102,7 +101,9 @@ Raytracer::Raytracer(const shared_ptr<BlockStorage> forest, const BlockDataID st setupView_(); setupFilenameRankWidth_(); - setupMPI_(); + WALBERLA_MPI_SECTION() { + setupMPI_(); + } } /*!\brief Instantiation constructor for the Raytracer class using a config object for view setup. @@ -191,7 +192,9 @@ Raytracer::Raytracer(const shared_ptr<BlockStorage> forest, const BlockDataID st setupView_(); setupFilenameRankWidth_(); - setupMPI_(); + WALBERLA_MPI_SECTION() { + setupMPI_(); + } } /*!\brief Utility function for setting up the view plane and calculating required variables. @@ -217,16 +220,13 @@ void Raytracer::setupView_() { /*!\brief Utility function for initializing the attribute filenameRankWidth. */ void Raytracer::setupFilenameRankWidth_() { - WALBERLA_MPI_SECTION() { - int numProcesses = mpi::MPIManager::instance()->numProcesses(); - filenameRankWidth_ = uint8_c(log10(numProcesses)+1); - } + int numProcesses = mpi::MPIManager::instance()->numProcesses(); + filenameRankWidth_ = uint8_c(log10(numProcesses)+1); } /*!\brief Utility function for setting up the MPI datatype and operation. */ void Raytracer::setupMPI_() { -#ifdef WALBERLA_BUILD_WITH_MPI MPI_Op_create((MPI_User_function *)BodyIntersectionInfo_Comparator_MPI_OP, true, &bodyIntersectionInfo_reduction_op); const int nblocks = 7; @@ -257,7 +257,6 @@ void Raytracer::setupMPI_() { MPI_Type_create_resized( tmp_type, lb, extent, &bodyIntersectionInfo_mpi_type ); MPI_Type_commit(&bodyIntersectionInfo_mpi_type); -#endif } /*!\brief Generates the filename for output files. @@ -410,7 +409,12 @@ void Raytracer::writeImageToFile(const std::vector<BodyIntersectionInfo>& inters * \attention This function only works on MPI builds due to the explicit usage of MPI routines. */ void Raytracer::syncImageUsingMPIReduce(std::vector<BodyIntersectionInfo>& intersectionsBuffer, WcTimingTree* tt) { -#ifdef WALBERLA_BUILD_WITH_MPI + WALBERLA_NON_MPI_SECTION() { + WALBERLA_UNUSED(intersectionsBuffer); + WALBERLA_UNUSED(tt); + WALBERLA_ABORT("Cannot call MPI reduce on a non-MPI build due to usage of MPI-specific code."); + } + WALBERLA_MPI_BARRIER(); if (tt != NULL) tt->start("Reduction"); int rank = mpi::MPIManager::instance()->rank(); @@ -429,11 +433,6 @@ void Raytracer::syncImageUsingMPIReduce(std::vector<BodyIntersectionInfo>& inter WALBERLA_MPI_BARRIER(); if (tt != NULL) tt->stop("Reduction"); -#else - WALBERLA_UNUSED(intersectionsBuffer); - WALBERLA_UNUSED(tt); - WALBERLA_ABORT("Cannot call MPI reduce on a non-MPI build due to usage of MPI-specific code."); -#endif } /*!\brief Conflate the intersectionsBuffer of each process onto the root process using MPI_Gather. diff --git a/src/pe/raytracing/Raytracer.h b/src/pe/raytracing/Raytracer.h index 8d77d63ee..4ca1008fe 100644 --- a/src/pe/raytracing/Raytracer.h +++ b/src/pe/raytracing/Raytracer.h @@ -35,9 +35,6 @@ #include "pe/ccd/ICCD.h" #include <pe/ccd/HashGrids.h> -#include "core/mpi/MPIManager.h" -#include "core/mpi/MPIWrapper.h" -#include "core/mpi/all.h" #include <stddef.h> using namespace walberla::pe; @@ -161,10 +158,8 @@ private: real_t pixelHeight_; //!< The height of a pixel of the generated image in the viewing plane. //@} -#ifdef WALBERLA_BUILD_WITH_MPI MPI_Op bodyIntersectionInfo_reduction_op; MPI_Datatype bodyIntersectionInfo_mpi_type; -#endif public: /*!\name Get functions */ @@ -713,8 +708,7 @@ void Raytracer::generateImage(const size_t timestep, WcTimingTree* tt) { syncImageUsingMPIGather(intersections, intersectionsBuffer, tt); break; } - } - WALBERLA_NON_MPI_SECTION() { + } else { syncImageUsingMPIGather(intersections, intersectionsBuffer, tt); } diff --git a/tests/pe/Raytracing.cpp b/tests/pe/Raytracing.cpp index 5b450b9d1..b3910f550 100644 --- a/tests/pe/Raytracing.cpp +++ b/tests/pe/Raytracing.cpp @@ -352,7 +352,6 @@ void RaytracerSpheresTestScene(Raytracer::Algorithm raytracingAlgorithm = Raytra Vec3(-5,5,5), Vec3(-1,5,5), Vec3(0,0,1), //-5,5,5; -1,5,5 lighting, Color(real_t(0.2),real_t(0.2),real_t(0.2)), - real_t(2), customSpheresBodyToShadingParams); MaterialID iron = Material::find("iron"); @@ -535,7 +534,6 @@ void HashGridsTest(Raytracer::Algorithm raytracingAlgorithm, uint8_t antiAliasFa std::get<2>(vector), lighting0, Color(real_t(0.2),real_t(0.2),real_t(0.2)), - real_t(2), customHashGridsBodyToShadingParams); raytracer.setImageOutputEnabled(true); raytracer.setFilenameTimestepWidth(12); @@ -579,7 +577,6 @@ void raytraceArtifactsForest(Raytracer::Algorithm raytracingAlgorithm, uint8_t a upVector, lighting, Color(real_t(0.2),real_t(0.2),real_t(0.2)), - real_t(2), customArtifactsBodyToShadingParams); raytracer.setImageOutputEnabled(true); raytracer.setFilenameTimestepWidth(timestepWidth); @@ -818,8 +815,7 @@ void HashGridsTestScene(Raytracer::Algorithm raytracingAlgorithm = Raytracer::RA std::get<1>(vector), std::get<2>(vector), lighting, - Color(real_t(0.2),real_t(0.2),real_t(0.2)), - real_t(2)); + Color(real_t(0.2),real_t(0.2),real_t(0.2))); raytracer.setRaytracingAlgorithm(raytracingAlgorithm); raytracer.setImageOutputEnabled(true); @@ -855,6 +851,7 @@ int main( int argc, char** argv ) RaytracerTest(algorithm, antiAliasFactor); //RaytracerSpheresTestScene(algorithm, antiAliasFactor); HashGridsTestScene(algorithm, antiAliasFactor); + HashGridsTest(algorithm, antiAliasFactor, 50, 30, 130, 10); -- GitLab