HPlogo HP C/HP-UX Release Notes for HP-UX 11i: HP 9000 Computers > Chapter 1 New and Changed Features

OpenMP pragmas and options

» 

Technical documentation

Complete book in PDF

 » Table of Contents

A set of OpenMP pragmas have been added to this version of the HP C compiler for HP-UX. OpenMP is an industry-standard parallel programming model which implements a fork-join model of parallel execution. The HP C OpenMP pragmas included in this release are based upon the OpenMP Standard for C, version 1.0.

To view details about the standard and details about usage, syntax and values, please go to htpp://www.openmp.org/specs. You can download either a postscript (ps) or Adobe Acrobat (PDF) version of the C/C++ Version 1.0 OpenMP standard from this website

+Oopenmp command line option

The OpenMP driver option +Oopenmp is added to this release of the HP C compiler. When used with the +Oparallel option, +Oopenmp prompts the compiler to recognize the OpenMP pragmas and pragmas implemented with this release of the compiler.

NOTE: The +Oopenmp option is accepted at all optimization levels. However, most of the OpenMP pragmas and pragmas need a minimum optimization level of +O3. To ensure that OpenMP pragmas are recognized, you must specify +O3 on the command line.

When the +Oopenmp is used, most of the HP Programming Model (HPPM)pragmas are not accepted.The following HPPM pragmas, howevr, are accepted by the HP C compiler when +Oopenmp is issued.

  • BLOCK_LOOP

  • NO_BLOCK_LOOP

  • NO_DISTRIBUTE

  • NO_DYNSEL

  • NO_PARALLEL

  • NO_LOOP_DEPENDENCE

  • NO_LOOP_TRANSFORM

  • NO_UNROLL_AND_JAM

  • OPTIONS

  • SCALAR

  • UNROLL_AND_JAM

New header file

Every C program that contains OpenMP pragmas and is to be compiled for the current version of HP-UX must include the header file <omp.h>. If it does not, the OpenMP pragmas will be ignored. The default path for <omp.h> is /opt/ansic/include.

C pragmas for OpenMP

A set of OpenMP pragmas for HP C are introduced in this release of the compiler. These include work sharing pragmas and synchronization pragmas.

The following are the OpenMP work-sharing pragmas to be implemented for HP C.

  • PARALLEL

  • FOR

  • SECTIONS

  • SECTION

  • PARALLEL FOR

  • PARALLEL SECTIONS

The following are the OpenMP synchronization pragmas to be implemented for HP C.

  • CRITICAL

  • BARRIER

  • ORDERED

Each of the pragmas to be implemented are discussed in brief below .Only mapping of pragmas is covered here and not the complete functionality of a pragma.

OMP PARALLEL

The OMP_PARALLEL pragma defines a parallel region, which is a region of the program that is executed by multiple threads in parallel.This is the fundamental construct that starts parallel execution.

Syntax

#pragma OMP PARALLEL [clause1, clause2...] new-line structured block

where [clause1, clause2...] indicates that the clauses are optional. There can be zero (0) or more clauses, where clause may be one of the following:

  • PRIVATE (list)

  • DEFAULT (shared | none)

  • SHARED (list)

  • REDUCTION(operator :list)

  • LASTPRIVATE(list)

The following clauses are not currently supported in this initial release of the OMP PARALLEL pragma for HP C.

  • IF(scalar-expression)

  • FIRSTPRIVATE(list)

  • COPYIN(list)

OMP FOR

The OMP FOR pragma for HP C identifies a construct that specifies a region in which the iterations of the associated loop should be executed in parallel. The iterations of the loop are distributed across threads that already exist.

This initial release of OMP FOR in the HP C compiler only supports static scheduling. In the case of multiple schedule clauses, the first clause is considered and the rest are silently ignored.

Syntax

#pragma OMP FOR [clause1,clause2...] newline
for-loop

where [clause1, clause2...] indicates that the clauses are optional. There can be zero (0) or more clauses, where clause may be one of the following:

  • LASTPRIVATE (list)

  • REDUCTION (list)

  • ORDERED

  • SCHEDULE (kind [,chunksize])

NOTE: chunksize should be an integer constant. Expressions in the place of chunksize are not currently supported.

The following clauses are not currently supported in this initial release of the OMP FOR pragma for HP C.

  • NOWAIT

  • FIRSTPRIVATE

  • PRIVATE

OMP_SECTION/OMP_SECTIONS

The OMP SECTION/SECTIONS pragmas identify a construct that specifies a set of constructs to be divided among threads in a team. Each section is executed once by a thread in the team.

Syntax

#pragma OMP SECTIONS [clause1, clause2...]new-line
{
#pragma OMP SECTION new-line
structured-block

#pragma OMP SECTION new-line
structured-block

.
.
.
}

where [clause1, clause2...] indicates that the clauses are optional. There can be zero (0) or more clauses, where clause may be one of the following:

  • LASTPRIVATE

  • REDUCTION

The following clauses are not currently supported in this initial release of the OMP SECTION/SECTIONS pragmas for HP C.

  • PRIVATE

  • FIRSTPRIVATE

  • NOWAIT

OMP PARALLEL FOR

The OMP PARALLEL FOR pragma for HP C is a shortcut for an OMP PARALLEL region that contains a single OMP FOR pragma.

Syntax

#pragma OMP PARALLEL FOR clause1,clause2... new-line
for-loop

OMP PARALLEL FOR admits all the allowable clauses of the OMP PARALLEL pragma and the OMP FOR pragma. The PRIVATE clause is supported.

OMP PARALLEL SECTIONS

The OMP PARALLEL SECTIONS pragma for HP C is a shortcut for specifying a parallel region containing a single OMP SECTIONS pragma.

Syntax

#pragma OMP PARALLEL SECTIONS [clause1, clause2...]new-line
{
[#pragma OMP SECTION new-line
structured-block

[#pragma OMP SECTION new-line
structured-block

.
.
.
}

OMP PARALLEL SECTIONS admits all the allowable clauses of the OMP PARALLEL pragma and the OMP SECTIONS pragma. The PRIVATE clause is supported.

OMP PARALLEL CRITICAL

The OMP PARALLEL CRITICAL pragma identifies a construct that restricts the execution of the associated structured block to one thread at a time.

Syntax

#pragma OMP CRITICAL [(name)] new-line
structured-block

The critical section name parameter is optional. All unnamed critical sections globally map to a single name; this is provided by the HP C compiler.

OMP BARRIER

The OMP_BARRIER pragma synchronizes all the threads in a team. When encountered , each thread waits until all the threads in the team have reached that point.

Syntax

#pragma OMP BARRIER new-line

The smallest statement to contain a barrier must be a block or a compound statement. OMP BARRIER is valid only inside a parallel region and outside the scope of a OMP FOR, OMP SECTION/SECTIONS, OMP CRITICAL, OMP ORDERED, and OMP MASTER.

OMP ORDERED

The OMP ORDERED pragma indicates that the following structured block should be executed in the same order in which iterations would be executed in a sequential loop.

Syntax

#pragma OMP ORDERED new-line
structured-block

The OMP ORDERED pragmas must be called within theOMP FOR and/or OMP PARALLEL FOR loops.

OMP MASTER

The OMP MASTER pragma for HP C directs that the structured block following it should be executed by the master thread(thread 0) of the team.

Syntax

#pragma OMP MASTER new-line
structured block

Other threads in the team do not execute the associated statement.

© 2000 - Hewlett-Packard Development Company, L.P.