Skip to content

Direct memory access in fmi3SetX / fmi3GetX functions #515

@t-sommer

Description

@t-sommer

Currently all requested values are copied twice for every call of fmi3GetX / fmi3SetX which is inefficient in terms of bandwidth and memory usage. This can be avoided by re-using the memory for subsequent calls of the getters and setters.
A possible implementation is outlined below. (It is the result of a discussion with @pmai)

Instantiation

The FMU allocates the memory for all variables during fmi3Instantiate using the callbacks provided by the environment.
For FMUs that don't support variable array sizes this memory may be static. The FMU may even use this memory directly for it's calculations.
The Memory layout is defined by the model description: it is the same as for a get / set call where all variables of a respective type are set / retrieved in the same order as they appear in the model description.

Get variables

fmi3Status fmi3GetX(const fmi3ValueReference vr[], size_t nvr, fmi3X* values[], size_t *nValues);
  • vr: all variables the caller is interested in (NULL = all)
  • nvr: size of vr
  • values: the memory that contains the variables
  • nValues: size of values

Set variables

fmi3Status fmi3SetX(const fmi3ValueReference vr[], size_t nvr, fmi3X values[], size_t nValues);
  • vr: all variables that have changed since the last call to fmi3SetX (NULL = all)
  • nvr: size of vr
  • values: memory retrieved from fmi3GetX
  • nValues: size of values

The value references are provided to allow optimizations if only a small number of variables are set / retrieved.

Structural changes

The FMU re-allocates the memory using the callbacks provided by the environment. The memory layout changes according to the structural parameters.

Termination

In fmi3Terminate() the FMU frees the memory using fmi3Free()

Comments welcome!

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions