11 #ifdef PORTAGE_ENABLE_MPI 26 void collate_type(MPI_Comm comm,
const int rank,
const int numpe,
27 const MPI_Datatype mpi_type,
28 std::vector<T> &lvec, std::vector<T> &gvec) {
30 std::vector<int> lvec_sizes(numpe);
31 std::vector<int> displs;
32 int lvec_size = lvec.size();
34 MPI_Gather(&lvec_size, 1, MPI_INT, &lvec_sizes[0], 1, MPI_INT, 0, comm);
37 int const gvec_size = std::accumulate(lvec_sizes.begin(), lvec_sizes.end(),0);
38 int const lvec_size_count = lvec_sizes.size();
40 gvec.resize(gvec_size);
41 displs.resize(lvec_size_count);
44 for (
int i=0; i < lvec_size_count; i++) {
54 MPI_Gatherv(&lvec[0], lvec.size(), mpi_type, &gvec[0], &lvec_sizes[0],
55 &displs[0], mpi_type, 0, comm);
59 void collate(MPI_Comm comm,
const int rank,
const int numpe,
60 std::vector<int> &lvec, std::vector<int> &gvec) {
61 collate_type(comm, rank, numpe, MPI_INT, lvec, gvec);
65 void collate(MPI_Comm comm,
const int rank,
const int numpe,
66 std::vector<double> &lvec, std::vector<double> &gvec) {
67 collate_type(comm, rank, numpe, MPI_DOUBLE, lvec, gvec);
72 void argsort(
const std::vector<T> &x, std::vector<int> &idx) {
74 std::iota(idx.begin(), idx.end(), 0);
75 std::sort(idx.begin(), idx.end(), [&x](
int a,
int b){
return x[a] < x[b]; });
80 void reorder(std::vector<T> &x,
const std::vector<int> &idx) {
81 int const n = x.size();
83 for (
int i=0; i < n; i++) y[i] = x[idx[i]];
91 #endif // MPI_COLLATE_H_ Definition: coredriver.h:42