17static constexpr size_t MinSizeToSaveMicrodata = 128 * 1024;
18static constexpr size_t MaxSizeToSaveMicrodata = 2 * 1024 * 1024;
94 forward_list<unique_ptr<
double[]> > & io_accValues
99 return metaStore->runOptionTable ? metaStore->runOptionTable->isExist(
currentRunId(), i_key) :
false;
103 string strOption(
const char * i_key,
const string & i_default =
"") const noexcept
override {
104 return metaStore->runOptionTable ? metaStore->runOptionTable->strValue(
currentRunId(), i_key, i_default) : i_default;
108 bool boolOption(
const char * i_key)
const noexcept override {
109 return metaStore->runOptionTable ? metaStore->runOptionTable->boolValue(
currentRunId(), i_key) :
false;
119 return metaStore->runOptionTable ? metaStore->runOptionTable->boolValueToInt(
currentRunId(), i_key) : -1;
123 int intOption(
const char * i_key,
int i_default)
const noexcept override {
124 return metaStore->runOptionTable ? metaStore->runOptionTable->intValue(
currentRunId(), i_key, i_default) : i_default;
128 long long longOption(
const char * i_key,
long long i_default)
const noexcept override {
129 return metaStore->runOptionTable ? metaStore->runOptionTable->longValue(
currentRunId(), i_key, i_default) : i_default;
133 double doubleOption(
const char * i_key,
double i_default)
const noexcept override {
134 return metaStore->runOptionTable ? metaStore->runOptionTable->doubleValue(
currentRunId(), i_key, i_default) : i_default;
138 vector<pair<string, string>>
allOptions(
void)
const noexcept override;
176 void pushDbMicrodata(
int i_runId,
int i_entityKind, uint64_t i_microdataKey,
const void * i_entityThis);
186 void writeCsvMicrodata(
int i_entityKind, uint64_t i_microdataKey,
int i_eventId,
bool i_isSameEntity,
const void * i_entityThis,
string & io_line);
192 void makeCsvLineMicrodata(
const EntityItem & i_entityItem, uint64_t i_microdataKey,
int i_eventId,
bool i_isSameEntity,
const void * i_entityThis,
string & io_line)
const;
195 tuple<bool, const RunController::EntityItem &>
findEntityItem(
int i_entityKind)
const;
222 tuple<int, int, ModelStatus>
createNewRun(
int i_taskRunId,
bool i_isWaitTaskRun,
IDbExec * i_dbExec);
240 forward_list<unique_ptr<
double[]> > & io_accValues
250 map<int, EntityItem> entityMap;
251 vector<int> entityIds;
261 map<int, list<unique_ptr<uint8_t[]>>>
pullDbMicrodata(
bool i_isNow =
false);
277 ListFirstNext(list<unique_ptr<uint8_t[]>>::const_iterator i_begin, list<unique_ptr<uint8_t[]>>::const_iterator i_end) {
287 return rowIt != endIt ? rowIt->get() :
nullptr;
293 if (rowIt == endIt)
return nullptr;
296 return rowIt != endIt ? rowIt->get() :
nullptr;
299 list<unique_ptr<uint8_t[]>>::const_iterator beginIt;
300 list<unique_ptr<uint8_t[]>>::const_iterator endIt;
301 list<unique_ptr<uint8_t[]>>::const_iterator rowIt;
308 BytesFirstNext(
size_t i_rowCount,
size_t i_rowSize, uint8_t * i_rows) : count(i_rowCount), size(i_rowSize) {
309 totalSize = size * count;
317 if (pRows ==
nullptr || count <= 0 || size <= 0)
return nullptr;
320 return size <= totalSize ? pRows :
nullptr;
326 if (pRows ==
nullptr || count <= 0 || size <= 0 || rowNow >= count)
return nullptr;
329 return (rowNow + 1) * size <= totalSize ? pRows + (rowNow * size) :
nullptr;
334 size_t totalSize = 0;
353 tuple<int, string, bool, bool> findWorkset(
int i_setId,
IDbExec * i_dbExec);
356 int findBaseRun(
IDbExec * i_dbExec);
359 void createRunOptions(
int i_runId,
int i_setId,
const string & i_setName,
int i_baseRunId,
int i_taskRunId,
IDbExec * i_dbExec)
const;
362 void createRunParameters(
int i_runId,
int i_setId,
bool i_isWsDefault,
bool i_isReadonlyWsDefault,
int i_baseRunId,
IDbExec * i_dbExec)
const;
365 void createRunText(
int i_runId,
int i_setId,
IDbExec * i_dbExec)
const;
368 void createRunEntityTables(
IDbExec* i_dbExec);
371 void insertRunEntity(
int i_runId,
IDbExec * i_dbExec);
374 const string makeEntityGenDigest(
const EntityDicRow * i_entRow,
const vector<EntityAttrRow> i_attrRows)
const;
377 void writeOutputValues(
int i_runId,
IDbExec * i_dbExec)
const;
380 void writeMicrodataDigest(
int i_runId,
IDbExec * i_dbExec)
const;
383 void checkParamSubCounts(
int i_runId,
int i_subCount,
const ParamDicRow & i_paramRow,
IDbExec * i_dbExec)
const;
395 RunImportOpts findImportRun(
const string & i_modelName,
const ImportOpts & i_importOpts,
const IModelDicTable * i_mainModelTable,
IDbExec * i_dbExec)
const;
398 bool importOutputTable(
402 const RunImportOpts & i_riOpts,
408 bool importParameter(
412 const RunImportOpts & i_riOpts,
414 const ParamSubOpts & i_subOpts,
423 recursive_mutex theMutex;
424 list<unique_ptr<uint8_t[]>> rowLst;
425 chrono::system_clock::time_point lastSaveTime = chrono::system_clock::time_point::min();
427 map<int, EntityDbItem> entityDbMap;
433 tuple<bool, size_t> statusDbMicrodata(chrono::system_clock::time_point i_nowTime, EntityDbItem & i_entityDbItem);
436 list<unique_ptr<uint8_t[]>> && moveDbMicrodata(chrono::system_clock::time_point i_nowTime, EntityDbItem & io_entityDbItem);
444 recursive_mutex theMutex;
448 map<int, EntityCsvItem> entityCsvMap;
451 void initMicrodata(
void);
454 void closeCsvMicrodata(
void)
noexcept;
457 void writeCsvLineMicrodata(EntityCsvItem & io_entityCsvItem,
const string & i_line);
database connection wrapper to execute sql commands.
Definition: dbExec.h:21
public interface for message passing
Definition: msg.h:138
run controller: create new model run(s) and support data exchange.
Definition: runController.h:24
long long longOption(const char *i_key, long long i_default) const noexcept override
return long value of run option by i_key or default if not found or can not be converted to long.
Definition: runController.h:128
void updateRunState(IDbExec *i_dbExec, const map< pair< int, int >, RunState > i_updated) const
merge updated sub-values run statue into database
Definition: runController.cpp:353
int parameterSelfSubCount(int i_paramId) const override
number of parameter sub-values for current process
Definition: runController.h:51
virtual ~RunController(void) noexcept=0
last cleanup
Definition: runController.cpp:21
virtual void writeAccumulators(const RunOptions &i_runOpts, bool i_isLastTable, const char *i_name, size_t i_size, forward_list< unique_ptr< double[]> > &io_accValues)=0
write output table accumulators or send data to root process.
virtual int currentRunId(void) const noexcept=0
get run id of the current model run.
const string csvHeaderMicrodata(int i_entityKind) const
return microdata entity csv file header
Definition: runControllerMicrodata.cpp:882
virtual void shutdownOnExit(ModelStatus i_status)=0
model process shutdown if exiting without completion (ie: exit on error).
int parameterIdByName(const char *i_name) const override
return index of parameter by name
Definition: runController.h:45
int createTaskRun(int i_taskId, IDbExec *i_dbExec)
create task run entry in database
Definition: runControllerNewRun.cpp:16
bool isUseSubValue(int i_subId) const override
return true if sub-value used by current process
Definition: runController.h:65
int findTask(IDbExec *i_dbExec)
find modeling task, if specified
Definition: runControllerNewRun.cpp:57
int parameterSubCount(int i_paramId) const override
number of parameter sub-values for current model run
Definition: runController.h:48
virtual void init(void)=0
get number of sub-values, read and broadcast metadata.
tuple< bool, const RunController::EntityItem & > findEntityItem(int i_entityKind) const
check if any microdata write required for this entity kind
Definition: runControllerMicrodata.cpp:83
RunStateHolder & runStateStore(void)
return holder of all sub-values modeling run states
Definition: runController.h:71
string strOption(const char *i_key, const string &i_default="") const noexcept override
return string value of run option by i_key or default value if not found.
Definition: runController.h:103
virtual void shutdownWaitAll(void)=0
model process shutdown: cleanup resources.
void openCsvMicrodata(void)
create microdata CSV files for new model run.
Definition: runControllerMicrodata.cpp:889
void writeCsvMicrodata(int i_entityKind, uint64_t i_microdataKey, int i_eventId, bool i_isSameEntity, const void *i_entityThis, string &io_line)
write microdata into the CSV file.
Definition: runControllerMicrodata.cpp:853
int selfSubCount
number of sub-values for current process
Definition: runController.h:30
virtual int nextRun(void)=0
create new run and input parameters in database.
static RunController * create(const ArgReader &i_argOpts, bool i_isMpiUsed, IDbExec *i_dbExec, IMsgExec *i_msgExec)
create run controller, load metadata tables and broadcast it to all modeling processes.
Definition: runController.cpp:24
int intOption(const char *i_key, int i_default) const noexcept override
return int value of run option by i_key or default if not found or can not be converted to int.
Definition: runController.h:123
bool isOptionExist(const char *i_key) const noexcept override
return true if run option found by i_key in run_option table for the current run id.
Definition: runController.h:98
bool boolOption(const char *i_key) const noexcept override
return boolean value of run option by i_key or false if not found or value is not "yes",...
Definition: runController.h:108
tuple< int, int, ModelStatus > createNewRun(int i_taskRunId, bool i_isWaitTaskRun, IDbExec *i_dbExec)
create new run, create input parameters and run options for input working sets
Definition: runControllerNewRun.cpp:89
virtual void shutdownRun(int i_runId)=0
model run shutdown: save results and update run status.
int processCount
number of modeling processes: MPI world size
Definition: runController.h:33
void pushDbMicrodata(int i_runId, int i_entityKind, uint64_t i_microdataKey, const void *i_entityThis)
push microdata database rows into the buffer.
Definition: runControllerMicrodata.cpp:318
void updateRestartSubValueId(int i_runId, IDbExec *i_dbExec, int i_subRestart) const
update sub-value index to restart the run
Definition: runController.cpp:339
virtual bool childExchange(void)=0
exchange between root and child processes and threads.
int parameterSubValueIndex(int i_paramId, int i_subId) const override
return index of parameter sub-value in the storage array of sub-values
Definition: runController.h:57
void makeCsvLineMicrodata(const EntityItem &i_entityItem, uint64_t i_microdataKey, int i_eventId, bool i_isSameEntity, const void *i_entityThis, string &io_line) const
make attributes csv line by converting attribute values into string
Definition: runControllerMicrodata.cpp:954
double doubleOption(const char *i_key, double i_default) const noexcept override
return double value of run option by i_key or default if not found or can not be converted to double.
Definition: runController.h:133
void doShutdownAll(int i_taskRunId, IDbExec *i_dbExec)
implementation model process shutdown.
Definition: runController.cpp:127
void doShutdownOnExit(ModelStatus i_status, int i_runId, int i_taskRunId, IDbExec *i_dbExec)
impelementation of model process shutdown if exiting without completion.
Definition: runController.cpp:66
void doWriteAccumulators(int i_runId, IDbExec *i_dbExec, const RunOptions &i_runOpts, const char *i_name, size_t i_size, forward_list< unique_ptr< double[]> > &io_accValues) const
write output table accumulators if table is not suppressed.
Definition: runController.cpp:297
void doShutdownRun(int i_runId, int i_taskRunId, IDbExec *i_dbExec)
implementation of model run shutdown.
Definition: runController.cpp:157
RunController(const ArgReader &i_argStore)
create run controller
Definition: runController.h:202
bool isEntityEventInFilter(int i_entityKind, uint64_t i_microdataKey, int i_eventId) const
retrun true if entity event id is matching events filter or if there no filter and all events are all...
Definition: runControllerMicrodata.cpp:997
map< int, list< unique_ptr< uint8_t[]> > > pullDbMicrodata(bool i_isNow=false)
pull microdata database rows from the buffer.
Definition: runControllerMicrodata.cpp:359
int boolOptionToInt(const char *i_key) const noexcept override
search for boolean value of run option by i_key and return one of: return 1 if key found and value i...
Definition: runController.h:118
size_t doDbMicrodata(IDbExec *i_dbExec, int i_entityId, IRowsFirstNext &i_entityMdRows)
write entity microdata rows into database and return inserted rows count
Definition: runControllerMicrodata.cpp:422
int processRank
modeling processes rank: MPI rank
Definition: runController.h:36
vector< pair< string, string > > allOptions(void) const noexcept override
return a copy of all run options as [key, value] pairs, ordered by key.
Definition: runControllerNewRun.cpp:348
size_t doDbMicrodataSql(IDbExec *i_dbExec, const map< int, list< unique_ptr< uint8_t[]> > > &i_entityMdRows)
write microdata into database using sql insert literal and return inserted rows count
Definition: runControllerMicrodata.cpp:515
int subFirstId
sub-value staring index for current modeling process
Definition: runController.h:27
sub-value run state for all modeling threads, identified by (run id, sub-value id) pair
Definition: modelRunState.h:61
OpenM++ data library: db value classes access value rows: input parameter, accumulator or expression ...
openM++ namespace
Definition: log.h:32
ModelStatus
modeling job status
Definition: omModelRunState.h:43
arguments reader to get runtime arguments from command line and ini-file.
Definition: argReader.h:56
entity_dic table row.
Definition: dbMetaRow.h:1200
model_dic table public interface.
Definition: dbMetaTable.h:175
public interface to initialize model run and input parameters
Definition: omModel.h:112
parameter_dic join to model_parameter_dic table row.
Definition: dbMetaRow.h:473
parameter_dic join to model_parameter_import table row.
Definition: dbMetaRow.h:547
model input parameter name, type and size
Definition: omModel.h:184
array of bytes rows wrapped into IRowsFirstNext interface
Definition: runController.h:306
BytesFirstNext(size_t i_rowCount, size_t i_rowSize, uint8_t *i_rows)
create interface to opaque list of bytes rows
Definition: runController.h:308
virtual uint8_t * toNext(void) override
move pointer to the next row, return NULL at the end of rows.
Definition: runController.h:324
virtual uint8_t * toFirst(void) override
move pointer to the first row, return NULL if row list is empty.
Definition: runController.h:315
entity attribute item to write microdata into database or csv file
Definition: runController.h:142
unique_ptr< IValueFormatter > fmtValue
attribute value offset in database row buffer
Definition: runController.h:146
int idxOf
entity attribute metadata id
Definition: runController.h:144
ptrdiff_t rowOffset
attribute index in EntityNameSizeArr
Definition: runController.h:145
unique_ptr< IValueFormatter > sqlFmtValue
attribute value to string converter for csv output
Definition: runController.h:147
EntityAttrItem(int i_attrId, int i_index)
attribute value to string converter for database insert
Definition: runController.h:149
entity item to write microdata into database or csv file
Definition: runController.h:154
string sqlInsPrefix
database row size
Definition: runController.h:162
string csvHdr
db microdata table name
Definition: runController.h:160
string dbMicrodataTable
entity generation unique id, unique in that database
Definition: runController.h:159
string genDigest
entity attributes
Definition: runController.h:157
int genHid
entity generation digest
Definition: runController.h:158
vector< DbValueSetter > rowSetter
microdata sql statement prefix
Definition: runController.h:163
vector< EntityAttrItem > attrs
entity metadata id
Definition: runController.h:156
EntityItem(int i_entityId)
column types of insert statement
Definition: runController.h:166
vector< const type_info * > rowTypes
function helpers to set column value of insert statement
Definition: runController.h:164
size_t rowSize
microdata csv header line
Definition: runController.h:161
interface to opaque list of bytes rows
Definition: runController.h:265
virtual uint8_t * toNext(void)=0
move pointer to the next row, return NULL at the end of rows.
virtual uint8_t * toFirst(void)=0
move pointer to the first row, return NULL if row list is empty.
list of bytes rows wrapped into IRowsFirstNext interface
Definition: runController.h:275
virtual uint8_t * toNext(void) override
move pointer to the next row, return NULL at the end of rows.
Definition: runController.h:291
virtual uint8_t * toFirst(void) override
move pointer to the first row, return NULL if row list is empty.
Definition: runController.h:284
ListFirstNext(list< unique_ptr< uint8_t[]> >::const_iterator i_begin, list< unique_ptr< uint8_t[]> >::const_iterator i_end)
create interface to opaque list of bytes rows
Definition: runController.h:277
basic model run options
Definition: omModel.h:26
model run state data: status, progress, update times
Definition: omModelRunState.h:93