In the singleton class Mpi: added method Mpi::Init_thread that
performs MPI initialization using MPI_Init_thread; added method Mpi::Init_auto that selects what MPI init mode to use based on the configured external packages used by MFEM -- currently it calls Mpi::Init_thread(MPI_THREAD_MULTIPLE) when using STRUMPACK built with SLATE or PT-Scotch, otherwise it calls Mpi::Init. In the examples that can use STRUMPACK, use Mpi::Init_auto instead of Mpi::Init. Fix a small unrelated issue noticed during testing: in miniapps/multidomain/multidomain.cpp, do not open GLVis socket connections when visualization is disabled.
This commit is contained in:
+1
-1
@@ -58,7 +58,7 @@ using namespace mfem;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// 1. Initialize MPI and HYPRE.
|
||||
Mpi::Init(argc, argv);
|
||||
Mpi::Init_auto();
|
||||
int num_procs = Mpi::WorldSize();
|
||||
int myid = Mpi::WorldRank();
|
||||
Hypre::Init();
|
||||
|
||||
+1
-1
@@ -155,7 +155,7 @@ prob_type prob;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// 1. Initialize MPI and HYPRE.
|
||||
Mpi::Init(argc, argv);
|
||||
Mpi::Init_auto();
|
||||
int num_procs = Mpi::WorldSize();
|
||||
int myid = Mpi::WorldRank();
|
||||
Hypre::Init();
|
||||
|
||||
@@ -42,7 +42,7 @@ using namespace mfem;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// 1. Initialize MPI and HYPRE.
|
||||
Mpi::Init(argc, argv);
|
||||
Mpi::Init_auto();
|
||||
int num_procs = Mpi::WorldSize();
|
||||
int myid = Mpi::WorldRank();
|
||||
Hypre::Init();
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
#include "sort_pairs.hpp"
|
||||
#include "globals.hpp"
|
||||
|
||||
#ifdef MFEM_USE_STRUMPACK
|
||||
#include <StrumpackConfig.hpp> // STRUMPACK_USE_PTSCOTCH, etc
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
@@ -34,6 +38,51 @@ using namespace std;
|
||||
namespace mfem
|
||||
{
|
||||
|
||||
// static private method
|
||||
void Mpi::Init_(int *argc, char ***argv)
|
||||
{
|
||||
MFEM_VERIFY(!IsInitialized(), "MPI already initialized!")
|
||||
#if defined(MFEM_USE_STRUMPACK)
|
||||
#if defined(STRUMPACK_USE_PTSCOTCH) || defined(STRUMPACK_USE_SLATE_SCALAPACK)
|
||||
if (Root())
|
||||
{
|
||||
MFEM_WARNING("STRUMPACK built with SLATE or PT-Scotch may require "
|
||||
"MPI_Init_thread with MPI_THREAD_MULTIPLE!");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
int mpi_err = MPI_Init(argc, argv);
|
||||
MFEM_VERIFY(!mpi_err, "error in MPI_Init()!");
|
||||
// The Mpi singleton object below needs to be created after MPI_Init() for
|
||||
// some MPI implementations
|
||||
Singleton();
|
||||
}
|
||||
|
||||
// static public method
|
||||
void Mpi::Init_thread(int required, int *provided)
|
||||
{
|
||||
MFEM_VERIFY(!IsInitialized(), "MPI already initialized!")
|
||||
int provided_;
|
||||
int mpi_err = MPI_Init_thread(nullptr, nullptr, required,
|
||||
provided ? provided : &provided_);
|
||||
MFEM_VERIFY(!mpi_err, "error in MPI_Init_thread()!");
|
||||
// The Mpi singleton object below needs to be created after MPI_Init() for
|
||||
// some MPI implementations
|
||||
Singleton();
|
||||
}
|
||||
|
||||
// static public method
|
||||
void Mpi::Init_auto()
|
||||
{
|
||||
#if defined(MFEM_USE_STRUMPACK) && \
|
||||
(defined(STRUMPACK_USE_PTSCOTCH) || defined(STRUMPACK_USE_SLATE_SCALAPACK))
|
||||
Mpi::Init_thread(MPI_THREAD_MULTIPLE);
|
||||
#else
|
||||
Mpi::Init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
GroupTopology::GroupTopology(const GroupTopology >)
|
||||
: MyComm(gt.MyComm),
|
||||
group_lproc(gt.group_lproc)
|
||||
|
||||
+17
-14
@@ -36,6 +36,18 @@ public:
|
||||
static void Init() { Init_(NULL, NULL); }
|
||||
/// Singleton creation with Mpi::Init(argc,argv);
|
||||
static void Init(int &argc, char **&argv) { Init_(&argc, &argv); }
|
||||
/// Singleton creation; MPI is initialized using MPI_Init_thread.
|
||||
/** For a description of the parameters @a required and @a provided, see the
|
||||
documentation for MPI_Init_thread. When the parameter @a provided is
|
||||
@c nullptr (default), no output value is returned. */
|
||||
static void Init_thread(int required, int *provided = nullptr);
|
||||
/** @brief Singleton creation; MPI is initialized appropriately for all
|
||||
configured external libraries used by MFEM. */
|
||||
/** @note In some cases, this method may not be able to select the correct
|
||||
MPI initialization method. In such cases, initialization with Mpi::Init()
|
||||
or Mpi::Init_thread() is recommended based on the needs of the
|
||||
application. */
|
||||
static void Init_auto();
|
||||
/// Finalize MPI (if it has been initialized and not yet already finalized).
|
||||
static void Finalize()
|
||||
{
|
||||
@@ -72,23 +84,14 @@ public:
|
||||
/// Return true if the rank in MPI_COMM_WORLD is zero.
|
||||
static bool Root() { return WorldRank() == 0; }
|
||||
private:
|
||||
/// Initialize MPI
|
||||
static void Init_(int *argc, char ***argv)
|
||||
/// Initialize the Mpi singleton.
|
||||
static Mpi &Singleton()
|
||||
{
|
||||
MFEM_VERIFY(!IsInitialized(), "MPI already initialized!")
|
||||
#if defined(MFEM_USE_STRUMPACK)
|
||||
#if defined(STRUMPACK_USE_PTSCOTCH) || defined(STRUMPACK_USE_SLATE_SCALAPACK)
|
||||
if (Root())
|
||||
{
|
||||
MFEM_WARNING("STRUMPACK built with SLATE or PT-Scotch may require MPI_Init_thread with MPI_THREAD_MULTIPLE!");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
MPI_Init(argc, argv);
|
||||
// The "mpi" object below needs to be created after MPI_Init() for some
|
||||
// MPI implementations
|
||||
static Mpi mpi;
|
||||
return mpi;
|
||||
}
|
||||
/// Initialize MPI using MPI_Init()
|
||||
static void Init_(int *argc, char ***argv);
|
||||
/// Finalize MPI
|
||||
~Mpi() { Finalize(); }
|
||||
/// Prevent direct construction of objects of this class
|
||||
|
||||
@@ -322,17 +322,19 @@ int main(int argc, char *argv[])
|
||||
|
||||
char vishost[] = "localhost";
|
||||
int visport = 19916;
|
||||
socketstream cyl_sol_sock(vishost, visport);
|
||||
socketstream cyl_sol_sock;
|
||||
if (visualization)
|
||||
{
|
||||
cyl_sol_sock.open(vishost, visport);
|
||||
cyl_sol_sock << "parallel " << num_procs << " " << myid << "\n";
|
||||
cyl_sol_sock.precision(8);
|
||||
cyl_sol_sock << "solution\n" << cylinder_submesh << temperature_cylinder_gf <<
|
||||
"pause\n" << std::flush;
|
||||
}
|
||||
socketstream block_sol_sock(vishost, visport);
|
||||
socketstream block_sol_sock;
|
||||
if (visualization)
|
||||
{
|
||||
block_sol_sock.open(vishost, visport);
|
||||
block_sol_sock << "parallel " << num_procs << " " << myid << "\n";
|
||||
block_sol_sock.precision(8);
|
||||
block_sol_sock << "solution\n" << block_submesh << temperature_block_gf <<
|
||||
|
||||
Reference in New Issue
Block a user