Nemo  2.3.56
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
45class SimRunner;
46class StatServices;
47
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
59 unsigned int **buf_int; //is [2][size]: replicate [0] and generation [1] done by each worker
60 unsigned int buf_stride, size; //size = worker count
61
62};
63
64#ifdef USE_MPI
77class 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 > worker_job; //records the current replicate done by worker i
89 unsigned int waitWorker();
90 unsigned int assign( const unsigned int job, const unsigned int worker );
91
92};
93
104class MPIworker : public MPImanager {
105
106 public:
107 MPIworker() {}
108 unsigned int init( StatServices *StatManager );
109 void iterate( SimRunner *_sim, StatServices *StatManager, unsigned int *_gen, unsigned int *_repl );
110
111};
112#endif
113
121class 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 workerCount() const { return size-1; }
129 unsigned int workerRank() 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
MPI environment setup.
Definition: MPImanager.h:121
std::string hostName() const
Definition: MPImanager.h:130
bool isMaster() const
Definition: MPImanager.h:127
unsigned int workerCount() const
Definition: MPImanager.h:128
static void finish(MPImanager *p)
Definition: MPImanager.cc:68
std::string host
Definition: MPImanager.h:135
unsigned int workerRank() const
Definition: MPImanager.h:129
unsigned int size
Definition: MPImanager.h:133
unsigned int rank
Definition: MPImanager.h:134
Definition: MPImanager.h:48
virtual unsigned int init(StatServices *StatManager)=0
unsigned int ** buf_int
Definition: MPImanager.h:59
virtual ~MPImanager()
Definition: MPImanager.h:52
unsigned int size
Definition: MPImanager.h:60
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
void abort()
Definition: output.cc:115

Generated for Nemo v2.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR