iterative-solver 0.0
 
Loading...
Searching...
No Matches
gather_all.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_GATHER_ALL_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_GATHER_ALL_H
3#include <molpro/linalg/array/util/Distribution.h>
4#include <molpro/mpi.h>
5#include <vector>
6
8
18inline void gather_all(const Distribution<size_t>& distr, MPI_Comm commun, double* first_elem) {
19#ifdef HAVE_MPI_H
20 int nproc;
21 MPI_Comm_size(commun, &nproc);
22 if (nproc == 1)
23 return;
24 std::vector<int> chunks(nproc), displs(nproc);
25 for (int i = 0; i < nproc; i++) {
26 displs[i] = distr.range(i).first;
27 chunks[i] = distr.range(i).second - distr.range(i).first;
28 }
29 MPI_Allgatherv(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, first_elem, chunks.data(), displs.data(), MPI_DOUBLE, commun);
30#endif
31}
32
33} // namespace molpro::linalg::array::util
34
35#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_GATHER_ALL_H
Specifies distribution of a contiguous array into non-overlapping chunks.
Definition Distribution.h:16
std::pair< index_type, index_type > range(int chunk) const
Returns [fist, end) indices for section of array assigned to chunk.
Definition Distribution.h:64
Definition ArrayHandler.h:24
void gather_all(const Distribution< size_t > &distr, MPI_Comm commun, double *first_elem)
Replicate data of a full container on all the processes based on distributed pieces.
Definition gather_all.h:18