oomph::MPI_Helpers Class Reference

#include <oomph_utilities.h>

Static Public Member Functions

static void init (int argc, char **argv, const bool &make_duplicate_of_mpi_comm_world=true)
 
static void finalize ()
 finalize mpi More...
 
static OomphCommunicatorcommunicator_pt ()
 access to the global oomph-lib communicator More...
 
static bool mpi_has_been_initialised ()
 return true if MPI has been initialised More...
 

Private Member Functions

 MPI_Helpers ()
 
 MPI_Helpers (const MPI_Helpers &)
 

Static Private Attributes

static bool MPI_has_been_initialised = false
 Bool set to true if MPI has been initialised. More...
 
static OomphCommunicatorCommunicator_pt = 0
 the global communicator More...
 

Detailed Description

MPI_Helpers class contains static helper methods to support MPI within oomph-lib. The methods init(...) and finalize() initialize and finalize MPI in oomph-lib and manage the oomph-libs global communicator communicator_pt(). NOTE: This class encapsulates static helper methods and instances of it CANNOT be instantiated.

Constructor & Destructor Documentation

◆ MPI_Helpers() [1/2]

oomph::MPI_Helpers::MPI_Helpers ( )
private

private default constructor definition (to prevent instances of the class being instantiated)

◆ MPI_Helpers() [2/2]

oomph::MPI_Helpers::MPI_Helpers ( const MPI_Helpers )
private

private copy constructor definition (to prevent instances of the class being instantiated)

Member Function Documentation

◆ communicator_pt()

OomphCommunicator * oomph::MPI_Helpers::communicator_pt ( )
static

access to the global oomph-lib communicator

access to global communicator. This is the oomph-lib equivalent of MPI_COMM_WORLD

