criptic v1
Cosmic Ray Interstellar Propagation Tool using Itô Calculus
Loading...
Searching...
No Matches
CRTreeCommunicator.H
Go to the documentation of this file.
1
11#ifndef _CRTREECOMMUNICATOR_H_
12#define _CRTREECOMMUNICATOR_H_
13
14#ifdef ENABLE_MPI
15
16#include "MPIUtil.H"
17#include "../Definitions.H"
18#include "../Core/FieldQty.H"
19#include "../Utils/RealTensor2.H"
20#include "../Utils/RngThread.H"
21#include "../Utils/Types.H"
22#include "../Utils/Vec3.H"
23#include <array>
24#include <list>
25#include <queue>
26#include <vector>
27#ifdef _OPENMP
28#include "omp.h"
29#endif
30
31namespace criptic {
32
33 class CRTree; // Forward declaration
34
49
50 public:
51
55 CRTreeCommunicator(const CRTree* tree_);
56
61
63 // Status methods
65
69 void initCycle();
70
74 void finalizeCycle();
75
80 bool allDone();
81
83 // Registration methods
85
100 void registerRequest(const IdxType& start,
101 const IdxType& count,
102 const std::vector<bool>& defer,
103 const std::vector<int>& rank,
104 const RealTensor2& h2Inv,
105 const RealTensor2& h2InvGrad,
106 const Real& hScale,
107 const std::vector<FieldQty>& qMin);
108
114 void registerResponse(const int& rank,
115 const MPIUtil::fillResponse& resp);
116
118 // Communication methods
120
124 void recv();
125
129 void sendRequests();
130
134 void sendResponses();
135
137 // Methods to process communications from other ranks
139
147 std::pair<MPIUtil::fillRequest*, int> getFillRequest() {
148 if (inReqPtr == inReqBuf.size())
149 return std::pair<MPIUtil::fillRequest*, int>(nullptr, -1);
150 int rank = inReqRank[inReqPtr];
152 inReqPtr++;
153 return std::pair<MPIUtil::fillRequest*, int>(req, rank);
154 }
155
161 if (inRespProcPtr == inRespWritePtr) return nullptr;
164 return resp;
165 }
166
167 private:
168
169 // Private data
170 const CRTree* tree;
171 std::vector<int> rankDone;
173 // Buffers and handles for communication
174
175 // "All done" send and receive handles
176 std::vector<MPI_Request> doneSendHandle;
179 std::vector<MPI_Request> doneRecvHandle;
183 // Outgoing requests
184 std::vector<std::vector<MPIUtil::fillRequest> >
186 std::vector<MPI_Request> outReqHandle;
188 // Outgoing responses
189 std::vector<std::list<std::vector<MPIUtil::fillResponse> > >
191 std::vector<std::vector<MPI_Request> >
194 // Incoming requests
195 std::vector<MPIUtil::fillRequest>
197 std::vector<int> inReqRank;
201 // Incoming responses
202 std::vector<MPIUtil::fillResponse>
210 // OpenMP infrastructure
211#ifdef _OPENMP
212 std::vector<omp_lock_t> outReqBufLock;
214 std::vector<omp_lock_t> outRespBufLock;
216#endif
217
218 };
219
220
221}
222
223#endif
224// ENABLE_MPI
225
226#endif
227// _CRTREECOMMUNICATOR_H_
Global constants and functions to handle MPI processing.
Class to manage communications during tree walks.
Definition CRTreeCommunicator.H:48
std::vector< MPIUtil::fillRequest > inReqBuf
Definition CRTreeCommunicator.H:196
std::vector< MPI_Request > doneSendHandle
Definition CRTreeCommunicator.H:176
std::vector< int > inReqRank
Definition CRTreeCommunicator.H:197
MPIUtil::fillResponse * getFillResponse()
Retrieve responses that are ready to process.
Definition CRTreeCommunicator.H:160
IdxType inRespWritePtr
Definition CRTreeCommunicator.H:204
const CRTree * tree
Definition CRTreeCommunicator.H:170
void recv()
Receive incoming messages.
Definition CRTreeCommunicator.cpp:204
std::pair< MPIUtil::fillRequest *, int > getFillRequest()
Retrieve the next fill request to process.
Definition CRTreeCommunicator.H:147
std::vector< omp_lock_t > outReqBufLock
Definition CRTreeCommunicator.H:212
void sendRequests()
Send all requests from the outgoing request buffers.
Definition CRTreeCommunicator.cpp:259
void finalizeCycle()
Finalize a communication cycle.
Definition CRTreeCommunicator.cpp:75
IdxType inReqPtr
Definition CRTreeCommunicator.H:199
bool allDone()
Report if all work on all ranks is done.
Definition CRTreeCommunicator.cpp:87
void initCycle()
Initialize a communication cycle.
Definition CRTreeCommunicator.cpp:47
std::vector< std::vector< MPIUtil::fillRequest > > outReqBuf
Definition CRTreeCommunicator.H:185
std::vector< MPIUtil::fillResponse > inRespBuf
Definition CRTreeCommunicator.H:203
void registerRequest(const IdxType &start, const IdxType &count, const std::vector< bool > &defer, const std::vector< int > &rank, const RealTensor2 &h2Inv, const RealTensor2 &h2InvGrad, const Real &hScale, const std::vector< FieldQty > &qMin)
Register an MPI request for a deferred leaf.
Definition CRTreeCommunicator.cpp:147
void registerResponse(const int &rank, const MPIUtil::fillResponse &resp)
Register a response to an MPI request from a remote rank.
Definition CRTreeCommunicator.cpp:188
std::vector< omp_lock_t > outRespBufLock
Definition CRTreeCommunicator.H:214
std::vector< std::list< std::vector< MPIUtil::fillResponse > > > outRespBuf
Definition CRTreeCommunicator.H:190
void sendResponses()
Send responses to requests from other ranks.
Definition CRTreeCommunicator.cpp:287
IdxType inRespProcPtr
Definition CRTreeCommunicator.H:207
std::vector< int > rankDone
Definition CRTreeCommunicator.H:171
~CRTreeCommunicator()
Destructor.
Definition CRTreeCommunicator.cpp:32
std::vector< MPI_Request > outReqHandle
Definition CRTreeCommunicator.H:186
std::vector< MPI_Request > doneRecvHandle
Definition CRTreeCommunicator.H:179
std::vector< std::vector< MPI_Request > > outRespHandle
Definition CRTreeCommunicator.H:192
A class to manage CR packets and sources.
Definition CRTree.H:44
Class that represents a rank 2 tensor.
Definition RealTensor2.H:34
The primary namespace for criptic objects.
Definition AdvancePacket.H:25
std::vector< Real >::size_type IdxType
Definition Types.H:45
double Real
Definition Types.H:38
Struture to hold data representing a search request.
Definition MPIUtil.H:135
Struture to hold data representing a response to a request.
Definition MPIUtil.H:162