Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ugbase/bridge/misc_bridges/pcl_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#ifdef UG_PARALLEL
#include "pcl/pcl.h"
#include "pcl/space_time_communicator.hpp"
#endif

using namespace std;
Expand Down Expand Up @@ -155,6 +156,24 @@ void RegisterBridge_PCL(Registry& reg, string parentGroup)
reg.add_function("ParallelVecMax", &ParallelVecMax<double>, grp, "tmin", "t", "returns the maximum of t over all processes. note: you have to assure that all processes call this function.");
reg.add_function("ParallelVecSum", &ParallelVecSum<double>, grp, "tsum", "t", "returns the sum of t over all processes. note: you have to assure that all processes call this function.");
reg.add_function("UG_PARALLEL", &ug_parallel, grp);

// Space Time Communicator
{
using T_SpaceTimeCommunicator = pcl::SpaceTimeCommunicator ;
const std::string name = "SpaceTimeCommunicator";
reg.add_class_<T_SpaceTimeCommunicator>(name, "SpaceTimeCommunicator", "")
.add_constructor()
.add_method("split", &T_SpaceTimeCommunicator::split)
.add_method("unsplit", &T_SpaceTimeCommunicator::unsplit)
.add_method("get_global_rank", &T_SpaceTimeCommunicator::get_global_rank)
.add_method("get_spatial_rank", &T_SpaceTimeCommunicator::get_spatial_rank)
.add_method("get_temporal_rank", &T_SpaceTimeCommunicator::get_temporal_rank)
.add_method("get_global_size", &T_SpaceTimeCommunicator::get_global_size)
.add_method("get_spatial_size", &T_SpaceTimeCommunicator::get_spatial_size)
.add_method("get_temporal_size", &T_SpaceTimeCommunicator::get_temporal_size)
.add_method("sleep", &T_SpaceTimeCommunicator::sleep)
.set_construct_as_smart_pointer(true);
}
}

#else // UG_PARALLEL
Expand Down
1 change: 1 addition & 0 deletions ugbase/pcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(srcPcl parallel_archive.cpp
pcl_multi_group_communicator.cpp
pcl_process_communicator.cpp
pcl_util.cpp)
set(HEADERS space_time_communicator.hpp)

if(BUILD_ONE_LIB)
EXPORTSOURCES(ugbase/pcl ${srcPcl})
Expand Down
150 changes: 150 additions & 0 deletions ugbase/pcl/space_time_communicator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Copyright (c) 2025: G-CSC, Goethe University Frankfurt
* Author: Arne Nägel, Martin Parnet

* Copyright (c) 2026: KAUST, King Abdullah University of Science and Technology
* Author: Daniel Gonzalez
*
* This file is part of UG4.
*
* UG4 is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License version 3 (as published by the
* Free Software Foundation) with the following additional attribution
* requirements (according to LGPL/GPL v3 §7):
*
* (1) The following notice must be displayed in the Appropriate Legal Notices
* of covered and combined works: "Based on UG4 (www.ug4.org/license)".
*
* (2) The following notice must be displayed at a prominent place in the
* terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
*
* (3) The following bibliography is recommended for citation and must be
* preserved in all covered files:
* "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
* parallel geometric multigrid solver on hierarchically distributed grids.
* Computing and visualization in science 16, 4 (2013), 151-164"
* "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
* flexible software system for simulating pde based models on high performance
* computers. Computing and visualization in science 16, 4 (2013), 165-179"
*
* This program 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.
*/

#ifndef __H__PCL__PCL_SPACE_TIME_COMMUNICATOR_H
#define __H__PCL__PCL_SPACE_TIME_COMMUNICATOR_H


#include "pcl/pcl_comm_world.h"

