Skip to content

Commit

Permalink
Add an MPI exclusion to allow 2d basis construction to work with sing…
Browse files Browse the repository at this point in the history
…le process pyEXP runs
  • Loading branch information
Martin D. Weinberg committed Mar 6, 2024
1 parent a338b68 commit 461de5f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
34 changes: 22 additions & 12 deletions exputil/BiorthCyl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ using namespace __EXP__; // For reference to n-body globals
// Constructor
BiorthCyl::BiorthCyl(const YAML::Node& conf) : conf(conf)
{
// Check whether MPI is initialized. Use flag to suppress MPI calls
// if MPI is not active.
//
int flag;
MPI_Initialized(&flag);
if (flag) use_mpi = true;
else use_mpi = false;

// Read and assign parameters
//
try {
Expand Down Expand Up @@ -110,7 +118,7 @@ BiorthCyl::BiorthCyl(const YAML::Node& conf) : conf(conf)
<< std::string(60, '-') << std::endl
<< conf
<< std::string(60, '-') << std::endl;
MPI_Finalize();
if (use_mpi) MPI_Finalize();
exit(-1);
}

Expand Down Expand Up @@ -231,16 +239,18 @@ void BiorthCyl::create_tables()

if (verbose and myid==0) std::cout << std::endl;

for (int m=0; m<=mmax; m++) {
for (int n=0; n<nmax; n++) {
MPI_Allreduce(MPI_IN_PLACE, dens [m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(MPI_IN_PLACE, pot [m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(MPI_IN_PLACE, rforce[m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(MPI_IN_PLACE, zforce[m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
if (use_mpi) {
for (int m=0; m<=mmax; m++) {
for (int n=0; n<nmax; n++) {
MPI_Allreduce(MPI_IN_PLACE, dens [m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(MPI_IN_PLACE, pot [m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(MPI_IN_PLACE, rforce[m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(MPI_IN_PLACE, zforce[m][n].data(), numx*numy,
MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
}
}
}

Expand Down Expand Up @@ -595,7 +605,7 @@ bool BiorthCyl::ReadH5Cache()
double v; HighFive::Attribute vv = h5file.getAttribute(name); vv.read(v);
if (fabs(value - v) < 1.0e-16) return true;
else {
if (myid==0) std::cout << "---- BiortyCyl::ReadH5Cache: wanted "
if (myid==0) std::cout << "---- BiorthCyl::ReadH5Cache: wanted "
<< name << "=" << value
<< " but found "
<< name << "=" << v << std::endl;
Expand Down
15 changes: 5 additions & 10 deletions exputil/EmpCyl2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ class EmpCyl2d::ExponCyl : public EmpCyl2d::ModelCyl
<< std::string(60, '-') << std::endl
<< conf << std::endl
<< std::string(60, '-') << std::endl;
MPI_Finalize();
exit(-1);
throw std::runtime_error("EmpCyl2d::ExponCyl: error parsing YAML config");
}
}

Expand Down Expand Up @@ -416,8 +415,7 @@ class EmpCyl2d::KuzminCyl : public EmpCyl2d::ModelCyl
<< std::string(60, '-') << std::endl
<< conf << std::endl
<< std::string(60, '-') << std::endl;
MPI_Finalize();
exit(-1);
throw std::runtime_error("EmpCyl2d::KuzminCyl: error parsing YAML config");
}
}

Expand Down Expand Up @@ -475,8 +473,7 @@ class EmpCyl2d::MestelCyl : public EmpCyl2d::ModelCyl
<< std::string(60, '-') << std::endl
<< conf << std::endl
<< std::string(60, '-') << std::endl;
MPI_Finalize();
exit(-1);
throw std::runtime_error("EmpCyl2d::MestelCyl: error parsing YAML config");
}
}

Expand Down Expand Up @@ -586,8 +583,7 @@ class EmpCyl2d::ZangCyl : public EmpCyl2d::MestelCyl
<< std::string(60, '-') << std::endl
<< conf << std::endl
<< std::string(60, '-') << std::endl;
MPI_Finalize();
exit(-1);
throw std::runtime_error("EmpCyl2d::ZangCyl: error parsing YAML config");
}
}

Expand Down Expand Up @@ -690,8 +686,7 @@ std::shared_ptr<EmpCyl2d::ModelCyl> EmpCyl2d::createModel()
<< std::string(60, '-') << std::endl
<< Params << std::endl
<< std::string(60, '-') << std::endl;
MPI_Finalize();
exit(-1);
throw std::runtime_error("EmpCyl2d::createModel: error parsing YAML config");
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/BiorthCyl.H
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected:
int mmax, nmax, numr, nmaxfid, mmin, mlim, nmin, nlim, knots, NQDHT;
double rcylmin, rcylmax, scale, acyltbl, acylcut, Ninner, Mouter;

bool EVEN_M, verbose, logr;
bool EVEN_M, verbose, logr, use_mpi;

//@{
//! Grid parameters
Expand Down

0 comments on commit 461de5f

Please sign in to comment.