iterative-solver 0.0
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 <mpi.h>
5
7
15void gather_all(const Distribution<size_t>& distr, MPI_Comm commun, double* first_elem) {
16 int nproc, mpi_rank;
17 MPI_Comm_size(commun, &nproc);
18 MPI_Comm_rank(commun, &mpi_rank);
19 int chunks[nproc], displs[nproc];
20 for (int i = 0; i < nproc; i++) {
21 displs[i] = distr.range(i).first;
22 chunks[i] = distr.range(i).second - distr.range(i).first;
23 }
24 MPI_Allgatherv(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, first_elem, chunks, displs, MPI_DOUBLE, commun);
25}
26
27} // namespace molpro::linalg::array::util
28
29#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:23
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:15