OpenMP - the difference between directives and constructs

This may seem like a silly question, but I'm learning OpenMP and I'm a bit confused by the terminology. Are directives and create the same thing? Or is it a comprehensive, prescriptive word that includes constructs as well as orphan directives?

I saw words like PARALLEL Directive , but also PARALLEL Region Construct AND, in some manuals, Work Sharing Constructs are listed in OpenMP Directives .

the Microsoft page makes me think that potentially the entire following line is a directive:

  #pragma omp directive-name [clause[ [,] clause]...] new-line 

Because of the statement " Every directive starts with C # pragma omp ." And that will mean that the words parallel and for (and others) are constructs. However, at the same time, in the same line above, they put a directive-name immediately after the pragma.

If someone can clarify, that would be great: D

+4
source share
2 answers

If I read it correctly, the directive is an OpenMP statement, for example

 #pragma omp for 

or

 #pragma omp parallel private(th_id) shared(nthreads) 

A directive may include sentences , for example, the private statement above or schedule(dynamic, CHUNKSIZE) .

Directives combined with code form a construct . That is, the design is a template for achieving something. Thus, the "parallel construction" is a parallel directive, its optional sentences and any executable code:

 #pragma omp parallel printf("Hello, world.\n"); 

A "workharing construct" is a parallel for directive followed by a loop code:

 #pragma omp parallel for for (i = 0; i < N; i++) a[i] = 2 * i; 
+1
source

There is no shame in reading the OpenMP specification . ยง1.2.2 is entirely devoted to OpenMP terminology. You can find various definitions in it, including:

directive . In C / C ++, #pragma and Fortran is a comment that defines the behavior of an OpenMP program. COMMENT: see Section 2.1 on page 22 for a description of the syntax of the OpenMP directive.

Section 2.1 on page 22 reads:

OpenMP directives for C / C ++ are set using the pragma preprocessing directive. The syntax of the OpenMP directive is formally defined by grammar in Appendix C and unofficially as follows:

#pragma omp directory name [sentence [[,] sentence] ...] new line

Each directive begins with #pragma omp . The rest of the directive complies with C and C ++ standards conventions for compiler directives. In particular, a space can be used before and after # , and sometimes a space must be used to separate words in a directive. Preprocessing tags following #pragma omp are subject to macro replacement.

Directives are case sensitive.

The OpenMP executable directive applies to no more than one of the following statements, which should be a structured block.

Another convenient definition:

executable directive . OpenMP directive, which is not declarative. That is, it can be placed in an executable context. COMMENT: All directives, except the threadprivate directive, are executable directives.

Then comes the construction, explained in terms of the previous two:

construct is the OpenMP directive (and for Fortran, the pair end directive, if any) and the associated statement, loop or structured block, if any, and not including code in any routines. That is, in the lexical degree of the executable directive.

Microsoft pages simply reference parts of the (much) earlier OpenMP specification.

+3
source

Source: https://habr.com/ru/post/1468798/


All Articles