36#ifndef MPI_MPICOMMUNICATOR_H
37#define MPI_MPICOMMUNICATOR_H
48#ifdef VF_DOUBLE_ACCURACY
49#define VF_MPI_REAL MPI_DOUBLE
51#define VF_MPI_REAL MPI_FLOAT
69 double Wtime()
override;
80 bool isRoot()
const override;
88 std::vector<std::string>
gather(
const std::string &
str)
override;
89 std::vector<int>
gather(std::vector<int> &values)
override;
90 std::vector<float>
gather(std::vector<float> &values)
override;
91 std::vector<double>
gather(std::vector<double> &values)
override;
92 std::vector<unsigned long long>
gather(std::vector<unsigned long long> &values)
override;
101 void allReduceSum(std::vector<double>& values)
override;
107 void broadcast(
long int &value)
override;
108 void broadcast(std::vector<int> &values)
override;
109 void broadcast(std::vector<float> &values)
override;
110 void broadcast(std::vector<double> &values)
override;
111 void broadcast(std::vector<long int> &values)
override;
114 std::vector<T>
gather(std::vector<T> &values);
149 std::vector<MPI_Request> requests;
168 if ((std::string)
typeid(
T).name() == (std::string)
typeid(
double).name())
170 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
float).name())
172 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
int).name())
174 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
unsigned long long).name())
176 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
char).name())
181 int count =
static_cast<int>(values.size());
185 rvalues.resize(numprocs * count);
188 MPI_Gather(&values[0], count, mpiDataType, &
rvalues[0], count, mpiDataType, root, comm);
197 if ((std::string)
typeid(
T).name() == (std::string)
typeid(
double).name())
199 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
float).name())
201 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
int).name())
203 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
unsigned long long).name())
218 throw std::runtime_error(
"No processors!");
222 for (
int i = 1;
i < numprocs; ++
i) {
258 if ((std::string)
typeid(
T).name() == (std::string)
typeid(
double).name())
260 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
float).name())
262 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
int).name())
264 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
long int).name())
270 if (this->PID == this->root) {
276 if (this->PID != this->root) {
280 MPI_Bcast(&values[0], (
int)values.size(), mpiDataType,
this->root, comm);
287 if ((std::string)
typeid(
T).name() == (std::string)
typeid(
double).name())
289 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
float).name())
291 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
int).name())
293 else if ((std::string)
typeid(
T).name() == (std::string)
typeid(
long int).name())
298 MPI_Bcast(&value, 1, mpiDataType, this->root, comm);
An abstract class for communication between processes in parallel computation.
A class uses MPI library to communication.
double reduceSum(double quantityPerProcess) const override
void * getNativeCommunicator() override
void allGather(std::vector< int > &svalues, std::vector< int > &rvalues) override
MPICommunicator & operator=(MPICommunicator const &)=delete
bool isRoot() const override
void abort(int errorcode) override
int getProcessID() const override
void receiveNonBlocking(real *rbuf, int count_r, int sourceRank) override
int getBundleRoot() const override
~MPICommunicator() override
void send(real *sbuf, int count_s, int nb_rank) const override
int getNumberOfBundles() const override
void allReduceSum(std::vector< float > &values) override
int mapCudaDevicesOnHosts(const std::vector< unsigned int > &devices, int numberOfDevices) const override
int getNumberOfProcesses() const override
MPICommunicator(MPICommunicator const &)=delete
std::vector< float > gather(std::vector< float > &values) override
void receiveSerializedObject(std::stringstream &ss, int source) override
void receiveSend(uint *buffer_receive, int size_buffer_recv, int neighbor_rank_recv, const uint *buffer_send, int size_buffer_send, int neighbor_rank_send) const override
int getProcessRoot() const override
void resetRequests() override
std::vector< int > gather(std::vector< int > &values) override
void sendNonBlocking(real *sbuf, int count_s, int destinationRank) override
void broadcast(int &value) override
void sendSerializedObject(std::stringstream &ss, int target) override
int getRoot() const override
std::vector< std::string > gather(const std::string &str) override
std::vector< double > gather(std::vector< double > &values) override
int getBundleID() const override
static std::shared_ptr< Communicator > getInstance()
int getNumberOfProcessesInBundle(int bundle) const override
std::shared_ptr< T > SPtr
MPI_Datatype getDataType< char >()
MPI_Datatype getDataType< int >()
MPI_Datatype getDataType()
MPI_Datatype getDataType< double >()
MPI_Datatype getDataType< unsigned int >()
MPI_Datatype getDataType< unsigned long long >()
MPI_Datatype getDataType< float >()