OpenM++ runtime library (libopenm)
model.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_H
9#define MODEL_H
10
11#include <memory>
12#include <stdexcept>
13#include <mutex>
14#include <future>
15#include <list>
16using namespace std;
17
18#include "libopenm/omLog.h"
20#include "libopenm/omModel.h"
21#include "libopenm/common/xz_crc64.h"
23#include "dbMetaTable.h"
24#include "modelRunState.h"
25#include "metaHolder.h"
26#include "runController.h"
27
28namespace openm
29{
31 class ModelBase : public IModel
32 {
33 public:
34 ~ModelBase(void) noexcept { }
35
37 static ModelBase * create(
38 int i_runId,
39 int i_subCount,
40 int i_subId,
41 RunController * i_runCtrl,
42 const MetaHolder * i_metaStore
43 );
44
46 int subValueCount(void) const noexcept override { return runOptions()->subValueCount; }
47
49 int subValueId(void) const noexcept override { return runOptions()->subValueId; }
50
52 int parameterSubValueIndex(const char * i_name) const override;
53
55 const RunOptions * runOptions(void) const override { return &runOpts; }
56
58 int tableIdByName(const char * i_name) const override { return runCtrl->tableIdByName(i_name); };
59
61 bool isSuppressed(const char * i_name) const override { return runCtrl->isSuppressed(i_name); };
62
64 void writeOutputTable(const char * i_name, size_t i_size, forward_list<unique_ptr<double[]> > & io_accValues) override;
65
67 void updateProgress(int i_count, double i_value = 0.0) override { runCtrl->runStateStore().updateProgress(runId, runOpts.subValueId, i_count, i_value); }
68
77 virtual void writeDbMicrodata(int i_entityKind, uint64_t i_microdataKey, const void * i_entityThis) override;
78
80 virtual void writeCsvMicrodata(int i_entityKind, uint64_t i_microdataKey, int i_eventId, bool i_isSameEntity, const void * i_entityThis) override;
81
82 private:
83 int modelId; // model id in database
84 int runId; // model run id
85 RunController * runCtrl; // run controller interface
86 const MetaHolder * metaStore; // metadata tables
87 RunOptions runOpts; // model run options
88 string microdataBuf; // microdata write buffer
89
91 int i_modelId,
92 int i_runId,
93 int i_subCount,
94 int i_subId,
95 RunController * i_runCtrl,
96 const MetaHolder * i_metaStore
97 );
98
99 // helper struct to store output table save status
100 struct TableDoneItem
101 {
102 int tableId; // output table id
103 bool isDone; // if true then table is written into db or send to root process
104
105 TableDoneItem(const TableDicRow & i_tableRow) : tableId(i_tableRow.tableId), isDone(false)
106 { }
107 };
108 vector<TableDoneItem> tableDoneVec; // status for all output tables of sub-value
109
110 private:
111 ModelBase(const ModelBase & i_model) = delete;
112 ModelBase & operator=(const ModelBase & i_model) = delete;
113 };
114}
115
116#endif // MODEL_H
bool isSuppressed(const char *i_name) const
check by name if output table suppressed
Definition: metaLoader.h:287
int tableIdByName(const char *i_name) const
return id of output table by name
Definition: metaLoader.cpp:127
model sub-value run base class
Definition: model.h:32
int tableIdByName(const char *i_name) const override
return id of output table by name
Definition: model.h:58
int subValueCount(void) const noexcept override
number of sub-values
Definition: model.h:46
void writeOutputTable(const char *i_name, size_t i_size, forward_list< unique_ptr< double[]> > &io_accValues) override
write result into output table and release accumulators memory.
Definition: modelBase.cpp:115
bool isSuppressed(const char *i_name) const override
check by name if output table suppressed.
Definition: model.h:61
static ModelBase * create(int i_runId, int i_subCount, int i_subId, RunController *i_runCtrl, const MetaHolder *i_metaStore)
model factory: create new model sub-value run.
Definition: modelBase.cpp:59
virtual void writeDbMicrodata(int i_entityKind, uint64_t i_microdataKey, const void *i_entityThis) override
write microdata into the database.
Definition: modelBase.cpp:166
void updateProgress(int i_count, double i_value=0.0) override
set modeling progress count and value
Definition: model.h:67
int parameterSubValueIndex(const char *i_name) const override
return index of parameter sub-value in the storage array for current modeling thread
Definition: modelBase.cpp:75
virtual void writeCsvMicrodata(int i_entityKind, uint64_t i_microdataKey, int i_eventId, bool i_isSameEntity, const void *i_entityThis) override
write microdata into CSV file or into trace
Definition: modelBase.cpp:188
const RunOptions * runOptions(void) const override
return model run options
Definition: model.h:55
int subValueId(void) const noexcept override
sub-value index of current modeling thread
Definition: model.h:49
run controller: create new model run(s) and support data exchange.
Definition: runController.h:24
RunStateHolder & runStateStore(void)
return holder of all sub-values modeling run states
Definition: runController.h:71
bool updateProgress(int i_runId, int i_subId, int i_count, double i_value)
set modeling progress count and value, return false if not exist
Definition: modelRunState.cpp:192
OpenM++ data library: db rows of model metadata tables.
OpenM++ data library: db tables for model metadata.
OpenM++ modeling library: holder struct for metadata tables used by model.
OpenM++ modeling library: implementation.
openM++ namespace
Definition: log.h:32
OpenM++ common file utilities.
OpenM++: public interface for log and trace support.
OpenM++ modeling library: public interface.
OpenM++ modeling library: public base class for run controller to run modeling process.
model sub-value run public interface
Definition: omModel.h:136
Holder for model metadata core part (not include model text).
Definition: metaHolder.h:20
basic model run options
Definition: omModel.h:26
int subValueId
sub-value index for current modeling thread
Definition: omModel.h:31
int subValueCount
number of sub-values
Definition: omModel.h:28
table_dic table row.
Definition: dbMetaRow.h:741