63 allGatherv(
const std::unordered_map<CepsUInt, CepsUInt>& orig,
64 std::unordered_map<CepsUInt, CepsUInt>& dest);
72 template<
typename _Key,
typename _Val,
73 template<
typename,
typename>
typename _Container>
86 template<
typename _Key,
typename _Val,
87 template<
typename,
typename>
typename _Container>
92 _Container<_Key,_Val>& table,
105 sendRecvWithMatrix(
const Eigen::Matrix<CepsUInt, Eigen::Dynamic,Eigen::Dynamic>& commMat,
112 template <
typename T>
120 MPI_Allgather(&localSize,1,MPI_INT,localSizes.data(),1,MPI_INT,comm);
125 for (
CepsUInt i=0u; i<gridSize; i++)
127 count += localSizes[i];
128 displacements[i+1] = count;
131 T* localNonConst =
const_cast<T*
>(localTab.data());
132 void* localVoid =
static_cast<void*
>(localNonConst);
139 globalTab.resize(displacements[gridSize]);
140 return MPI_Gatherv(localVoid, localSize, mpiType, globalTab.data(), localSizes.data(),
145 globalTab.resize(displacements[gridSize]);
146 return MPI_Allgatherv(localVoid, localSize, mpiType, globalTab.data(), localSizes.data(),
147 displacements.data(), mpiType, comm);
151 template<
typename _Key,
typename _Val,
152 template<
typename,
typename>
typename _Container>
159 CepsUInt nItems = isSender ? table.size() : 0;
169 keys .resize(nItems);
170 values.resize(nItems);
175 for (
CepsUInt i = 0U; i < keys.size (); ++i)
176 table.emplace (keys[i], values[i]);
182 template<
typename _Key,
typename _Val,
183 template<
typename,
typename>
typename _Container>
188 _Container<_Key,_Val>& table,
196 if (isReceiver or isSender)
201 CepsUInt nItems = isSender ? table.size() : 0;
207 CepsInt tag = commId + nComms*(receiver + gSize*sender);
220 keys .resize(nItems);
230 values.resize(nItems);
232 for (
CepsUInt i = 0U; i < keys.size (); ++i)
233 table.emplace (keys[i], values[i]);
242 template <
typename T>
244 sendRecvWithMatrix(
const Eigen::Matrix<CepsUInt, Eigen::Dynamic, Eigen::Dynamic>& commMat,
254 CepsBool badShape = nrows > gridSize or ncols > gridSize;
256 "given comm Matrix has wrong shape " << nrows <<
" " << ncols
259 std::map<CepsUInt, CepsUInt> connectivity;
260 for (
CepsUInt i = 0U; i < gridSize; ++i)
261 connectivity[i] = commMat(rank,i);
264 MPI_Request *sendRequests = ceps::newArray<MPI_Request>(connectivity.size());
266 for (
auto &[destination, data_size] : connectivity)
268 destination,rank*gridSize+destination,comm, &sendRequests[i++]);
271 connectivity.clear();
272 for (
CepsUInt j=0U; j<gridSize; ++j)
273 connectivity[j] = commMat(j,rank);
275 CepsUInt nbReceives = connectivity.size();
277 MPI_Request *receiveRequests = ceps::newArray<MPI_Request>(nbReceives);
278 MPI_Status *receiveStatus = ceps::newArray<MPI_Status >(nbReceives);
280 recvBuffers.resize(gridSize);
281 for (
auto &[sender, data_size] : connectivity)
283 recvBuffers[sender].resize(data_size);
285 sender, sender*gridSize+rank, comm, &receiveStatus[i++]);
297 sendRecvWithMatrix(
const Eigen::Matrix<CepsUInt, Eigen::Dynamic, Eigen::Dynamic>& commMat,
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
std::vector< _Type, _Alloc > CepsVector
C++ vector.
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
int32_t CepsInt
Need 32 bit integer.
A namespace for all utility methods.
CepsUInt getRank()
Returns current processor rank.
int broadcastMap(const CepsUInt &sender, _Container< _Key, _Val > &table)
broadcast map or multimap
void destroyTabular(_Type &)
Destroy[delete] any type.
void sendRecvWithMatrix(const Eigen::Matrix< CepsUInt, Eigen::Dynamic, Eigen::Dynamic > &commMat, CepsVector< CepsVector< T >> &sendBuffers, CepsVector< CepsVector< T >> &recvBuffers)
Pair to pair communication (using matrix)
MPI_Comm getCommunicator()
Get the communicator.
int sendMap(const CepsUInt &sender, const CepsUInt &receiver, _Container< _Key, _Val > &table, const CepsUInt &nComms=1, const CepsUInt &commId=1)
send a map or mutlimap from a cpu to another
CepsUInt getGridSize()
Returns the number of process on the computing grid.
int allGatherv(const CepsVector< T > &localTab, int localSize, CepsVector< T > &globalTab, CepsBool masterOnly=false)
Gather all the local orig vector in the global dest vector.
CepsVector< _Tp > valuesOf(const CepsMap< _Key, _Tp, _Comp, _Alloc > &m)
Get the values of a map as a vector.
CepsBool isMaster()
Is calling process the master ?
CepsVector< _Key > keysOf(const CepsMap< _Key, _Tp, _Comp, _Alloc > &m)
Get the keys of a map as a vector.
Used to retrieve the MPI "type" in function of the true type.