Minimally complete examples of interfacing between Julia and various languages, including the uncommon and undocumented case of Fortran calling Julia. Interoperability between languages is essential if Julia is to integrate with scientific codebases in Fortran, C, and Python. One cannot always assume that Julia will be the top-level/driver environment. Libraries written in Julia should be able to be called by Fortran/C/Py users. This motivates this simple set of tutorial examples. Please help by expanding it.
The focus is:
- calling user-written Julia functions from C/Fortran
- passing arrays (their allocation being on the C/Fortran side)
- using multithreading
They are tested in a linux environment only (Ubuntu 21.04, GCC10, Julia 1.7.1).
Thanks to: Julia docs, StackOverflow, Julia Discourse, especially to Steven G Johnson.
jcallf
: Julia calls Fortran (ie, wrapping low-level language functions)
ccallj
: C calls Julia ("embedding")
fcallj
: Fortran calls Julia ("embedding", but needs intermediate C layer)
pcallj
: Python calls Julia (needs various Py and Jl packages, see makefile)
Each directory has its own makefile, which read any common settings placed in the top-level file make.inc
(thus, you will need to copy make.inc.example
to this file). Some demos explore multithreading in the "inner" (called) function. Some also report timings (which adds a few lines of code beyond the "minimal").
There are notes and resource links in each directory.
Recent Julia installed, C complier, Fortran compiler, GNU make
.
-
cp make.inc.example make.inc
-
Edit
make.inc
for your Julia installation directory and choice of compilers -
make
This goes to each directory and makes/runs all examples. Total wall-clock time is around 30 seconds, a lot due to Julia first-run times.
-
J calling F with non-void return type, eg
ddot
LAPACK in manual 27.5 -
J calling C, eg w/ SIMD (manual has it); 27.14 thread safety I don't get
-
understand garbage collection in the C calling J case (Manual 30.5)
-
passing function handles in either direction (probably hard)