OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
ManyMasterSplit.h
Go to the documentation of this file.
1#ifndef __ONE_MASTER_SPLIT__
2#define __ONE_MASTER_SPLIT__
3
4#include "mpi.h"
5
6#include "Comm/types.h"
8
9#include "Util/CmdArguments.h"
11
12
21template < class TopoDiscoveryStrategy >
22class ManyMasterSplit : protected SplitStrategy, public TopoDiscoveryStrategy {
23
24public:
25
26 ManyMasterSplit(CmdArguments_t args, MPI_Comm comm = MPI_COMM_WORLD)
27 : SplitStrategy(args, comm)
28 {}
29
30
32 {}
33
34
35 virtual void split() {
36
38
39 size_t group_size = num_procs_ / num_masters_;
40 group_id_ = rank_ / group_size;
41 Comm::id_t group_start = group_id_ * group_size;
42
43 // Fix Pilot to core start_group + 1
44 poller_ = group_start;
45
46 // Master and Optimizer fixed to first two cores of group
47 if(rank_ % group_size == 0) {
48
49 role_ = POLLER;
50 leader_ = 0;
51
52 } else if(rank_ % group_size == 1) {
53
55 leader_ = 1;
56
57 } else {
58
59 role_ = WORKER;
60 Comm::localId_t worker_group = ((rank_ % group_size) - 2) /
62
63 leader_ = group_start + 2 + worker_group * num_coworkers_worker_;
64 leader_ = leader_ % group_size;
65 }
66
67 // define coloring for splitting starting with INTERNAL comm
68 colorings_.push_back(group_start + leader_);
69
70 // .. and optimizer -- poller leaders
71 if(role_ == WORKER ||
72 rank_ % group_size != static_cast<size_t>(leader_))
73 colorings_.push_back(MPI_UNDEFINED);
74 else
75 colorings_.push_back(group_id_);
76
77 // .. and worker -- poller leaders
78 if(role_ == OPTIMIZER ||
79 rank_ % group_size != static_cast<size_t>(leader_))
80 colorings_.push_back(MPI_UNDEFINED);
81 else
82 colorings_.push_back(group_id_);
83
84 // .. and finally the "world" communicator
85 if(role_ == WORKER)
86 colorings_.push_back(0);
87 else if(role_ == OPTIMIZER)
88 colorings_.push_back(1);
89 else
90 colorings_.push_back(2);
91
92 //FIXME:
93 if(role_ == POLLER)
94 leader_ = 1;
95 }
96
97 virtual int getNrWorkerGroups() const {
99 }
100
101private:
102
105
107
109 try {
110 num_coworkers_worker_ = cmd_args_->getArg<size_t>("num-coworkers");
111 } catch (OptPilotException &e) {
112 std::cout << "\033[01;31m" << "Could not find 'num-coworkers' "
113 << "in arguments.. Aborting." << "\e[0m" << std::endl;
114 MPI_Abort(getComm(), -111);
115 }
116
117
118 num_masters_ = 1;
119 try {
120 num_masters_ = cmd_args_->getArg<size_t>("num-masters");
121 } catch (OptPilotException &e) {
122 std::cout << "\033[01;31m" << "Could not find 'num-masters' "
123 << "in arguments.. Aborting." << "\e[0m" << std::endl;
124 MPI_Abort(getComm(), -1111);
125 }
126
127 if(num_masters_ == 0 || num_coworkers_worker_ == 0) {
128 std::cout << "\033[01;31m" << "Need at least"
129 << " 1 master and 1 coworker to run.. Aborting." << "\e[0m" << std::endl;
130 MPI_Abort(getComm(), -1111);
131 }
132
133 if(static_cast<size_t>(num_procs_) < num_masters_ *
134 (2 + num_coworkers_worker_)) {
135 std::cout << "\033[01;31m" << "Need at least "
137 << " cores to run.. Aborting." << "\e[0m" << std::endl;
138 MPI_Abort(getComm(), -1111);
139 }
140 }
141
142};
143
144#endif
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
@ POLLER
Definition: Types.h:35
@ OPTIMIZER
Definition: Types.h:35
@ WORKER
Definition: Types.h:35
boost::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:176
constexpr double e
The value of.
Definition: Physics.h:39
size_t id_t
Definition: types.h:28
size_t localId_t
Definition: types.h:29
ManyMasterSplit(CmdArguments_t args, MPI_Comm comm=MPI_COMM_WORLD)
virtual void split()
virtual ~ManyMasterSplit()
virtual int getNrWorkerGroups() const
Get number of worker groups.
size_t num_coworkers_worker_
Defines an interface for splitter strategy implementations.
Definition: SplitStrategy.h:13
int leader_
every core specifies a leader (master is its own leader)
Definition: SplitStrategy.h:81
std::vector< unsigned int > colorings_
defines comm splitting
Definition: SplitStrategy.h:78
int poller_
every core can specifies a master
Definition: SplitStrategy.h:84
CmdArguments_t cmd_args_
Definition: SplitStrategy.h:73
MPI_Comm getComm() const
Definition: SplitStrategy.h:49