1047  {
1048 #ifdef MPI
1049 #ifdef PARANOID
1051  {
1052  std::ostringstream error_message_stream;
1053  error_message_stream
1054  << "MPI has not been initialised.\n Call MPI_Helpers::init(...)";
1055  throw OomphLibError(error_message_stream.str(),
1058  }
1059 #endif
1060  return Communicator_pt;
1061 
1062 #else // ifndef MPI
1063 
1064  // If MPI is not enabled then we are unlikely to have called init, so to
1065  // be nice to users create a new serial comm_pt if none exits.
1066 
1067  if (Communicator_pt == 0)
1068  {
1069  Communicator_pt = new OomphCommunicator;
1070  }
1071 
1072  // #ifdef PARANOID
1073  // if(!Communicator_pt->serial_communicator())
1074  // {
1075  // std::string error_msg =
1076  // "MPI_Helpers has somehow ended up with a non-serial\n"
1077  // + "communicator pointer even though MPI is disabled!";
1078  // throw OomphLibError(error_msg.str(),
1079  // OOMPH_CURRENT_FUNCTION,
1080  // OOMPH_EXCEPTION_LOCATION);
1081  // }
1082  // #endif
1083 
1084  return Communicator_pt;
1085 
1086 #endif // end ifdef MPI
1087  }
static OomphCommunicator * Communicator_pt
the global communicator
Definition: oomph_utilities.h:869
static bool MPI_has_been_initialised
Bool set to true if MPI has been initialised.
Definition: oomph_utilities.h:866
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References Communicator_pt, MPI_has_been_initialised, OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

Referenced by oomph::Z2ErrorEstimator::doc_flux(), oomph::MemoryUsage::doc_total_memory_usage(), oomph::HelmholtzMGPreconditioner< DIM >::full_setup(), oomph::Z2ErrorEstimator::get_element_errors(), oomph::Node::hanging_pt(), oomph::HypreInterface::hypre_solve(), oomph::HypreInterface::HypreInterface(), main(), oomph::Problem::Problem(), oomph::MemoryUsage::run_continous_top(), oomph::MGPreconditioner< DIM >::setup(), oomph::HelmholtzGMRESMG< MATRIX >::solve(), oomph::HelmholtzFGMRESMG< MATRIX >::solve(), and oomph::MemoryUsage::stop_continous_top().

◆ finalize()

void oomph::MPI_Helpers::finalize ( )
static

finalize mpi

finalize mpi (oomph-lib equivalent of MPI_Finalize()) Deletes the global oomph-lib communicator and finalizes MPI.

1033  {
1034  // delete the communicator
1035  delete Communicator_pt;
1036 
1037  // and call MPI_Finalize
1038 #ifdef OOMPH_HAS_MPI
1039  MPI_Finalize();
1040 #endif
1041  }

References Communicator_pt.

Referenced by main(), and oomph::CommandLineArgs::parse_and_assign().

◆ init()

void oomph::MPI_Helpers::init ( int  argc,
char **  argv,
const bool make_duplicate_of_mpi_comm_world = true 
)
static

initialise mpi (oomph-libs equivalent of MPI_Init(...)) Initialises MPI and creates the global oomph-lib communicator. If optional boolean flag is set to false, we use MPI_COMM_WORLD itself as oomph-lib's communicator. Defaults to true.

Initialize mpi. If optional boolean flag is set to false, we use MPI_COMM_WORLD itself as oomph-lib's communicator. Defaults to true.

986  {
987 #ifdef OOMPH_HAS_MPI
988  // call mpi int
989  MPI_Init(&argc, &argv);
990 
991 
992  // By default, create the oomph-lib communicator using MPI_Comm_dup so that
993  // the communicator has the same group of processes but a new context
994  MPI_Comm oomph_comm_world = MPI_COMM_WORLD;
995  if (make_duplicate_of_mpi_comm_world)
996  {
997  MPI_Comm_dup(MPI_COMM_WORLD, &oomph_comm_world);
998  }
999 
1000  if (MPI_COMM_WORLD != oomph_comm_world)
1001  {
1002  oomph_info << "Oomph-lib communicator is a duplicate of MPI_COMM_WORLD\n";
1003  }
1004  else
1005  {
1006  oomph_info << "Oomph-lib communicator is MPI_COMM_WORLD\n";
1007  }
1008 
1009  // create the oomph-lib communicator
1010  // note: oomph_comm_world is deleted when the destructor of
1011  // Communicator_pt is called
1012  Communicator_pt = new OomphCommunicator(oomph_comm_world, true);
1013 
1014  // Change MPI error handler so that error will return
1015  // rather than aborting
1016  MPI_Comm_set_errhandler(oomph_comm_world, MPI_ERRORS_RETURN);
1017 
1018  // Use MPI output modifier: Each processor precedes its output
1019  // by its rank
1020  oomph_mpi_output.communicator_pt() = Communicator_pt;
1021  oomph_info.output_modifier_pt() = &oomph_mpi_output;
1022 #else
1023  // create a serial communicator
1024  Communicator_pt = new OomphCommunicator;
1025 #endif
1026  MPI_has_been_initialised = true;
1027  }
OutputModifier *& output_modifier_pt()
Access function for the output modifier pointer.
Definition: oomph_definitions.h:476
OomphInfo oomph_info
Definition: oomph_definitions.cc:319

References Communicator_pt, MPI_has_been_initialised, oomph::oomph_info, and oomph::OomphInfo::output_modifier_pt().

Referenced by main().

◆ mpi_has_been_initialised()

Member Data Documentation

◆ Communicator_pt

OomphCommunicator * oomph::MPI_Helpers::Communicator_pt = 0
staticprivate

the global communicator

Referenced by communicator_pt(), finalize(), and init().

◆ MPI_has_been_initialised

bool oomph::MPI_Helpers::MPI_has_been_initialised = false
staticprivate

Bool set to true if MPI has been initialised.

Referenced by communicator_pt(), and init().


The documentation for this class was generated from the following files: