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.
- Host: GitHub
- URL: https://github.com/ahbarnett/multilingual-julia
- Owner: ahbarnett
- Created: 2020-12-28T22:46:09.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-27T14:34:07.000Z (almost 3 years ago)
- Last Synced: 2023-02-27T09:32:39.981Z (over 2 years ago)
- Language: C
- Homepage:
- Size: 66.4 KB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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 multithreadingThey 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)