Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
MPIenv Class Reference

MPI environment setup. More...

#include <MPImanager.h>

+ Collaboration diagram for MPIenv:

Public Member Functions

 MPIenv (int *argc, char ***argv, MPImanager *&_p)
 
bool isMaster () const
 
int workerCount () const
 
int workerRank () const
 
std::string hostName () const
 

Static Public Member Functions

static void abort (int i)
 
static void finish (MPImanager *p)
 

Private Attributes

int size
 
int rank
 
std::string host
 

Detailed Description

MPI environment setup.

Provides basic node information: rank (0 is master, 1...size-1 are workers), hostname. Constructor creates the MPImanagers (Master or worker). This can be instantiated also in a single cpu situation, will return trivial values. The abort() function should always be used instead of exit().

Constructor & Destructor Documentation

◆ MPIenv()

MPIenv::MPIenv ( int *  argc,
char ***  argv,
MPImanager *&  _p 
)
39 {
40 #ifdef USE_MPI
41 
42 #ifdef DEBUG_MPI
43  message(">>>> STARTING NEMO MPI <<<<\n");
44 #endif
45 
46  MPI_Init( argc, argv );
47 
48  MPI_Comm_size(MPI_COMM_WORLD, &size);
49  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
50 
51  if(0 > size - 1){
52  fatal("MPI environment needs more than 1 cpu to run properly (found %i cpu).\n", size);
53  }
54 
55  int lhost;
56 // char *thost = new char[100];
57  char thost[MPI_MAX_PROCESSOR_NAME];
58 
59  // MPI::Get_processor_name(thost, lhost);
60  MPI_Get_processor_name(&thost[0], &lhost);
61 
62  host = std::string( thost, lhost );
63 
64  if ( rank == 0 ) _p = new MPImaster(size-1);
65  else _p = new MPIworker();
66 
67 #ifdef DEBUG_MPI
68  message(">>>> MPI_COMM_WORLD::size = %i\n",size);
69  message(">>>> I have rank %i (%s) on host %s <<<<\n", rank, (rank==0?"Master":"Worker"), host.c_str());
70 #endif
71 
72 #else
73  size = 1;
74  rank = 0;
75  host = std::string( "local" );
76 #endif
77 }
int size
Definition: MPImanager.h:132
std::string host
Definition: MPImanager.h:134
int rank
Definition: MPImanager.h:133
void fatal(const char *str,...)
Definition: output.cc:98
void message(const char *message,...)
Definition: output.cc:38

References fatal(), host, message(), rank, and size.

Member Function Documentation

◆ abort()

void MPIenv::abort ( int  i)
static
80 {
81 #ifdef USE_MPI
82 // MPI::COMM_WORLD.Abort(i);
83  MPI_Abort(MPI_COMM_WORLD, i);
84 #endif
85  exit(i);
86 }

Referenced by abort(), and fatal().

+ Here is the caller graph for this function:

◆ finish()

void MPIenv::finish ( MPImanager p)
static
89 {
90 #ifdef USE_MPI
91  delete p;
92  MPI_Finalize();
93 #endif
94 }

Referenced by SimRunner::run().

+ Here is the caller graph for this function:

◆ hostName()

std::string MPIenv::hostName ( ) const
inline
129 { return host; }

References host.

◆ isMaster()

bool MPIenv::isMaster ( ) const
inline

◆ workerCount()

int MPIenv::workerCount ( ) const
inline
127 { return size-1; }

References size.

Referenced by RAND::init().

+ Here is the caller graph for this function:

◆ workerRank()

int MPIenv::workerRank ( ) const
inline
128 { return rank; }

References rank.

Referenced by BinaryDataSaver::finish(), FileServices::getFirstReplicateFileName(), and RAND::init().

+ Here is the caller graph for this function:

Member Data Documentation

◆ host

std::string MPIenv::host
private

Referenced by hostName(), and MPIenv().

◆ rank

int MPIenv::rank
private

Referenced by isMaster(), MPIenv(), and workerRank().

◆ size

int MPIenv::size
private

Referenced by MPIenv(), and workerCount().


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

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR