9 #include "fei_EqnComm.hpp"
10 #include "fei_sstream.hpp"
14 EqnComm::EqnComm(MPI_Comm comm,
int numLocalEqns)
21 MPI_Comm_size(comm, &numProcs);
22 MPI_Comm_rank(comm, &localProc);
24 std::vector<int> local(numProcs*2, 0);
25 int* global = &local[0] + numProcs;
27 if (numLocalEqns < 0) {
28 throw std::runtime_error(
"fei::EqnComm ERROR, negative numLocalEqns not allowed.");
31 local[localProc] = numLocalEqns;
33 MPI_Allreduce(&local[0], global, numProcs, MPI_INT, MPI_MAX, comm_);
35 globalOffsets_.resize(numProcs+1);
38 for(
int i=0; i<numProcs; ++i) {
39 globalOffsets_[i] = offset;
42 globalOffsets_[numProcs] = offset;
45 globalOffsets_[0] = 0;
46 globalOffsets_[1] = numLocalEqns;
50 EqnComm::EqnComm(MPI_Comm comm,
int numLocalEqns,
const std::vector<int>& globalOffsets)
52 globalOffsets_(globalOffsets)
60 const std::vector<int>&
61 EqnComm::getGlobalOffsets()
const
63 return(globalOffsets_);
67 EqnComm::getOwnerProc(
int eqn)
const
75 for(
unsigned p=1; p<globalOffsets_.size(); ++p) {
76 if (eqn < globalOffsets_[p]) {
83 int numProcs = globalOffsets_.size()-1;
84 if (proc >= numProcs) {
85 FEI_OSTRINGSTREAM osstr;
86 osstr <<
"fei::EqnComm::getOwnerProc: input eqn="<<eqn<<
", proc="<<proc
87 <<
", ERROR, proc should be in [0.."<<numProcs-1<<
"].";
88 throw std::runtime_error(std::string(osstr.str().c_str()));
int localProc(MPI_Comm comm)
int numProcs(MPI_Comm comm)