Git Product home page Git Product logo

Comments (12)

ThummeTo avatar ThummeTo commented on June 28, 2024

This is currently not possible, because the Julia-C-Pipeline currently does not support variadic arguements. The only way to currently solve this, would be to redirect the variadic C function call to a DLL/LIB, replace the format placeholders inside and call a Julia-Function with the formatted string (no variadic arguments any more). As said, this would need us to ship a DLL/LIB with the library or build a DLL/LIB on the system that implements this single function.

Funny thing: In some eraly version we already tried this and it works fine, but the preferable solution would be to handle the variadic callback function with "native" Julia.

PS: The only tool I currently know that uses the variadic argument calling convention is OpenModelica, Dymoal and many others just deliver a ready to use formatted string.

So the options would be to deliver some C-library-code and (automated) compile it for the target machine and redirect the callback function (which is not a really clean solution) or wait for Julia to support variadic arguments in c-functions.

from fmi.jl.

AnHeuermann avatar AnHeuermann commented on June 28, 2024

If other tools would struggle with this I would just change it in OpenModelica. But the tools I tested (OMSimulator, FMPy) can handle it. Not sure how python does FMPy does this. Maybe Python can do this or they added a similar binary.

So the options would be to deliver some C-library-code and (automated) compile it for the target machine and redirect the callback function (which is not a really clean solution) or wait for Julia to support variadic arguments in c-functions.

The C-library would be the fastest option. Do you think you can add that library to FMI.jl until there is a pure Julia solution available?

from fmi.jl.

ThummeTo avatar ThummeTo commented on June 28, 2024

We still have the library and the old code, I just need to refactor it a bit. Would be nice if you could check (and maybe adapt) the DLL/LIB to compile on Linux as well as soon we are ready (we are working mainly on windows)? I think I will need about a week, because there are currently other things open, too.

from fmi.jl.

AnHeuermann avatar AnHeuermann commented on June 28, 2024

Sure, I can check it out on Linux.

I think the recommended way for C dependencies is to use BinaryBuilder.jl and Yggrasil. I never tried them myself, but instead added pre-build binaries to a Julia package. But then you have the trouble to compile the sources for all available systems.

from fmi.jl.

ThummeTo avatar ThummeTo commented on June 28, 2024

The more I think about it, the more I don't like the idea of checking in such a "hacky" solution. Further, we would build platform-dependent code around a library that is platform-independent, which seems not a good idea.

Because - if I understand you right - this issue isn't really urgent (there is the option to export the FMU with ready-formatted strings), I would suggest to wait for a language native fix (variadic c-functions), instead of deploying a (propably) unreliable workaround...

What do you think?

from fmi.jl.

AnHeuermann avatar AnHeuermann commented on June 28, 2024

The more I think about it, the more I don't like the idea of checking in such a "hacky" solution.

I'm not sure it is a "hacky" solution. Not everything works in Julia and you are dealing with C FMUs, so havon some C sources / binaries for FMI.jl sounds fine.

this issue isn't really urgent (there is the option to export the FMU with ready-formatted strings)
I don't know about an option for OpenModelica to have ready-formatted strings. I could add it, but the FMUs are according to the specification, so I don't think it makes that much sense to change OM FMUs.
But yes, not an urgent problem.

But how long would a language native fix be? Do you know any discussion about this? I couldn't find much about giving variadic Julia functions to a C function. Only the other way around.

from fmi.jl.

ThummeTo avatar ThummeTo commented on June 28, 2024

I just found an article, that this should be possible using CBindings.jl.
I will check this out ...

from fmi.jl.

ThummeTo avatar ThummeTo commented on June 28, 2024

This is fixed for Windows in FMI.jl 0.6.0. Until Julia supports variadic c-calls, you can use fmiInstantiate(....; externalCallbacks=true).

from fmi.jl.

ThummeTo avatar ThummeTo commented on June 28, 2024

To solve this the way it should be solved, it is needed to offer a variadic function for fmi2CallbackLogger, that formats the message like a call to sprintf (or printf). In native Julia, variadic c-functions are not supported by now (as far as I know). A possible option may be using CBindings.jl but I am not familiar with ...

EDIT: Added "help wanted"-badge

from fmi.jl.

AnHeuermann avatar AnHeuermann commented on June 28, 2024

I added binaries for Linux and Mac in ThummeTo/FMIImport.jl#40.

from fmi.jl.

ThummeTo avatar ThummeTo commented on June 28, 2024

Much appreciated! I will merge them soon together with some other changes.
Thanks!

from fmi.jl.

ThummeTo avatar ThummeTo commented on June 28, 2024

Closed by FMIImport v0.11.0 (FMI.jl 0.10.0) via PR#45

from fmi.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.