Impact of calling external C function on CPU time in OpenModelica

Viewed 102

we have implemented an external delay function in C and we want to recall it in our Modelica model (transmission line). our goal is to accelerate the CPU time. unfortunately, it increased the CPU time.
My questions are:

  1. Does calling the external function principally increase the simulation time in Modelica compared to the existing built-in delay?

  2. Does use an external object in OpenModelica significantly increase the simulation time?

  3. How to compile only our external function with Open MP (how we can add -fopenmp flag only for external function)? The following error (see the bekow Fig) was created when we did not use the above flag (as shown below figure), but using the flag from the beginning of compilation, made the simulation time longer while we have expected a shorter simulation time. PS: our function is compiled as a library in which we have included the -fopenmp flag. enter image description here enter image description here

1 Answers
  1. Does calling the external function principally increase the simulation time in Modelica compared to the existing built-in delay?

No. It's a very simple call and you are only allowed to use external function calls at well defined points in time in Modelica. You could have a problem if you introduce algebraic loops however.

  1. Does use an external object in OpenModelica significantly increase the simulation time?

No. It's only a pointer. If something is slow, it is within the external object itself or how it is used.

  1. How to compile only our external function with Open MP (how we can add -fopenmp flag only for external function): when linking source files? the following error was created when we did not use the above flag, but using the flag from the beginning of compilation, made the simulation time longer while we have expected a shorter simulation time. PS: our function is compiled as a library in which we have included the -fopenmp flag.

You compile the library ahead of time and add the -fopenmp flag to linker flags or in the Library annotation of the external function. Does the code run slower when using only 1 thread in OpenMP? Writing fast parallel code is hard and OpenMP hides a lot of the details, so it is hard to know why it runs slower.

Related