From 18a0c4a0d92ac36a4553fa4303c59b53bb062ee6 Mon Sep 17 00:00:00 2001 From: Lukas Werner <lks.werner@fau.de> Date: Wed, 31 Jan 2018 11:14:05 +0100 Subject: [PATCH] Distributed raytracing of global objects over all processes --- src/pe/raytracing/Raytracer.h | 42 ++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/pe/raytracing/Raytracer.h b/src/pe/raytracing/Raytracer.h index 46349a7b8..dee4ce717 100644 --- a/src/pe/raytracing/Raytracer.h +++ b/src/pe/raytracing/Raytracer.h @@ -320,6 +320,9 @@ template <typename BodyTypeTuple> void Raytracer::rayTrace(const size_t timestep) { real_t inf = std::numeric_limits<real_t>::max(); + int numProcesses = mpi::MPIManager::instance()->numProcesses(); + int rank = mpi::MPIManager::instance()->rank(); + std::vector<real_t> tBuffer(pixelsVertical_ * pixelsHorizontal_, inf); std::vector<Vec3> imageBuffer(pixelsVertical_ * pixelsHorizontal_); std::vector<BodyIntersectionInfo> intersections; // contains for each pixel information about an intersection, if existent @@ -366,26 +369,29 @@ void Raytracer::rayTrace(const size_t timestep) { } } - // only iterate over global body storage in one process. - // optimization required, e.g. split up global bodies over all processes. - WALBERLA_ROOT_SECTION() { - for( auto bodyIt = globalBodyStorage_->begin(); bodyIt != globalBodyStorage_->end(); ++bodyIt ) { - if (bodyIt->getTypeID() == Plane::getStaticTypeID()) { - PlaneID plane = (Plane*)(*bodyIt); - if (!isPlaneVisible(plane, ray)) { - continue; - } - } - - bool intersects = SingleCast<BodyTypeTuple, IntersectsFunctor, bool>::execute(*bodyIt, func); - - if (intersects && t < t_closest) { - // body was shot by ray and currently closest to camera - t_closest = t; - body_closest = *bodyIt; - n_closest = n; + int i = 0; + for(auto bodyIt: *globalBodyStorage_) { + i++; + // distribute global objects more or less evenly on all processes + if (((i-1)%numProcesses) != rank) { + continue; + } + + if (bodyIt->getTypeID() == Plane::getStaticTypeID()) { + PlaneID plane = (PlaneID)bodyIt; + if (!isPlaneVisible(plane, ray)) { + continue; } } + + bool intersects = SingleCast<BodyTypeTuple, IntersectsFunctor, bool>::execute(bodyIt, func); + + if (intersects && t < t_closest) { + // body was shot by ray and currently closest to camera + t_closest = t; + body_closest = bodyIt; + n_closest = n; + } } if (!realIsIdentical(t_closest, inf) && body_closest != NULL) { -- GitLab