Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

External C functions as annotations

External C functions as annotations

Hi,

To speed op my calculations I implemented an external function to solve sparse matrices [Ax=b stuff, with A sparse] (using CSpares of Tim Davis). The syntax I used is quite straigthforward.

function FunctionName
input a;
input b;
...

output result;

external "C";
  annotation(Include="#include <HeaderFile.h>", Library={"LibraryFile"});

end FunctionName;

The function does what it has to do. At least for small matrices (lets say size(b)=400 and A = 400x400 but square) . When I increase the matrix size (within the C-code: size(b)=40000 and A = 40000x40000) OpenModelica takes a tremendous long time to compile the code. (I tried for 2 hours, but even after this time OpenModelica had not finished yet)
This is very strange, because when I compile the c-function with gcc to an .exe-file it only needs a few seconds to give me the solution (of the case where size(b)=40000 and A = 40000x40000). Has anyone any idea why OpenModelica needs so much time? Is it because it has to process the solution-vector x?

Kind regards
Ruben G

Ps. To test this I used a model which only uses this function. So basically OpenModelica only needs to call this function, give it a few doubles (to specify the matrix size) as an input (the matrices are build inside the c-function) and receive the solution vector x (from Ax=b) as an output.

Edited by: Ruben - Jul-15-11 18:15:12

Re: External C functions as annotations

Yes, the OpenModelica backend does really odd things for some of these equations. It seems to scale O(n^3.5), which means very rapid degradation is quality.  https://openmodelica.org:8443/cb/issue/ … ation=true has an example I submitted some time ago current/sad

Re: External C functions as annotations

This might be also due to constant evaluation (function with constant input are evaluated at compile time, either via interpretation or via dll loading).
You might get better results if you use:
omc +d=nogen,noevalfunc script.mos
which will turn of function evaluation at compile time.

Cheers,
Adrian Pop/

Re: External C functions as annotations

I am afraid that there's still something wrong.  Why is OpenModelica not treating the external functions as a black box? The only thing I do is passing on a few real numbers to a C-function, which makes and solves a sparse matrix. OpenModelica only has to give the real numbers and receive the solution vector.

The options nogen and noevalfun doesn't seem to reduce the compile time of the code.

Best Regards
Ruben

There are 0 guests and 0 other users also viewing this topic
You are here: