Jonas Juselius <[email protected]> HPC@UiT
- There exists no perfect language for all tasks
- Languages have different stenghts:
- Python is excellent for driving computations and pre- and post-processing results
- Fortran is suitable for high-performance linear algebra and mathematical programming
- C++ supports advanced data structures, generic programming and more
- C is the mother tongue of UNIX
- Haskell is purely functional and lazy
- Coupling functionality from existing programs
- C is the common denominator
- Export needed functionality to C
- Often necessary to modularize the host code:
- init()
- step()
- finalize()
- + accessors
- Couple either directly or via Cython
- Use CMake to build and link
- Use iso_c_binding
- Calling conventions:
- Pass by value
- bind(C)
- c_ptr, c_loc, c_f_pointer
- Column vs. row major matrices
C++ cannot be directly linked due to name mangling.
- Compile Python to C!
- Speedup Pyhton
- Call external C/C++ functions directly
- Pass arrays via numpy
- Use CMake!
- https://github.com/bakerjonas/python-tutorials/tree/master/Cython
- FFI (Foreign Functions Interface):
- Call C functions from Haskell
- Export Haskell functions to C