-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMPIProcess.h
68 lines (52 loc) · 1.42 KB
/
MPIProcess.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* MPIProcess.h
*
* Created on: Jul 7, 2014
* Author: jrw32
*/
#ifndef MPIPROCESS_H
#define MPIPROCESS_H
#include <string>
#include <utility>
#include <deque>
#include "MPIProcessFactory.h"
namespace PLATO{
class MPIProcess {
protected:
MPIProcess();
protected:
virtual void processResponse(unsigned int bufsz, const char* buf) = 0;
virtual std::pair<unsigned int, const char*> nextQuery() = 0;
protected:
virtual const std::string& getMPIName() const = 0;
void processMPI(unsigned int threads);
// waits for all currently running models to return
void collect();
void sendAll(unsigned int, const char*) const;
private:
void sendMPI(const std::pair<unsigned int, const char*>& query);
std::deque<int> _idle_queue;
int n_procs;
//! Number of cores per node.
unsigned int _mpi_threads;
protected:
int _tag;
};
template <class T>
class MPIProcessImpl : virtual public MPIProcess{
protected:
MPIProcessImpl(const std::string& name) : _mpi_name(name) {
_tag = MPIProcessFactory::getFactory().getKeyPos(_mpi_name);
}
protected:
static const std::string& registerMPI(const std::string& key_in);
virtual const std::string& getMPIName() const { return _mpi_name;}
private:
std::string _mpi_name;
};
template<class T>
const std::string& MPIProcessImpl<T>::registerMPI(const std::string& key_in){
return MPIProcessFactory::getFactory().RegisterMPIProcess(key_in, &T::calculate_MPI);
}
}
#endif /* MPIPROCESS_H_ */