seapodym-parallel
Fish dynamics models with parameter estimations
Loading...
Searching...
No Matches
SeapodymCourier.h
1#include <mpi.h>
2#include <set>
3#include <vector>
4#ifndef SEAPODYM_COURIER
5#define SEAPODYM_COURIER
6
7
8using Tuple3 = std::tuple<MPI_Win, double*, std::size_t>;
9
17
18 private:
19
20 // MPI communicator to use for communication
21 MPI_Comm comm;
22
23 // Pointer to the data exposed by this worker. This class does not own this pointer,
24 // it is provided by the user. The data is expected to be allocated by the user and
25 // should remain valid for the lifetime of this SeapodymCourier instance.
26 double *data;
27 int data_size;
28
29 // MPI window for the exposed data
30 MPI_Win win;
31 MPI_Win winRecv;
32
33 // data array to receive the accumulate operation
34 std::vector<double> dataRecv;
35
36 // Local MPI rank
37 int local_rank;
38 public:
39
44 SeapodymCourier(MPI_Comm comm=MPI_COMM_WORLD);
45
50
55 double* getDataPtr() const { return this->data;}
56
62 void expose(double* data, int data_size);
63
69 std::vector<double> fetch(int source_worker);
70
76 std::vector<double> accumulate(int targetWorker);
77
81 void free() {
82 if (this->win != MPI_WIN_NULL) {
83 MPI_Win_free(&this->win);
84 }
85 if (this->winRecv != MPI_WIN_NULL) {
86 MPI_Win_free(&this->winRecv);
87 }
88 this->data = nullptr;
89 this->data_size = 0;
90 this->dataRecv.clear();
91 }
92
93 // Disable copy and assignment operations
94 // to prevent accidental copying of the SeapodymCourier instance
95 // This is important because the class manages an MPI window and data pointer
96 // which should not be copied or assigned.
97 SeapodymCourier(const SeapodymCourier&) = delete; // Disable copy constructor
98 SeapodymCourier& operator=(const SeapodymCourier&) = delete; // Disable assignment operator
99 SeapodymCourier(SeapodymCourier&& other) noexcept; // Move constructor
100 SeapodymCourier& operator=(SeapodymCourier&& other) noexcept; // Move assignment operator
101};
102
103#endif // SEAPODYM_COURIER
SeapodymCourier class for managing memory exposure and data fetching between MPI processes.
Definition SeapodymCourier.h:16
std::vector< double > accumulate(int targetWorker)
Accumulate the data from all workers.
Definition SeapodymCourier.cpp:66
void free()
Free the MPI window and reset the data pointer.
Definition SeapodymCourier.h:81
double * getDataPtr() const
Get the pointer to the exposed data.
Definition SeapodymCourier.h:55
std::vector< double > fetch(int source_worker)
Fetch data from a remote process and store it in the local data array.
Definition SeapodymCourier.cpp:40
~SeapodymCourier()
Destructor.
Definition SeapodymCourier.cpp:17
void expose(double *data, int data_size)
Expose the memory to other processes.
Definition SeapodymCourier.cpp:22
SeapodymCourier(MPI_Comm comm=MPI_COMM_WORLD)
Constructor.
Definition SeapodymCourier.cpp:7