namespace pcl{

class SpaceTimeCommunicator {
public:

//--------------------------------------------------------------------------------------------------------------

SpaceTimeCommunicator() = default;
virtual ~SpaceTimeCommunicator() = default;

//--------------------------------------------------------------------------------------------------------------

void split(int numTemporalProcesses)
{

int world_size, myid;

Check warning on line 57 in ugbase/pcl/space_time_communicator.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define each identifier in a dedicated statement.

See more on https://sonarcloud.io/project/issues?id=UG4_ugcore&issues=AZ2BB7YWB1HMB1XNi9Ar&open=AZ2BB7YWB1HMB1XNi9Ar&pullRequest=121
MPI_Comm_size(PCL_COMM_WORLD, &world_size);

globalsize_ = world_size;
spatialsize_ = world_size / numTemporalProcesses;
temporalsize_ = numTemporalProcesses;

if(world_size % numTemporalProcesses != 0 )
UG_THROW("SpaceTimeCommunicator: world_size is not a multiple of # temporal processes:"
" Change the number of processors to "
<< numTemporalProcesses * spatialsize_ <<" or "
<< (numTemporalProcesses) * (spatialsize_ + 1 )<<".\n");


GLOBAL = PCL_COMM_WORLD;



MPI_Comm_rank(GLOBAL, &myid);
const int xcolor = myid / spatialsize_;
const int tcolor = myid % spatialsize_;

MPI_Comm_split(GLOBAL, xcolor, myid, &SPATIAL);
MPI_Comm_split(GLOBAL, tcolor, myid, &TEMPORAL);

if (verbose_)
{
UG_LOG("World size after splitting is:\t" << world_size );
UG_LOG( "... with temporal world size:\t" << temporalsize_ );
UG_LOG( "... and spatial world size:\t" << spatialsize_ );
}


PCL_COMM_WORLD = SPATIAL; // replaces ugs world communicator with the communicator for spatial
}

void unsplit() {
PCL_COMM_WORLD = GLOBAL; // reset the world communicator

MPI_Comm_free(&SPATIAL); // free the spatial communicator
SPATIAL = PCL_COMM_WORLD;

MPI_Comm_free(&TEMPORAL);// free the temporal communicator
TEMPORAL = PCL_COMM_WORLD;
}

int get_global_size() const {
return globalsize_;
}

int get_temporal_size() const {
return temporalsize_;
}

int get_spatial_size() const {
return spatialsize_;
}

int get_temporal_rank() const {
int rank = 0;
MPI_Comm_rank(TEMPORAL, &rank);
return rank;
}

int get_spatial_rank() const {
int rank = 0;
MPI_Comm_rank(SPATIAL, &rank);
return rank;
}

int get_global_rank() const {
int rank = 0;
MPI_Comm_rank(GLOBAL, &rank);
return rank;
}

void sleep(int microseconds) {

Check warning on line 133 in ugbase/pcl/space_time_communicator.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This function should be declared "const".

See more on https://sonarcloud.io/project/issues?id=UG4_ugcore&issues=AZ2BB7YWB1HMB1XNi9As&open=AZ2BB7YWB1HMB1XNi9As&pullRequest=121
usleep(microseconds);

Check warning on line 134 in ugbase/pcl/space_time_communicator.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove use of this obsolete "usleep" function. Replace it by a call to "nanosleep" or "setitimer".

See more on https://sonarcloud.io/project/issues?id=UG4_ugcore&issues=AZ2BB7YWB1HMB1XNi9At&open=AZ2BB7YWB1HMB1XNi9At&pullRequest=121
}

//--------------------------------------------------------------------------------------------------------------
MPI_Comm GLOBAL = PCL_COMM_WORLD;
MPI_Comm TEMPORAL = PCL_COMM_WORLD;
MPI_Comm SPATIAL = PCL_COMM_WORLD;

bool verbose_ = true;
int globalsize_ = 1;
int temporalsize_ = 1;
int spatialsize_ = 1;

//--------------------------------------------------------------------------------------------------------------
};
}
#endif
Loading