Skip to content

Latest commit

 

History

History
111 lines (87 loc) · 2.58 KB

mma.rst

File metadata and controls

111 lines (87 loc) · 2.58 KB

Mixed Martial Arts

Jonas Juselius <[email protected]>
HPC@UiT

Why

  • 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

How

  • 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

Fortran

  • Use iso_c_binding
  • Calling conventions:
    • Pass by value
    • bind(C)
    • c_ptr, c_loc, c_f_pointer
    • Column vs. row major matrices

Fortran calling C

C calling Fortran

C++

C++ cannot be directly linked due to name mangling.

Cython

Cython for speed

Cython calling C

Calling Cython from Python

Cython CMake

Haskell

  • FFI (Foreign Functions Interface):
    • Call C functions from Haskell
    • Export Haskell functions to C