An open API service indexing awesome lists of open source software.

https://github.com/ahbarnett/multilingual-julia

Minimally complete examples of Julia calling, more importantly being called by, Fortran, C, and Python.
https://github.com/ahbarnett/multilingual-julia

Last synced: 6 months ago
JSON representation

Minimally complete examples of Julia calling, more importantly being called by, Fortran, C, and Python.

Awesome Lists containing this project

README

        

# multilingual-julia

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.

### Contents

`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.

### Requirements

Recent Julia installed, C complier, Fortran compiler, GNU `make`.

### Testing

1. `cp make.inc.example make.inc`

1. Edit `make.inc` for your Julia installation directory and choice of compilers

1. `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.

### To do

* 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)