OpenM++ runtime library (libopenm)
modelRunState.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_RUN_STATE_H
9 #define MODEL_RUN_STATE_H
10 
11 #include <chrono>
12 #include <list>
13 #include <mutex>
14 #include <forward_list>
15 using namespace std;
16 
17 #include "libopenm/omModel.h"
18 #include "helper.h"
19 
20 namespace openm
21 {
23  class ModelRunState : public virtual IModelRunState, private RunState
24  {
25  public:
27  ModelRunState(void) : RunState() { };
28 
30  ModelStatus status(void) override;
31 
33  bool isFinal(void) override;
34 
36  bool isError(void) override;
37 
39  bool isShutdownOrFinal(void) override;
40 
42  RunState get(void) override;
43 
45  ModelStatus updateStatus(ModelStatus i_status) override;
46 
48  void updateProgress(int i_count, double i_value = 0.0) override;
49 
50  private:
51  recursive_mutex theMutex; // mutex to lock status upadte operations
52 
53  private:
54  ModelRunState(const ModelRunState & i_state) = delete;
55  ModelRunState & operator=(const ModelRunState & i_state) = delete;
56 
57  };
58 
61  {
62  public:
63  RunStateHolder(void) { }
64 
66  tuple<bool, RunState> get(int i_runId, int i_subId);
67 
69  void add(int i_runId, int i_subId) { add(i_runId, i_subId, RunState()); };
70 
72  void add(int i_runId, int i_subId, RunState i_state);
73 
75  ModelStatus updateStatus(int i_runId, int i_subId, ModelStatus i_status, bool i_isFinalUpdate = true);
76 
78  bool updateProgress(int i_runId, int i_subId, int i_count, double i_value);
79 
83  const map<pair<int, int>, RunState> saveUpdated(bool i_isNow = false);
84 
86  IRowBaseVec saveToRowVector(int i_runId);
87 
89  const RunState fromRowVector(const IRowBaseVec & i_src);
90 
91  private:
92  recursive_mutex theMutex; // mutex to lock access operations
93  map<pair<int, int>, RunState> stateMap; // store of current runs state for all sub-values, key: (run id, sub-value id) pair
94  map<pair<int, int>, RunState> updateStateMap; // run states updated since last save call
95  chrono::system_clock::time_point lastSaveTime = chrono::system_clock::time_point::min(); // last time of save
96 
97  private:
98  RunStateHolder(const RunStateHolder & i_state) = delete;
99  RunStateHolder & operator=(const RunStateHolder & i_state) = delete;
100  };
101 }
102 
103 #endif // MODEL_RUN_STATE_H
model run state public interface: thread safe
Definition: omModelRunState.h:140
ModelStatus
modeling job status
Definition: omModelRunState.h:44
model run state: thread safe
Definition: modelRunState.h:23
openM++ namespace
Definition: argReader.cpp:16
model run state data: status, progress, update times
Definition: omModelRunState.h:94
sub-value run state for all modeling threads, identified by (run id, sub-value id) pair ...
Definition: modelRunState.h:60
OpenM++ modeling library: public interface.
vector< IRowBaseUptr > IRowBaseVec
db rows: vector of unique pointers to db row
Definition: omHelper.h:190
void add(int i_runId, int i_subId)
add new or replace existing sub-value run state
Definition: modelRunState.h:69
ModelRunState(void)
initialize model run state
Definition: modelRunState.h:27
OpenM++ common helper utilities.