seapodym-parallel
Fish dynamics models with parameter estimations
Loading...
Searching...
No Matches
DataProvider.h
1#include <mpi.h>
2#include <cstddef>
3#include <cstring>
4#include <stdexcept>
5#include <vector>
6#include <string>
7#include <unordered_map>
8#include <tuple>
9
10#ifndef DATA_PROVIDER_H
11#define DATA_PROVIDER_H
12
16class DataProvider {
17
18public:
19
20 DataProvider(const DataProvider&) = delete;
21 DataProvider& operator=(const DataProvider&) = delete;
22
28 DataProvider(MPI_Comm comm, const std::vector<std::pair<std::string, std::size_t> >& nameSizePairs);
29
30 ~DataProvider();
31
36 int getShmRank() const { return shmRank_; }
37
42 bool isShmRoot() const { return shmRank_ == 0; }
43
52 double* getDataPtr(const std::string& name) const {
53 auto it = this->data_.find(name);
54 return it != this->data_.end() ? std::get<0>(it->second) : nullptr;
55 }
56
61 size_t getNumElements(const std::string& name) const {
62 auto it = this->data_.find(name);
63 return it != this->data_.end() ? std::get<1>(it->second) : 0;
64 }
65
70 MPI_Comm getShmComm() const {
71 return this->shmcomm_;
72 }
73
74private:
75 MPI_Comm comm_;
76 MPI_Comm shmcomm_;
77 std::unordered_map< std::string, std::tuple<double*, std::size_t, MPI_Win> > data_;
78 int shmRank_;
79};
80
81#endif // DATA_PROVIDER_H
bool isShmRoot() const
Check if the calling process is the root of the shared memory communicator (i.e., the one that provid...
Definition DataProvider.h:42
int getShmRank() const
Get the rank of the calling process in the shared memory communicator.
Definition DataProvider.h:36
MPI_Comm getShmComm() const
Definition DataProvider.h:70
double * getDataPtr(const std::string &name) const
Get a pointer to the shared data array.
Definition DataProvider.h:52
size_t getNumElements(const std::string &name) const
Get the number of elements in the shared data array.
Definition DataProvider.h:61