The input file language¶
Simulation user Operator developer
An Onika input file (.msp) is a YAML file that describes the
simulation graph: which operators run, in which order, with which values.
This page describes every construct. For a guided introduction, see
Your first input file.
Structure of a file¶
The top level of an input file is a map. A few keys are special, all others define operators or batches:
| Key | Meaning |
|---|---|
simulation |
Entry point: the operator (usually a list) that Onika runs. |
includes |
List of other input files to load first. See Includes and merging. |
configuration |
Settings of the Onika runtime (logging, profiling, threads, GPU...). See Configuration reference. |
| any other name | Default values for an operator of that name, or the definition of a new batch (named group of operators). |
includes: [ my_defaults.msp ] # optional
configuration: # optional
logging: { debug: false }
global: # default values for operator 'global'
dt: 1.0
my_step: # a new batch
- next_time_step
- print_timestep
simulation: # what runs
- global
- my_step
Calling operators¶
In a list, each item calls an operator in one of two forms:
- next_time_step # name only: default values
- print_int: { prefix: "t = ", suffix: "\n" } # name: map of slot values
The map sets the values of the operator's slots. Use onika-exec --help <operator> to list the slots of an operator.
A key that matches no slot gives a warning listing the valid ones, and is ignored:
ERR: Warning: operator 'print_int' has no parameter 'prefx'. Valid parameters are: prefix suffix value (unknown keys are ignored)
With --debug-strict_slots true, it is a fatal error instead.
Tip
Some operators accept a shortcut. For example message: "Hello" is the
same as message: { mesg: "Hello" }.
Values and units¶
Slot values are YAML values converted to the slot type. Real values can carry a unit; they are converted to the internal unit system (SI by default):
global:
dt: 2.0 fs # stored as 2.0e-15 (seconds)
len: 1.5 ang # stored as 1.5e-10 (meters)
acc: 9.81 m.s^-2 # units combine with '.', powers with '^'
Arithmetic expressions¶
A real value can be an arithmetic expression (evaluated with the TinyExpr library bundled with Onika), optionally followed by a unit. The expression must not contain spaces: the first space separates it from the unit.
global:
a: 2*3.5 # 7
b: sqrt(2) m # 1.4142135624 (meters)
c: pi/4 # 0.7853981634
d: 1.5e-3*2 fs # 3.0e-18 (seconds)
Available: + - * / ^ %, parentheses, the constants pi and e, and the
functions abs acos asin atan atan2 ceil cos cosh exp fac floor ln log log10
ncr npr pow sin sinh sqrt tan tanh and rand() (uniform in [0,1)).
rand() uses the seed --physics-rngseed (default 1812433253), so runs are
reproducible.
The internal unit system is set with --physics-units, or by the
unit_system operator for the operators that run after it. See
Units and physical quantities: the
difference matters.
Batches¶
A batch is a named sequence of operators. Define it at the top level, then use its name like any operator. Two forms exist:
# short form: a list
print_and_step:
- print_timestep
- next_time_step
# long form: a map with a 'body' and options
compute_loop:
loop: true
condition: compute_loop_continue
body:
- print_and_step
- compute_loop_stop
A batch defined as a plain name is an alias: init: nop makes init
run nop.
Batch options (long form):
| Option | Value | Effect |
|---|---|---|
body |
list | The operators to run, in order. Required in the long form. |
rebind |
map inner: outer |
Renames slots of the body. See Rebinding slots. |
condition |
slot name, or not <slot> |
Runs the body only if the boolean slot is true (or false with not). Checked before each run. See Conditions. |
loop |
true / false |
Runs the body again while condition is true. Without a condition, the loop never ends. See Loops. |
unroll |
integer | With loop: true: each pass of the loop runs N copies of the body, each one guarded by the condition. See Unrolling a loop. |
name |
string | Name shown in logs, graphs and profiles (default: the batch key). |
profiling |
true / false |
Forces profiling of this batch and of everything inside it on or off. See Profiling and naming. |
parallel |
true / false |
Runs the operators of the body at the same time, each on its own share of the OpenMP threads. Needs OpenMP nesting. See Running operators concurrently. |
cores |
list of numbers | With parallel: true: relative weight of each operator of the body when sharing the threads (default 1 each). |
task_group |
true / false |
Runs the body inside one OpenMP parallel region and task group, so that the tasks and asynchronous work created by its operators can overlap. Cannot be combined with parallel. See Task groups. |
Batch options can be changed from the command line like any other value, for
example --set-compute_loop-unroll 4 (see
Overriding values from the command line).
The examples below use only built-in operators (see
Built-in operators) and run with
onikarun <file>.msp. The outputs were obtained with Onika 1.0.4, without
the banner.
Conditions¶
condition names a boolean slot. The batch runs only if the slot is true;
with not <slot>, only if it is false. Here nth_timestep sets do_print
every 3 steps, and two batches use it in opposite ways:
global:
dt: 1.0
nsteps: 6
timestep: 0
compute_loop_continue: true
# do_print = true every 3 steps
check_print:
rebind: { result: do_print }
body: [ nth_timestep: { freq: 3 } ]
print_step:
condition: do_print
rebind: { value: timestep }
body: [ print_int: { prefix: "step ", suffix: " : printed\n" } ]
skip_step:
condition: not do_print
body: [ message: "skipped" ]
compute_loop_stop:
rebind: { end_at: nsteps, result: compute_loop_continue }
body: [ sim_continue ]
compute_loop:
loop: true
condition: compute_loop_continue
body: [ check_print, print_step, skip_step, next_time_step, compute_loop_stop ]
simulation: [ global, compute_loop ]
The condition slot must have a value when the batch is reached: give it a
default in global, or compute it earlier, as check_print does here.
Loops¶
With loop: true, the batch checks its condition, runs its body, then checks
the condition again, and so on: it behaves like a while loop. The body
must change the condition slot, otherwise the loop never ends. compute_loop
above is a typical loop: sim_continue sets compute_loop_continue to false
after nsteps steps.
Because the condition is checked before the first pass, a loop whose condition is false from the start never runs its body:
global:
go_on: false
never_runs:
loop: true
condition: go_on
body: [ message: "inside the loop" ]
simulation:
- global
- message: "before"
- never_runs
- message: "after"
Unrolling a loop¶
unroll: N (with loop: true and N > 1) replaces the body by N copies of it,
named <batch>$0 to <batch>$N-1. Each copy keeps the condition (and the
rebind) of the loop, so the loop still stops at the right step even if
that step is in the middle of a group of N:
global:
dt: 1.0
nsteps: 5
timestep: 0
compute_loop_continue: true
print_timestep:
rebind: { value: timestep }
body: [ print_int: { prefix: "step ", suffix: "\n" } ]
compute_loop_stop:
rebind: { end_at: nsteps, result: compute_loop_continue }
body: [ sim_continue ]
compute_loop:
loop: true
unroll: 4
condition: compute_loop_continue
body: [ print_timestep, next_time_step, compute_loop_stop ]
simulation: [ global, compute_loop ]
The printed output is the same with or without unroll (steps 0 to 5):
unrolling never changes the result or the order of the operators. What
changes is the graph. Run the file with --profiling-summary true (times in
ms, columns cut):
compute_loop .................................... 4.285e-02 ... 1
simulation.compute_loop$0 ..................... 2.104e-02 ... 2
print_int ................................... 5.828e-03 ... 2
next_time_step .............................. 1.311e-03 ... 2
sim_continue ................................ 1.020e-02 ... 2
simulation.compute_loop$1 ..................... 6.891e-03 ... 2
...
simulation.compute_loop$2 ..................... 6.548e-03 ... 1
...
simulation.compute_loop$3 ..................... 5.679e-03 ... 1
...
Without unroll, the body has one set of operators that runs 6 times. With
unroll: 4, it has 4 copies, compute_loop$0 to compute_loop$3, and the
last column (count) shows how the 6 steps were shared:
- 1st pass of the loop:
$0$1$2$3run steps 0 to 3; - 2nd pass:
$0and$1run steps 4 and 5. After step 5,compute_loop_continueis false, so$2and$3are skipped and the loop ends.
Hence the counts 2, 2, 1, 1. --debug-graph shows the same 4 copies. Each
copy has its own operators, so each one has its own entry in the profiles
and traces.
To compare the two versions without editing the file, use
--set-compute_loop-unroll 1.
Note
Unlike loop unrolling in a compiler, unroll does not make the loop
faster: the condition is still checked after each copy, and each operator
still waits for its own work to end. No application built on Onika uses
it at the moment.
Running operators concurrently: parallel and cores¶
By default the operators of a batch run one after the other, and each one
uses all the OpenMP threads. With parallel: true, all the operators of the
body start at the same time, each on a share of the threads, and the
batch ends when the last one ends.
cores gives the relative weight of each operator, in the order of the body
(1 for the missing ones). With 4 threads, cores: [3, 1] gives 3 threads to
the first operator and 1 to the second; [1, 1] gives 2 each. Each operator
gets at least one thread.
Enable OpenMP nesting
Each operator of the body runs in its own OpenMP thread, so its own
parallel loops are a nested parallel region. Set
omp_max_nesting to 2 or more (--omp_max_nesting 2, see
Configuration). Without it,
the operators still run at the same time, but each one on a single
thread.
configuration:
omp_num_threads: 4
omp_max_nesting: 2 # enables OpenMP nested parallelism
profiling:
summary: true
work_a:
- message: "work_a starts"
- parallel_for_benchmark: { samples: 65536, iterations: 4000 }
work_b:
- message: "work_b starts"
- parallel_for_benchmark: { samples: 65536, iterations: 4000 }
both:
parallel: true
cores: [ 3, 1 ] # work_a gets 3 of the 4 threads, work_b 1
body: [ work_a, work_b ]
simulation: [ both ]
parallel_for_benchmark comes from the onikaParallelTutorial plugin,
installed with Onika: it is a parallel_for that uses all the threads it is
given. The profiling summary (times in ms) shows that work_a ran 3 times
faster than work_b, and that both lasted as long as the slowest one:
Profiling ......................................... tot. time ( GPU ) avginb maxinb count percent
both .............................................. 6.335e+03 0.000 0.000 1 100.00%
work_a .......................................... 2.165e+03 0.000 0.000 1 34.18%
message
parallel_for_benchmark ........................ 2.165e+03 0.000 0.000 1 34.17%
work_b .......................................... 6.335e+03 0.000 0.000 1 100.00%
message
parallel_for_benchmark ........................ 6.335e+03 0.000 0.000 1 99.99%
The same file run in three ways (4 threads, times in seconds, on a laptop):
| Run | work_a |
work_b |
both |
|---|---|---|---|
onikarun concurrent.msp |
2.2 (3 threads) | 6.3 (1 thread) | 6.3 |
onikarun concurrent.msp --omp_max_nesting 1 |
6.2 (1 thread) | 6.2 (1 thread) | 6.2 |
onikarun concurrent.msp --set-both-parallel false |
1.6 (4 threads) | 1.6 (4 threads) | 3.2 |
Two operators that both scale well gain nothing from running concurrently
(last line). parallel is useful when the operators do not use all the
threads well on their own: an analysis next to the simulation, I/O,
communications, or GPU work driven by the CPU.
Rules to follow:
- The operators of the body must be independent: they must not write the
same slots, or a slot that another one reads. Give each one its own copy
of the data, with
rebindif needed. - Give each operator only the threads it needs: the others lose them for the whole batch.
- The batch waits for all its operators at the end. In a loop, the join happens at every pass.
- With MPI, the operators run at the same time on every process, so they may
call MPI at the same time: use a separate communicator for each one, and an
MPI library initialized with
MPI_THREAD_MULTIPLE(default, seempimt). - At most 63 operators, and no more operators than threads (Onika prints a warning otherwise).
Application: in-situ analysis in exaStamp
This input of exaStamp (an application built on Onika, so the operators
are not part of Onika) runs an analysis next to each time step. The
analysis reads a copy of the particles (copy_grid writes grid_copy)
and uses its own MPI communicator (mpi_dup), so the two branches share
no data:
init_prolog:
- mpi_dup # duplicate of the MPI communicator, as slot 'mpi_dup'
numerical_scheme:
name: scheme
body:
- copy_grid # snapshot of the particles, as slot 'grid_copy'
- concurrent_compute_insitu:
parallel: true
cores: [ 3 , 1 ]
body:
- simulation_compute:
- push_f_v_r: { dt_scale: 1.0 }
- push_f_v: { dt_scale: 0.5 }
- check_and_update_particles
- zero_force_energy
- compute_force
- force_to_accel
- push_f_v: { dt_scale: 0.5 }
- insitu_analytics:
rebind: { grid: grid_copy, mpi: mpi_dup }
body:
- histogram_energy: { samples: 50 }
- print_histogram: { message: "energy" }
Here every time step waits for the analysis. For an analysis that lasts longer than a step, put a whole block of steps in the first branch (an inner loop of, say, 100 steps) and start the analysis once per block: the join then happens only once per block.
Task groups¶
With task_group: true, the batch opens one OpenMP parallel region and runs
its body, on one thread, inside a taskgroup. Operators that create OpenMP
tasks or asynchronous parallel operations (see
Parallel API) then share the threads of this
region, and their work can overlap. The batch ends when all the tasks have
ended. The option is inherited by everything inside the batch, and it cannot
be used together with parallel: true (fatal error).
configuration:
omp_num_threads: 4
run_test:
task_group: true
body:
- concurrent_block_parallel: { rows: 4, columns: 4096, iter_count: 4096 }
- message: "task group done"
simulation: [ run_test ]
Enqueue parallel operations ...
schedule for execution ...
All operations have terminated !
task group done
concurrent_block_parallel (plugin onikaParallelTutorial) launches three
parallel operations, two of them concurrently. Operators that only use
parallel_for in the usual way gain nothing from a task group.
Profiling and naming¶
name changes the name of the batch in the logs, graphs and profiles.
profiling: false turns profiling off for the batch and all the operators
inside it (profiling: true turns it on even if they turned it off):
configuration:
profiling:
summary: true
hidden:
profiling: false
body:
- parallel_for_benchmark: { samples: 4096, iterations: 1000 }
- message: "hidden done"
shown:
name: my_benchmark
body:
- parallel_for_benchmark: { samples: 4096, iterations: 1000 }
- message: "shown done"
simulation: [ hidden, shown ]
Profiling ......................................... tot. time ( GPU ) avginb maxinb count percent
simulation ........................................ 3.488e+01 0.000 0.000 1 100.00%
hidden
parallel_for_benchmark
message
my_benchmark .................................... 1.777e+01 0.000 0.000 1 50.94%
parallel_for_benchmark ........................ 1.773e+01 0.000 0.000 1 50.84%
message ....................................... 1.413e-02 0.000 0.000 1 0.04%
A batch with a single operator, no loop and no condition is replaced by that
operator, so its name does not appear in the profile: add a second
operator to the batch if you need it.
How operators are connected¶
You never connect operators explicitly. Slots with the same name are
connected: an input slot reads the value of the last operator before it, in
execution order, that has an output slot with the same name. global
creates output slots from its values, so it is a common way to provide
parameters.
flowchart LR
g["global<br/>OUT dt, timestep"] -->|dt, timestep| n["next_time_step<br/>IN dt · IN/OUT timestep"]
n -->|timestep| p["print_int<br/>IN value ← timestep"]
Rebinding slots¶
Slot names are chosen by the operator author, so they rarely match.
rebind renames slots of a batch body, seen from outside the batch:
print_timestep:
rebind: { value: timestep } # inner slot 'value' is called 'timestep' outside
body:
- print_int: { prefix: "Current timestep = ", suffix: "\n" }
Here print_int reads timestep without knowing that name. Rebinding
applies to all operators of the body.
Unused operators are removed¶
After building the graph, Onika removes operators whose outputs are never read by a later operator. The log shows them as:
If an operator you expect to run disappears, check that its outputs are used,
or check with --debug-graph. Operators that only have side effects (print,
write files) have no outputs and are kept. Developers can also force this with
is_sink() (see Keeping an operator in the graph: is_sink()).
Includes and merging¶
Files are loaded in this order, each one merged on top of the previous ones:
main-config.msp, always first, even withincludes: [](see The default file:main-config.msp);- the files in
includes, recursively, each file only once; - your input file;
- command-line options (see Overriding values from the command line).
Merging rules:
- maps are merged key by key, the last file wins;
- lists and values are replaced;
- a key prefixed with
+appends to a list instead of replacing it.
includes: [ base.msp ]
+my_sequence: # appends to my_sequence from base.msp
- message: "second"
--debug-files prints the list of files actually loaded.
The default file: main-config.msp¶
Onika always loads data/config/main-config.msp first (found through
ONIKA_CONFIG_PATH). It defines a default simulation:
run: nop
init: nop
simulation:
- message: "<Onika banner>"
- mpi_comm_world
- init_cuda
- global
- unit_system: { verbose: true, unit_system: { length: meter, mass: kilogram, ... } }
- init
- run
- finalize_cuda
So you have two ways to write an input file:
- define
run(andinit) only: you keep MPI, GPU and unit system initialization, and add your own work; - define
simulation: you replace everything.
Applications built on Onika (exaNBody, exaStamp...) ship their own
main-config.msp with many predefined batches.
Overriding values from the command line¶
Any value can be changed at launch time with --set-<path> <value>, the
path being the YAML keys separated by -:
The same override can be written in the input file, under configuration:
Runtime options such as --omp_num_threads are described in the Configuration reference.