Chi-Tech
communicate_location_dependencies.cc
Go to the documentation of this file.
1#include "sweep_namespace.h"
2
3#include "chi_runtime.h"
4#include "chi_log.h"
5#include "chi_mpi.h"
6
7//###################################################################
8/**Communicates location by location dependencies.*/
11 const std::vector<int> &location_dependencies,
12 std::vector<std::vector<int>> &global_dependencies)
13{
14 int P = Chi::mpi.process_count;
15
16 //============================================= Communicate location dep counts
17 std::vector<int> depcount_per_loc(P, 0);
18 int current_loc_dep_count = location_dependencies.size();
19 MPI_Allgather(&current_loc_dep_count, //Send Buffer
20 1, MPI_INT, //Send count and type
21 depcount_per_loc.data(), //Recv Buffer
22 1, MPI_INT, //Recv count and type
23 Chi::mpi.comm); //Communicator
24
25 //============================================= Broadcast dependencies
26 std::vector<int> raw_depvec_displs(P, 0);
27 int recv_buf_size = depcount_per_loc[0];
28 for (int locI=1; locI<P; ++locI)
29 {
30 raw_depvec_displs[locI] = raw_depvec_displs[locI-1] + depcount_per_loc[locI-1];
31 recv_buf_size += depcount_per_loc[locI];
32 }
33
34 std::vector<int> raw_dependencies(recv_buf_size,0);
35
36 MPI_Allgatherv(location_dependencies.data(), //Send buffer
37 int(location_dependencies.size()), //Send count
38 MPI_INT, //Send type
39 raw_dependencies.data(), //Recv buffer
40 depcount_per_loc.data(), //Recv counts array
41 raw_depvec_displs.data(), //Recv displs
42 MPI_INT, //Recv type
43 Chi::mpi.comm); //Communicator
44
45 for (int locI=0; locI<P; ++locI)
46 {
47 global_dependencies[locI].resize(depcount_per_loc[locI], 0);
48 for (int c=0; c < depcount_per_loc[locI]; ++c)
49 {
50 int addr = raw_depvec_displs[locI] + c;
51 global_dependencies[locI][c] = raw_dependencies[addr];
52 }
53 }
54}
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
const MPI_Comm & comm
MPI communicator.
Definition: mpi_info.h:28
const int & process_count
Total number of processes.
Definition: mpi_info.h:27
void CommunicateLocationDependencies(const std::vector< int > &location_dependencies, std::vector< std::vector< int > > &global_dependencies)