parallel-runtimes / lomp

Little OpenMP Library
Apache License 2.0
154 stars 18 forks source link

Add Fortran interfaces for OpenMP library functions #48

Open JimCownie opened 2 years ago

JimCownie commented 2 years ago

Is your feature request related to a problem? Please describe. The LOMP library does not, yet, have interfaces for Fortran code to call into the user-visible OpenMP library functions (such as integer omp_get_thread_num).

Describe the solution you'd like The runtime should provide the relevant functions/subroutines with the appropriate Fortran argument interfaces and mangled names (if you count "adding a trailing '_' to the name" as mangling...)

Describe alternatives you've considered Not supporting Fortran is possible, but undesirable, given that this is not a huge amount of work.

Additional context None.

mjklemm commented 2 years ago

I'll take this task. One of the main things will be to figure out how to best enable a Fortran compiler in build system.

JimCownie commented 2 years ago

For the simple enquiry functions which take no arguments, all that is needed is an entrypoint with the "mangled" name that then immediately calls the underlying function. That should convert into a single branch... For any function/subroutine which takes an argument, a shim implementation will be required to match up the Fortran and C calling conventions.

mjklemm commented 2 years ago

It depends on what we want. The easiest and safest would to use a F08 compiler and use the ISO_C_BINDINGS to simply write an INTERFACE definition for the LOMP API and invoke these function. If you want F77, then things will be a bit more complex, but still not hard.

JimCownie commented 2 years ago

If we want compatibility with the existing runtime libraries, we need to provide the same interface functions as they do, and not require recompilation of Fortran codes.

For GCC, at least, that includes functions with the trailing '_'

...
0000000000012470 T _omp_destroy_lock
0000000000012f50 T _omp_destroy_lock_
00000000000124d0 T _omp_destroy_nest_lock
0000000000012f80 T _omp_destroy_nest_lock_
0000000000022a40 T _omp_display_affinity
0000000000013440 T _omp_display_affinity_
...

(Ignore the leading '_', that's a MacOS feature for all external symbols (AFAICT)).

mjklemm commented 2 years ago

Sure. Let me have a look at this.