VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
Communicator.h
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
32//=======================================================================================
33
34#ifndef MPI_COMMUNICATOR_H
35#define MPI_COMMUNICATOR_H
36
37#include <memory>
38#include <mutex>
39#include <sstream>
40#include <string>
41#include <vector>
42
43#include <basics/DataTypes.h>
44
45namespace vf::parallel
46{
47
50{
51public:
52 Communicator(const Communicator &) = delete;
54 static std::shared_ptr<Communicator> getInstance();
55
56 virtual ~Communicator() = default;
57
58
59 virtual double Wtime() = 0;
60 virtual int getBundleID() const = 0;
61 virtual int getNumberOfBundles() const = 0;
62 virtual int getProcessID() const = 0;
63 virtual int getProcessID(int bundle, int rank) const = 0;
64 virtual bool isRoot() const = 0;
65 virtual void *getNativeCommunicator() = 0;
66
67 virtual void sendSerializedObject(std::stringstream &ss, int target) = 0;
68 virtual void receiveSerializedObject(std::stringstream &ss, int source) = 0;
69
70 virtual int getRoot() const = 0;
71 virtual int getBundleRoot() const = 0;
72 virtual int getProcessRoot() const = 0;
73 virtual int getNumberOfProcessesInBundle(int bundle) const = 0;
74 virtual void barrier() = 0;
75 virtual void abort(int errorcode) = 0;
76
77 virtual std::vector<std::string> gather(const std::string &str) = 0;
78 virtual std::vector<int> gather(std::vector<int> &values) = 0;
79 virtual std::vector<float> gather(std::vector<float> &values) = 0;
80 virtual std::vector<double> gather(std::vector<double> &values) = 0;
81 virtual std::vector<unsigned long long> gather(std::vector<unsigned long long> &values) = 0;
82
83 virtual void allGather(std::vector<int> &svalues, std::vector<int> &rvalues) = 0;
84 virtual void allGather(std::vector<float> &svalues, std::vector<float> &rvalues) = 0;
85 virtual void allGather(std::vector<double> &svalues, std::vector<double> &rvalues) = 0;
86 virtual void allGather(std::vector<unsigned long long> &svalues, std::vector<unsigned long long> &rvalues) = 0;
87 virtual void allGather(std::vector<uint> &svalues, std::vector<uint> &rvalues) = 0;
88
89 virtual void allReduceSum(std::vector<float>& svalues) = 0;
90 virtual void allReduceSum(std::vector<double>& svalues) = 0;
91 virtual void allReduceSum(std::vector<uint>& svalues) = 0;
92
93 virtual void broadcast(int &value) = 0;
94 virtual void broadcast(float &value) = 0;
95 virtual void broadcast(double &value) = 0;
96 virtual void broadcast(long int &value) = 0;
97 virtual void broadcast(std::vector<int> &values) = 0;
98 virtual void broadcast(std::vector<float> &values) = 0;
99 virtual void broadcast(std::vector<double> &values) = 0;
100 virtual void broadcast(std::vector<long int> &values) = 0;
101
103 int size_buffer_send, int neighbor_rank_send) const = 0;
104 virtual int getNumberOfProcesses() const = 0;
105 virtual void send(real *sbuf, int count_s, int nb_rank) const = 0;
106 virtual double reduceSum(double quantityPerProcess) const = 0;
107 virtual int mapCudaDevicesOnHosts(const std::vector<unsigned int> &devices, int numberOfDevices) const = 0;
109 int neighbor_rank) const = 0;
110 virtual void receiveNonBlocking(real *rbuf, int count_r, int sourceRank) = 0;
111 virtual void sendNonBlocking(real *sbuf, int count_s, int destinationRank) = 0;
112 virtual void send(real *sbuf, int count_s, int destinationRank) = 0;
113 virtual void waitAll() = 0;
114 virtual void resetRequests() = 0;
115
116protected:
117 Communicator() = default;
118
119 static std::mutex instantiation_mutex;
120
121 static std::shared_ptr<Communicator> instance;
122};
123
124}
125
126#endif
127
An abstract class for communication between processes in parallel computation.
virtual void broadcast(float &value)=0
virtual int getNumberOfProcessesInBundle(int bundle) const =0
virtual std::vector< unsigned long long > gather(std::vector< unsigned long long > &values)=0
virtual double reduceSum(double quantityPerProcess) const =0
virtual std::vector< std::string > gather(const std::string &str)=0
virtual void allReduceSum(std::vector< double > &svalues)=0
virtual void sendSerializedObject(std::stringstream &ss, int target)=0
Communicator & operator=(const Communicator &rhs)=delete
virtual void broadcast(std::vector< double > &values)=0
static std::shared_ptr< Communicator > instance
virtual void resetRequests()=0
virtual int getProcessID() const =0
virtual void allGather(std::vector< int > &svalues, std::vector< int > &rvalues)=0
virtual void sendNonBlocking(real *sbuf, int count_s, int destinationRank)=0
virtual std::vector< float > gather(std::vector< float > &values)=0
virtual int getNumberOfBundles() const =0
virtual ~Communicator()=default
virtual void allGather(std::vector< double > &svalues, std::vector< double > &rvalues)=0
static std::mutex instantiation_mutex
virtual void allGather(std::vector< uint > &svalues, std::vector< uint > &rvalues)=0
virtual std::vector< int > gather(std::vector< int > &values)=0
virtual double Wtime()=0
virtual bool isRoot() const =0
virtual void allReduceSum(std::vector< uint > &svalues)=0
virtual void receiveNonBlocking(real *rbuf, int count_r, int sourceRank)=0
virtual int getBundleRoot() const =0
virtual void broadcast(int &value)=0
virtual 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 =0
virtual void allGather(std::vector< float > &svalues, std::vector< float > &rvalues)=0
virtual void broadcast(long int &value)=0
static std::shared_ptr< Communicator > getInstance()
virtual void abort(int errorcode)=0
virtual void allGather(std::vector< unsigned long long > &svalues, std::vector< unsigned long long > &rvalues)=0
virtual void allReduceSum(std::vector< float > &svalues)=0
virtual void broadcast(double &value)=0
virtual int mapCudaDevicesOnHosts(const std::vector< unsigned int > &devices, int numberOfDevices) const =0
virtual int getBundleID() const =0
virtual int getNumberOfProcesses() const =0
virtual std::vector< double > gather(std::vector< double > &values)=0
virtual void * getNativeCommunicator()=0
virtual void send(real *sbuf, int count_s, int nb_rank) const =0
virtual void broadcast(std::vector< int > &values)=0
virtual int getProcessID(int bundle, int rank) const =0
virtual void send(real *sbuf, int count_s, int destinationRank)=0
virtual void barrier()=0
virtual void receiveSerializedObject(std::stringstream &ss, int source)=0
virtual int getProcessRoot() const =0
virtual void waitAll()=0
virtual void broadcast(std::vector< long int > &values)=0
Communicator(const Communicator &)=delete
virtual int getRoot() const =0
virtual void broadcast(std::vector< float > &values)=0
virtual void receiveSend(real *buffer_send, int size_buffer_send, real *buffer_receive, int size_buffer_recv, int neighbor_rank) const =0
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
unsigned int uint
Definition DataTypes.h:47