Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jccampagne/gojulia
Julia embedding in Go
https://github.com/jccampagne/gojulia
cgo demo fun go golang goroutines julia julia-embedding learning-by-doing
Last synced: about 12 hours ago
JSON representation
Julia embedding in Go
- Host: GitHub
- URL: https://github.com/jccampagne/gojulia
- Owner: jccampagne
- Created: 2019-06-03T22:18:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-02T20:30:20.000Z (almost 5 years ago)
- Last Synced: 2023-03-30T09:19:53.449Z (almost 2 years ago)
- Topics: cgo, demo, fun, go, golang, goroutines, julia, julia-embedding, learning-by-doing
- Language: Go
- Size: 6.84 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# About
Simple examples showing how to embed Julia in Go.
# Requirements
Julia, Go, Make.
`go`, `julia` and `julia-config.jl` in your path.
You will probably have to add `julia-config.jl` to your PATH. Julia config tool on macOS, using Julia installed with [brew](https://brew.sh) is located here:
```
/Applications/Julia-1.2.app/Contents/Resources/julia/share/julia/julia-config.jl
```# Run the examples
This was tested on macOS, but should also work on Linux.
A makefile is provide for convenience, just type:
```
make
```This will compile the examples and run them (note: one of the example will fail on purpose).
# Description
There are 3 examples:
1. `gjl.go`: very simple example
1. `gjl_goroutines.go`: executing julia code from 2 different goroutines with synchronisation.
1. `gjl_goroutines_fail.go`: same as above example, but demonstrate failure when accessing julia from multiple goroutine without synchronization.# C binding
Julia is embedding in Go using cgo and a couple of C binding files: `gjl.h` and `gjl.c`.
These files provide function wrappers around [Julia C API](https://docs.julialang.org/en/v1/manual/embedding/index.html) that are defined C macros in Julia. Cgo cannot use C macros directly. For example [jl_typeof(v)](https://github.com/JuliaLang/julia/blob/d249e71ef2fd59acd557f2f6c9688253f4b5a47d/src/julia.h#L107) is a macro.# References
* [cgo](https://golang.org/cmd/cgo/)
* [Embedding Julia](https://docs.julialang.org/en/v1/manual/embedding/index.html)
* [julia.h](https://github.com/JuliaLang/julia/blob/master/src/julia.h)