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

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

Member Function Documentation

◆ abort()

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

Referenced by abort(), and fatal().

◆ finish()

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

Referenced by SimRunner::run().

◆ hostName()

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

References host.

◆ isMaster()

◆ workerCount()

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

References size.

Referenced by RAND::init().

◆ workerRank()

int MPIenv::workerRank ( ) const
inline

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.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR