Using the runtime C interface


I am currently working on a research project with the goal to create a C++ abstraction for creating tasks similar to tasking in OpenMP but with added functionality and only relying on standard C++ language features. In order to allow for an easy integration with existing OpenMP applications, I would like to use an existing OpenMP runtime as a basis so that users can only port parts of their application while keeping most of the existing code. Eventually all created tasks will be scheduled by the same runtime.

The LLVM OpenMP runtime seems to be a good fit as it comes with a documented API [1] and supports multiple compilers. Thanks to the documentation and the library code, I think I have a good understanding of how to create tasks with depdendencies using __kmpc_omp_task_alloc() and __kmpc_omp_task_with_deps(). However, it is not clear to me how threads can be spawned correctly. I assume that __kmpc_fork_call() is the right place to look at but I fail to understand how a microtask should exactly behave, e.g., which functions to call while waiting for tasks to be created in another thread. Is there any publicly available example on how to use the API correctly without any OpenMP pragmas? Or is it possible to extract such an example from OpenMP code using the LLVM compiler?

Any pointers are much appreciated.




Best is to create a few examples and look at the llvm files being generated. The construct that generates the fork call is #pragma omp parallel. Here is the template:

EXTERN void __kmpc_fork_call(klegacy_Indent *loc, int32_t argc, klegacy_ParFctPtr microtask, …);

where the first is unused, the second is the number of parameters to the microtask, the function to be called, and the params.

Parameters are typically used to pass references and first private values. If you have no shared/private values in your model, you can ignore them.



Thanks for your swift reply. Which LLVM files are you refering to in particular? Ideally I would like to use something like clang -E to see how the OpenMP pragmas are resolved to particular library calls (unfortunately, pragmas are carried through this step). I am not too familiar with the LLVM tool-suite so I am not sure about any tools to dump intermediate presentations.

So far I have tried to use “clang -E” and “clang -ast-print” but all of them still contain the pragmas. Do you have any suggestions how to get a representation of the library calls that are generated?


Hi Joseph,
You can use ‘clang -c -S -emit-llvm -o -’ to see the real calls of OpenMP runtime functions

Best regards,
Alexey Bataev

yes, that is what I do too