llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.21k stars 11.14k forks source link

[OMPT] Dispatch callback on single-threaded work sharing loops #96698

Open rpereira-dev opened 1 month ago

rpereira-dev commented 1 month ago

The issue

LLVM's OpenMP does not raises the ompt_callback_dispatch_t callback when running with a single thread in static mode

Standard

The standard 5.2 specifies

The ompt_callback_dispatch_t type is used for callbacks that are dispatched when a thread begins to execute a section or loop iteration.

Reproducer

int main(void)
{
    # pragma omp parallel for
    for (int i = 0 ; i < 128 ; ++i) {}

    return 0;
}

OMPT tool used

git clone https://github.com/rpereira-dev/ompt-dump.git

Compiled and run as

clang -Wall -Werror -Wextra -fopenmp main.c
OMP_NUM_THREADS=1 OMP_TOOL_LIBRARIES=path/to/libompt_dump.so ./a.out

Outputs

[OMPT] [INFO] ompt_callback_thread_begin
[OMPT] [INFO] ompt_callback_implicit_task
[OMPT] [INFO] ompt_callback_parallel_begin
[OMPT] [INFO] ompt_callback_implicit_task
[OMPT] [INFO] ompt_callback_work
[OMPT] [INFO] ompt_callback_work
[OMPT] [INFO] ompt_callback_sync_region
[OMPT] [INFO] ompt_callback_sync_region_wait
[OMPT] [INFO] ompt_callback_sync_region_wait
[OMPT] [INFO] ompt_callback_sync_region
[OMPT] [INFO] ompt_callback_implicit_task
[OMPT] [INFO] ompt_callback_parallel_end
[OMPT] [INFO] ompt_callback_implicit_task
[OMPT] [INFO] ompt_callback_thread_end

Remark

Any other schedule mode triggers the callback properly (even schedule(runtime) and OMP_SCHEDULE=static)

rpereira-dev commented 1 month ago

Just found other callbacks not raised when running in single-thread, which I believe should be

There is a few places in the LLVM runtime where there is some sort of serial elision (grep nth == 1 or nthreads == 1) which is probably where to start looking at

llvmbot commented 1 month ago

@llvm/issue-subscribers-openmp

Author: PEREIRA Romain (rpereira-dev)

### The issue LLVM's OpenMP does not raises the `ompt_callback_dispatch_t` callback when running with a single thread in `static` mode ### Standard The standard 5.2 specifies > The `ompt_callback_dispatch_t` type is used for callbacks that are dispatched when a thread begins to execute a section or loop iteration. ### Reproducer ```C int main(void) { # pragma omp parallel for for (int i = 0 ; i < 128 ; ++i) {} return 0; } ``` OMPT tool used ```bash git clone https://github.com/rpereira-dev/ompt-dump.git ``` Compiled and run as ``` clang -Wall -Werror -Wextra -fopenmp main.c OMP_NUM_THREADS=1 OMP_TOOL_LIBRARIES=path/to/libompt_dump.so ./a.out ``` Outputs ``` [OMPT] [INFO] ompt_callback_thread_begin [OMPT] [INFO] ompt_callback_implicit_task [OMPT] [INFO] ompt_callback_parallel_begin [OMPT] [INFO] ompt_callback_implicit_task [OMPT] [INFO] ompt_callback_work [OMPT] [INFO] ompt_callback_work [OMPT] [INFO] ompt_callback_sync_region [OMPT] [INFO] ompt_callback_sync_region_wait [OMPT] [INFO] ompt_callback_sync_region_wait [OMPT] [INFO] ompt_callback_sync_region [OMPT] [INFO] ompt_callback_implicit_task [OMPT] [INFO] ompt_callback_parallel_end [OMPT] [INFO] ompt_callback_implicit_task [OMPT] [INFO] ompt_callback_thread_end ``` ### Remark Any other schedule mode triggers the callback properly (even `schedule(runtime)` and `OMP_SCHEDULE=static`)