New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use memory in fmi3SetX / fmi3GetX functions #515

Open
t-sommer opened this Issue Dec 18, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@t-sommer
Copy link
Collaborator

t-sommer commented Dec 18, 2018

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!

@t-sommer t-sommer added the discussion label Dec 18, 2018

@t-sommer t-sommer added this to the FMI3.0 milestone Dec 18, 2018

@APillekeit

This comment has been minimized.

Copy link
Collaborator

APillekeit commented Jan 4, 2019

It is not completely clear how this is intended to work and how it will provide an improvement. Could you please provide an example in pseudo code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment