OpenM++ runtime library (libopenm)
Loading...
Searching...
No Matches
modelHelper.h
Go to the documentation of this file.
1
5// Copyright (c) 2013-2015 OpenM++
6// This code is licensed under the MIT license (see LICENSE.txt for details)
7
8#ifndef MODEL_HELPER_H
9#define MODEL_HELPER_H
10
11using namespace std;
12
13namespace openm
14{
15 // atomic bool vector to store sub-value done status
17 {
18 public:
19 DoneVector(size_t i_size) { init(i_size); };
20
21 // create new vector of bool values
22 void init(size_t i_size);
23
24 // clear all values: set it to false
25 void reset(void);
26
27 // return true if all values are set to true
28 bool isAll(void);
29
30 // set to true value at specified position
31 void setAt(size_t i_pos);
32
33 // return count of contiguous true values staring from zero position
34 int countFirst(void);
35
36 private:
37 recursive_mutex theMutex; // mutex to lock access operations
38 vector<bool> isDoneVec; // if true then all sub-value accumulators saved in database
39
40 private:
41 DoneVector(const DoneVector & i_doneVec) = delete;
42 DoneVector & operator=(const DoneVector & i_doneVec) = delete;
43 };
44
45 // helper struct to define modeling groups size and count: groups of processes for parallel run of modeling task
47 {
48 int groupSize; // size of modeling group
49 int groupCount; // number of modeling groups
50 int activeRank; // active rank in group: process index among other modeling processes in the group
51 int groupOne; // current process modeling group number, one based, not a zero based
52 bool isRootActive; // if true then root process used for modeling else dedicated for data exchange
53 int subPerProcess; // number of sub-values per modeling process, except of root process and last process
54 int selfSubCount; // number of sub-values for current process
55 int rootSubCount; // number of sub-values for root process
56 int firstSubId; // sub-value staring index for current modeling process
57
58 static const int all = 0; // worldwide group, all processes
59
60 ProcessGroupDef(void) :
61 groupSize(1), groupCount(0), activeRank(0), groupOne(0), isRootActive(true), subPerProcess(1), selfSubCount(1), rootSubCount(0), firstSubId(0)
62 { }
63
64 ProcessGroupDef(int i_subValueCount, int i_threadCount, bool i_isRootIdle, int i_worldSize, int i_worldRank);
65 };
66
67 // helper struct to hold modeling group run id and run state
68 struct RunGroup
69 {
70 int groupOne; // modeling group number, one based, not a zero based
71 int runId; // if > 0 then model run id
72 int setId; // if > 0 then set id of source input parametes
73 int firstChildRank; // world rank of first child process
74 int childCount; // number of child processes in group
75 bool isUseRoot; // if true then root process used for modeling else dedicated for data exchange
76 int groupSize; // size of modeling group
77 int subPerProcess; // number of sub-values per modeling process, except of root process and last process
78 int rootSubCount; // number of sub-values for root process
79 ModelRunState state; // group status and modeling progress
80 DoneVector isSubDone; // size of [subValue count], if true then all sub-value accumulators saved in database
81 vector<ModelRunState> childState; // size of [childCount] run state for all group child processes
82
83 // set initial run group size, assign process ranks and initial state state
84 RunGroup(int i_groupOne, int i_subValueCount, const ProcessGroupDef & i_rootGroupDef);
85
86 // set group state for next run
87 void nextRun(int i_runId, int i_setId, ModelStatus i_status);
88
89 // clear group state after run
90 void reset(void) { nextRun(0, 0, ModelStatus::init); }
91
92 // return child world rank where sub-value is calculated
93 int rankBySubValueId(int i_subId) const;
94
95 private:
96 RunGroup(const RunGroup & i_runGroup) = delete;
97 RunGroup & operator=(const RunGroup & i_runGroup) = delete;
98 };
99
100 // helper struct to receive output table values for each accumulator
102 {
103 int runId; // run id to receive
104 int subValueId; // sub-value index to receive
105 int tableId; // output table id
106 int accId; // accumulator id
107 size_t valueSize; // size of accumulator data
108 bool isReceived; // if true then data received
109 int senderRank; // sender rank: process where accumulator calculated
110 int msgTag; // accumulator message tag
111
113 int i_runId,
114 int i_subId,
115 int i_subValueCount,
116 int i_senderRank,
117 int i_tableId,
118 int i_accId,
119 int i_accIndex,
120 size_t i_valueSize
121 ) :
122 runId(i_runId),
123 subValueId(i_subId),
124 tableId(i_tableId),
125 accId(i_accId),
126 valueSize(i_valueSize),
127 isReceived(false),
128 senderRank(i_senderRank),
129 msgTag(accMsgTag(i_subId, i_subValueCount, i_accIndex))
130 { }
131
133 static int accMsgTag(int i_subId, int i_subValueCount, int i_accIndex)
134 {
135 return ((int)MsgTag::outSubValueBase + i_accIndex) * i_subValueCount + i_subId;
136 }
137 };
138}
139
140#endif // MODEL_HELPER_H
Definition modelHelper.h:17
model run state: thread safe
Definition modelRunState.h:24
openM++ namespace
Definition log.h:32
@ outSubValueBase
input parameter
ModelStatus
modeling job status
Definition omModelRunState.h:43
@ init
initial status
Definition modelHelper.h:102
static int accMsgTag(int i_subId, int i_subValueCount, int i_accIndex)
return accumulator message tag
Definition modelHelper.h:133
Definition modelHelper.h:47
Definition modelHelper.h:69