Search code examples
gccopenmp

Is it possible to trace the OpenMP source code?


I would like to get a deep understanding of OpenMP and its internal mechanisms, its data structures, and algorithms at an operating system level (for example, I suppose that for task affinity each place has its own task queue and in the case of untied tasks there is a task migration / stealing between run queues). Is there a database of technical papers that describe all this stuff as well as a guide describing what files in the gcc source tree are of interest?

I search the gcc source tree for filenames containing the string omp and i found some results but i don't know if these are all the associated files.


Solution

  • I would like to get a deep understanding of OpenMP and its internal mechanisms, its data structures, and algorithms at an operating system level

    OpenMP is a standard, not an implementation. There are multiple implementations. Two are mainstream: GOMP associated with GCC and IOMP associated to Clang (and ICC).

    Is there a database of technical papers that describe all this stuff as well as a guide describing what files in the GCC source tree are of interest?

    AFAIK, not for GOMP. The code is the reference for this as well as the associated documentation (more specifically this page). The code is modified over time so document would quickly get obsolete (especially since there are versions of the OpenMP specification released relatively frequently causing sometime changes deep in the target implementation).

    Note that there are some generated documentation online like this one but it looks like it is really obsolete now.

    I search the gcc source tree for filenames containing the string omp and i found some results but i don't know if these are all the associated files.

    Generally, an OpenMP implementation is written in two parts. One part is in the compiler and it is meant to parse pragmas so to then convert them to runtime calls (eg. parallel sections), or to tune the compiler behaviour (eg. SIMD directives). This is a kind of front-end. Another part is the runtime which is the heat of the implementation, a kind of back-end, where the dynamic data structure lies (eg. for tasks, barrier, parallel sections, etc.). GOMP is implemented that way. That being said, the two parts are more closely interrelated than other implementations like IOMP (AFAIK, GOMP is not meant to be used from another compiler than GCC).

    The code is available here. "loop.c" is probably the first file to look to understand the implementation. GOMP is relatively simple overall.

    I suppose that for task affinity each place has its own task queue and in the case of untied tasks there is a task migration / stealing between run queues

    Task affinity is a new feature that is only supported recently (in GCC 12). I would not be surprised if it would be a no-op (this is not rare for new features). In fact, "affinity.c" tends to confirm this. As for the queues, the last time I looked the code, GOMP was using a central queue (that does not scale).