Skip to content

Commit

Permalink
Allow changing the number of threads used for parmodauto when launchi…
Browse files Browse the repository at this point in the history
…ng simulation. (#9609)

  - A new simulation option `-parmodNumThreads=N` is added. This can be
    used to specify the number of theads to be uses for parallel simulations.

    The default value is 0, signifying that the max concurrency of the
    host should be used (note that this includes hyperthreading.)

  - The new simulation option has no effect if the Modelica model is not
    compiled/translated with `--parmodauto` option set.
  • Loading branch information
mahge committed Oct 31, 2022
1 parent 712686c commit c89679f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions OMCompiler/Compiler/Template/CodegenC.tpl
Expand Up @@ -1183,8 +1183,11 @@ template simulationFile(SimCode simCode, String guid, String isModelExchangeFMU)
>>
let pminit = if Flags.getConfigBool(Flags.PARMODAUTO) then
<<

pm_model = PM_Model_create("<%fileNamePrefix%>", &data, threadData, 0 /*num threads*/);
int num_threads = 0;
if(omc_flag[FLAG_PARMODNUMTHREADS]) {
num_threads = atoi(omc_flagValue[FLAG_PARMODNUMTHREADS]);
}
pm_model = PM_Model_create("<%fileNamePrefix%>", &data, threadData, num_threads);
PM_Model_load_ODE_system(pm_model, functionODE_systems);

>>
Expand Down
8 changes: 7 additions & 1 deletion OMCompiler/SimulationRuntime/c/util/simulation_options.c
Expand Up @@ -156,6 +156,7 @@ const char *FLAG_NAME[FLAG_MAX+1] = {
/* FLAG_DATA_RECONCILE_Sx */ "sx",
/* FLAG_UP_HESSIAN */ "keepHessian",
/* FLAG_W */ "w",
/* FLAG_PARMODNUMTHREADS */ "parmodNumThreads",

"FLAG_MAX"
};
Expand Down Expand Up @@ -286,6 +287,7 @@ const char *FLAG_DESC[FLAG_MAX+1] = {
/* FLAG_DATA_RECONCILE_Sx */ "value specifies a csv-file with inputs as covariance matrix Sx for DataReconciliation",
/* FLAG_UP_HESSIAN */ "value specifies the number of steps, which keep hessian matrix constant",
/* FLAG_W */ "shows all warnings even if a related log-stream is inactive",
/* FLAG_PARMODNUMTHREADS */ "[int default: 0] value specifies the number of threads for simulation using parmodauto. If not specified (or is 0) it will use the systems max number of threads. Note that this option is ignored if the model is not compiled with --parmodauto",

"FLAG_MAX"
};
Expand Down Expand Up @@ -607,6 +609,8 @@ const char *FLAG_DETAILED_DESC[FLAG_MAX+1] = {
" Value specifies the number of steps, which keep Hessian matrix constant.",
/* FLAG_W */
" Shows all warnings even if a related log-stream is inactive.",
/* FLAG_PARMODNUMTHREADS */
" Value specifies the number of threads for simulation using parmodauto. If not specified (or is 0) it will use the systems max number of threads. Note that this option is ignored if the model is not compiled with --parmodauto",

"FLAG_MAX"
};
Expand Down Expand Up @@ -737,6 +741,7 @@ const flag_repeat_policy FLAG_REPEAT_POLICIES[FLAG_MAX] = {
/* FLAG_DATA_RECONCILE_Sx */ FLAG_REPEAT_POLICY_FORBID,
/* FLAG_UP_HESSIAN */ FLAG_REPEAT_POLICY_FORBID,
/* FLAG_W */ FLAG_REPEAT_POLICY_FORBID,
/* FLAG_PARMODNUMTHREADS */ FLAG_REPEAT_POLICY_FORBID,
};


Expand Down Expand Up @@ -865,7 +870,8 @@ const int FLAG_TYPE[FLAG_MAX] = {
/* FLAG_STEADY_STATE_TOL */ FLAG_TYPE_OPTION,
/* FLAG_DATA_RECONCILE_Sx */ FLAG_TYPE_OPTION,
/* FLAG_UP_HESSIAN */ FLAG_TYPE_OPTION,
/* FLAG_W */ FLAG_TYPE_FLAG
/* FLAG_W */ FLAG_TYPE_FLAG,
/* FLAG_PARMODNUMTHREADS */ FLAG_TYPE_OPTION,
};

const char *GB_METHOD_NAME[RK_MAX] = {
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/SimulationRuntime/c/util/simulation_options.h
Expand Up @@ -172,6 +172,7 @@ enum _FLAG
FLAG_DATA_RECONCILE_Sx,
FLAG_UP_HESSIAN,
FLAG_W,
FLAG_PARMODNUMTHREADS,

FLAG_MAX
};
Expand Down

0 comments on commit c89679f

Please sign in to comment.