Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
MPImanager.h
Go to the documentation of this file.
1 
27 #ifndef __MPIMANAGER_H
28 #define __MPIMANAGER_H
29 
30 #include <queue>
31 #include <string>
32 #include <map>
33 
34 #ifdef USE_MPI
35 #include <mpi.h>
36 #endif
37 
43 class SimRunner;
44 class StatServices;
45 
46 class MPImanager {
47 
48  public:
50  virtual ~MPImanager() {}
51  virtual unsigned int init( StatServices* StatManager ) = 0;
52  virtual void finish( StatServices* StatManager, unsigned int *_gen, unsigned int _repl );
53  virtual void iterate( SimRunner *_sim, StatServices* StatManager, unsigned int *_gen, unsigned int *_repl ) = 0;
54 
55  protected:
56  double **buf_dbl; //receives stat records from each worker [num_worker][buf_stride]
57  unsigned int **buf_int; //is [2][num_worker]: how many records [0] and which replicate [1] done by each worker
58  unsigned int buf_stride;//number of stat recorders x number of generations recorded
59  int num_worker; //worker count
60 
61 };
62 
63 #ifdef USE_MPI
76 class MPImaster : public MPImanager {
77 
78  public:
79  MPImaster( const unsigned int count );
80  ~MPImaster() { delete[] _request; }
81  unsigned int init( StatServices *StatManager );
82  void finish( StatServices *StatManager, unsigned int *_gen, unsigned int _repl );
83  void iterate( SimRunner *_sim, StatServices* StatManager, unsigned int *_gen, unsigned int *_repl );
84 
85  private:
86  MPI_Request *_request;
87  std::vector< unsigned int > worker_job; //records the current replicate done by worker i
88  unsigned int waitWorker();
89  unsigned int assign( const unsigned int job, const unsigned int worker );
90 
91 };
92 
103 class MPIworker : public MPImanager {
104 
105  public:
106  MPIworker() {}
107  unsigned int init( StatServices *StatManager );
108  void iterate( SimRunner *_sim, StatServices *StatManager, unsigned int *_gen, unsigned int *_repl );
109 
110 };
111 #endif
112 
120 class MPIenv {
121 
122  public:
123  MPIenv( int *argc, char ***argv, MPImanager *&_p );
124  static void abort( int i );
125  static void finish( MPImanager *p );
126  bool isMaster() const { return (rank==0); }
127  int workerCount() const { return size-1; }
128  int workerRank() const { return rank; }
129  std::string hostName() const { return host; }
130 
131  private:
132  int size;
133  int rank;
134  std::string host;
135 
136 };
137 
138 #endif
MPI environment setup.
Definition: MPImanager.h:120
MPIenv(int *argc, char ***argv, MPImanager *&_p)
Definition: MPImanager.cc:38
int size
Definition: MPImanager.h:132
std::string hostName() const
Definition: MPImanager.h:129
bool isMaster() const
Definition: MPImanager.h:126
static void finish(MPImanager *p)
Definition: MPImanager.cc:88
static void abort(int i)
Definition: MPImanager.cc:79
std::string host
Definition: MPImanager.h:134
int rank
Definition: MPImanager.h:133
int workerCount() const
Definition: MPImanager.h:127
int workerRank() const
Definition: MPImanager.h:128
Definition: MPImanager.h:46
int num_worker
Definition: MPImanager.h:59
virtual unsigned int init(StatServices *StatManager)=0
unsigned int ** buf_int
Definition: MPImanager.h:57
virtual ~MPImanager()
Definition: MPImanager.h:50
unsigned int buf_stride
Definition: MPImanager.h:58
MPImanager()
Definition: MPImanager.h:49
double ** buf_dbl
Definition: MPImanager.h:56
virtual void iterate(SimRunner *_sim, StatServices *StatManager, unsigned int *_gen, unsigned int *_repl)=0
virtual void finish(StatServices *StatManager, unsigned int *_gen, unsigned int _repl)
Performs the setup of the Metapop and SimComponents and runs the simulation.
Definition: simulation.h:51
The Service class used to manage the StatHandler objects.
Definition: statservices.h:48

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR