Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can C++ attributes be used to replace OpenMP pragmas?

Tags:

c++

openmp

C++ attributes provide a convenient and standardized way to markup code with extra information to give to the compiler and/or other tools.

Using OpenMP involves adding a lot of #pragma omp... lines into the source (such as to mark a loop for parallel processing). These #pragma lines seem to be excellent candidates for a facility such as generalized attributes.

For example, #pragma omp parallel for might become [[omp::parallel(for)]].

The often inaccurate cppreference.com uses such an attribute as an example here, which confirms it has at least been considered (by someone).

Is there a mapping of OpenMP pragmas to C++ attributes currently available and supported by any/all of the major compilers? If not, are there any plans underway to create one?

like image 458
marack Avatar asked May 03 '16 23:05

marack


People also ask

What does #pragma OMP parallel do?

#pragma omp parallel spawns a group of threads, while #pragma omp for divides loop iterations between the spawned threads. You can do both things at once with the fused #pragma omp parallel for directive.

What is the use of pragma OMP?

The pragma omp parallel is used to fork additional threads to carry out the work enclosed in the construct in parallel. The original thread will be denoted as master thread with thread ID 0. Example (C program): Display "Hello, world." using multiple threads.

What is a critical compiler directive in OpenMP?

The omp critical directive identifies a section of code that must be executed by a single thread at a time.

What is OMP H?

The OpenMP functions are included in a header file called omp. h . OpenMP program structure: An OpenMP program has sections that are sequential and sections that are parallel. In general an OpenMP program starts with a sequential section in which it sets up the environment, initializes the variables, and so on.


1 Answers

This is definitely a possibility and it's even something the OpenMP language committee is looking at. Take a look at OpenMP Technical Report 8 (https://www.openmp.org/wp-content/uploads/openmp-TR8.pdf) page 36, where a syntax for using OpenMP via attributes is proposed. Inclusion in TR8 doesn't guarantee its inclusion in version 5.1, but it shows that it's being discussed. This syntax is largely based on the work done in the original proposal for C++ attributes.

If you have specific feedback on this, I'd encourage you to provide feedback on this via the OpenMP forum (http://forum.openmp.org/forum/viewforum.php?f=26).

like image 142
jefflarkin Avatar answered Oct 09 '22 04:10

jefflarkin