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

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