C project utility scripts in Julia

Dear all,

I was wondering if anyone has experience with the development of utility tools for a main code written in another language (e.g. C). Several activities around such code would require some kind of scripting (configuring, making, testing, input file generation and modification, output file analysis and visualisation…) which can be addressed with usual tools/languages (bash/make/cmake, perl, python, matlab).
Would anyone have some hints, dedicated packages, or examples of how such activities could be handled in Julia?

Cheers and thanks!

Your question is a bit vague :slight_smile:

But it’s quite simple to call other languages from Julia, through binary shared objects

ccall & PyCall for instance

https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/

I have some examples

C: GitHub - lawless-m/Czoo.jl: Examples of the use of ccall in Julia

Python: XlsxWriter.jl/XlsxWriter.jl at master · lawless-m/XlsxWriter.jl · GitHub

1 Like

thanks for the examples. Yes, my question was indeed not clear :smiley:
Together with some colleagues we are preparing a suite of tests for a C code. This involves automatically compiling the code and running different families of tests (compiling, going through valgrind, omp parallel scaling, running various tests with different input options and checking the results stored in the hdf5 outputs, create a pdf report with figures).
So far, I only have experience with computing using Julia and not much with I/O, scripting, interfacing. So I just wonder whether it would better to do these operations with Julia scripts rather than, say, python scripts.

As a language julia is super nice for scripting. Julia has super intuitive and powerful tools for scripting in the Base library. In practice I often use python however:

  • python is preinstalled on most linux machines
  • other programmers are often more familiar with python than julia
  • julia has slower startup time than python

There is no reason why you couldn’t use Julia.
In my Czoo runtests.jl I make sure the C code is up to date with the simple

cd("../src"); read(`make`); cd("..")

obviously that does no error checking but that’s only me being lazy

You can control stdin, stdout and stderr of such things.

I’m biased in the “better” part. But I can imagine running the tests in parallel, either via Threads or even on different machines using Distributed.

It would make a good project for learning Julia without taking too much time away from your actual goal of improving the C.

And you can always call Python from Julia if you feel like it and use both!

It’s far more flexible to test (and use) the code if you compile your C code as a library, not as a standalone program. Then you can test and call individual functions interactively, and communications is way easier than doing I/O through files and command-line options.

Indeed that’s likely the best option (especially for unit testing). I was just refrained to do it as I thought making a library would render debugging symbols unusable. But yes, in the end that’s likely what we’ll end up doing.
I was wondering whether there would be a more “2020 way” of doing such things but in the end we use a C code so we may better stick to classical tooling (a lighter Julia version of the code has been initiated it but it’s far from being ready).