seapodym-parallel
Fish dynamics models with parameter estimations
Loading...
Searching...
No Matches
SeapodymCourier.h
1#include <mpi.h>
2#include <set>
3#ifndef SEAPODYM_COURIER
4#define SEAPODYM_COURIER
5
6
7using Tuple3 = std::tuple<MPI_Win, double*, std::size_t>;
8
16
17 private:
18
19 // MPI communicator to use for communication
20 MPI_Comm comm;
21
22 // Pointer to the data exposed by this worker. This class does not own this pointer,
23 // it is provided by the user. The data is expected to be allocated by the user and
24 // should remain valid for the lifetime of this SeapodymCourier instance.
25 double *data;
26 int data_size;
27
28 // MPI window for the exposed data
29 MPI_Win win;
30
31 // Local MPI rank
32 int local_rank;
33 public:
34
39 SeapodymCourier(MPI_Comm comm=MPI_COMM_WORLD);
40
45
50 double* getDataPtr() const { return this->data;}
51
57 void expose(double* data, int data_size);
58
63 void fetch(int target_worker);
64
70 void accumulate(const std::set<int>& source_workers, int target_worker);
71
75 void free() {
76 if (this->win != MPI_WIN_NULL) {
77 MPI_Win_free(&this->win);
78 }
79 this->data = nullptr;
80 this->data_size = 0;
81 }
82
83 // Disable copy and assignment operations
84 // to prevent accidental copying of the SeapodymCourier instance
85 // This is important because the class manages an MPI window and data pointer
86 // which should not be copied or assigned.
87 SeapodymCourier(const SeapodymCourier&) = delete; // Disable copy constructor
88 SeapodymCourier& operator=(const SeapodymCourier&) = delete; // Disable assignment operator
89 SeapodymCourier(SeapodymCourier&& other) noexcept; // Move constructor
90 SeapodymCourier& operator=(SeapodymCourier&& other) noexcept; // Move assignment operator
91};
92
93#endif // SEAPODYM_COURIER
SeapodymCourier class for managing memory exposure and data fetching between MPI processes.
Definition SeapodymCourier.h:15
void fetch(int target_worker)
Fetch data from a remote process and store it in the local data array.
Definition SeapodymCourier.cpp:31
void accumulate(const std::set< int > &source_workers, int target_worker)
Accumulate/sum the data from multiple source workers into a target worker's local data array.
Definition SeapodymCourier.cpp:47
void free()
Free the MPI window and reset the data pointer.
Definition SeapodymCourier.h:75
double * getDataPtr() const
Get the pointer to the exposed data.
Definition SeapodymCourier.h:50
~SeapodymCourier()
Destructor.
Definition SeapodymCourier.cpp:15
void expose(double *data, int data_size)
Expose the memory to other processes.
Definition SeapodymCourier.cpp:20
SeapodymCourier(MPI_Comm comm=MPI_COMM_WORLD)
Constructor.
Definition SeapodymCourier.cpp:7