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

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

Member Function Documentation

◆ abort()

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

Referenced by abort(), and fatal().

+ Here is the caller graph for this function:

◆ finish()

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

Referenced by SimRunner::run().

+ Here is the caller graph for this function:

◆ hostName()

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

References host.

◆ isMaster()

bool MPIenv::isMaster ( ) const
inline

◆ workerCount()

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

References size.

Referenced by RAND::init().

+ Here is the caller graph for this function:

◆ workerRank()

int MPIenv::workerRank ( ) const
inline
129 { 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.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR