|
ADS
Algorithms and Data Structures
|
The executor [see Executor.h] on the threads of OpenMP, beyond the book, compiled only when the compiler has OpenMP on (_OPENMP, e.g., -fopenmp, or the CMake option ADS_WITH_OPENMP, OFF by default): bulk( n , f ) is, outside a parallel region, a loop #pragma omp parallel for on \( n \) indices with the dynamic schedule of chunks of 1 on \( \min\{ p , n \} \) threads, and invoke( f , g ) is bulk() on 2 indices, so that the parallel algorithms of ADS run on the runtime of OpenMP of the compiler (the libgomp of GCC, the libomp of LLVM) unchanged. More...
#include "ADS/Contract.h"#include "ADS/parallel/Executor.h"#include <omp.h>#include <algorithm>#include <atomic>#include <cstddef>#include <stdexcept>Go to the source code of this file.
Classes | |
| class | ADS::OpenMPLock |
| the lock of OpenMP, omp_lock_t, as a mutex of the standard More... | |
| class | ADS::OpenMPExecutor |
| the executor on the threads of OpenMP More... | |
Namespaces | |
| namespace | ADS |
The executor [see Executor.h] on the threads of OpenMP, beyond the book, compiled only when the compiler has OpenMP on (_OPENMP, e.g., -fopenmp, or the CMake option ADS_WITH_OPENMP, OFF by default): bulk( n , f ) is, outside a parallel region, a loop #pragma omp parallel for on \( n \) indices with the dynamic schedule of chunks of 1 on \( \min\{ p , n \} \) threads, and invoke( f , g ) is bulk() on 2 indices, so that the parallel algorithms of ADS run on the runtime of OpenMP of the compiler (the libgomp of GCC, the libomp of LLVM) unchanged.
The thread that calls is one of the \( p \), as in every region of OpenMP. Inside a parallel region that is already open (omp_in_parallel(): a region of the program around the call of an algorithm of ADS, or a call of bulk() nested in another), bulk() is instead a #pragma omp taskloop of chunks of 1, whose calls are tasks of the team that is there, and which waits for them at its implicit taskgroup, a point where the waiting thread runs tasks too; a nested region would get one thread (the default of OpenMP), so that the algorithm would run in order on the caller. In this mode the threads are those of the team, and concurrency() of an executor built with \( p = 0 \) is their number; the calls may be made by any thread of the team that joins the wait, e.g., from inside omp single or omp masked, or from each thread on data of its own. The task mode needs taskloop, i.e., OpenMP 4.5 (not the OpenMP 2.0 of MSVC, which keeps the nested regions). run( p , f ) is a region omp parallel of \( p \) threads, the thread \( i \) of the team making the call \( f( i ) \) of a long-lived worker (the caller is the thread 0, so that isRunCaller() holds in \( f( 0 ) \)), and its lock is the lock of OpenMP (omp_lock_t, OpenMPLock); a runtime that gives the region fewer threads (a run nested in a region, or a limit of the threads) makes no call and throws, since the workers could not all run at the same time.
The contracts [see Contract.h]: \( p \ge 1 \); an exception thrown by \( f \) stops the claims and is thrown again by bulk() (an exception may not leave a region of OpenMP).