From 461de5f101fcd4c44aa7573610a6c6d028704dbb Mon Sep 17 00:00:00 2001 From: "Martin D. Weinberg" Date: Tue, 5 Mar 2024 21:48:55 -0500 Subject: [PATCH] Add an MPI exclusion to allow 2d basis construction to work with single process pyEXP runs --- exputil/BiorthCyl.cc | 34 ++++++++++++++++++++++------------ exputil/EmpCyl2d.cc | 15 +++++---------- include/BiorthCyl.H | 2 +- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/exputil/BiorthCyl.cc b/exputil/BiorthCyl.cc index 859dc13d9..2eecc84a9 100644 --- a/exputil/BiorthCyl.cc +++ b/exputil/BiorthCyl.cc @@ -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 { @@ -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); } @@ -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 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"); } } diff --git a/include/BiorthCyl.H b/include/BiorthCyl.H index da3cd51f5..e8700e378 100644 --- a/include/BiorthCyl.H +++ b/include/BiorthCyl.H @@ -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