Nemo  2.3.46
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 slave
59  unsigned int **buf_int; //is [2][size]: replicate [0] and generation [1] done by each slave
60  unsigned int buf_stride, size; //size = slave count
61 
62 };
63 
64 #ifdef USE_MPI
65 
77 class MPImaster : public MPImanager {
78 
79  public:
80  MPImaster( const unsigned int count );
81  ~MPImaster() { delete[] _request; }
82  unsigned int init( StatServices *StatManager );
83  void finish( StatServices *StatManager, unsigned int *_gen, unsigned int _repl );
84  void iterate( SimRunner *_sim, StatServices* StatManager, unsigned int *_gen, unsigned int *_repl );
85 
86  private:
87  MPI::Request *_request;
88  std::vector< unsigned int > slave_job; //records the current replicate done by slave i
89  unsigned int waitSlave();
90  unsigned int assign( const unsigned int job, const unsigned int slave );
91 
92 };
93 
104 class MPIslave : public MPImanager {
105 
106  public:
107  MPIslave() {}
108  unsigned int init( StatServices *StatManager );
109  void iterate( SimRunner *_sim, StatServices *StatManager, unsigned int *_gen, unsigned int *_repl );
110 
111 };
112 #endif
113 
121 class MPIenv {
122 
123  public:
124  MPIenv( int &argc, char **&argv, MPImanager *&_p );
125  static void abort( int i );
126  static void finish( MPImanager *p );
127  bool isMaster() const { return (rank==0); }
128  unsigned int slaveCount() const { return size-1; }
129  unsigned int slaveRank() const { return rank; }
130  std::string hostName() const { return host; }
131 
132  private:
133  unsigned int size;
134  unsigned int rank;
135  std::string host;
136 
137 };
138 
139 #endif
MPImanager()
Definition: MPImanager.h:51
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
std::string host
Definition: MPImanager.h:135
virtual unsigned int init(StatServices *StatManager)=0
virtual void finish(StatServices *StatManager, unsigned int *_gen, unsigned int _repl)
unsigned int slaveCount() const
Definition: MPImanager.h:128
double ** buf_dbl
Definition: MPImanager.h:58
static void abort(int i)
Definition: MPImanager.cc:60
virtual ~MPImanager()
Definition: MPImanager.h:52
unsigned int slaveRank() const
Definition: MPImanager.h:129
unsigned int ** buf_int
Definition: MPImanager.h:59
std::string hostName() const
Definition: MPImanager.h:130
virtual void iterate(SimRunner *_sim, StatServices *StatManager, unsigned int *_gen, unsigned int *_repl)=0
Performs the setup of the Metapop and SimComponents and runs the simulation.
Definition: simulation.h:53
MPI environment setup.
Definition: MPImanager.h:121
unsigned int size
Definition: MPImanager.h:133
static void finish(MPImanager *p)
Definition: MPImanager.cc:68
unsigned int size
Definition: MPImanager.h:60
unsigned int buf_stride
Definition: MPImanager.h:60
unsigned int rank
Definition: MPImanager.h:134
Definition: MPImanager.h:48
bool isMaster() const
Definition: MPImanager.h:127
MPIenv(int &argc, char **&argv, MPImanager *&_p)
Definition: MPImanager.cc:40

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR