10.07.2015 Views

PGI Fortran Reference manual - The Portland Group

PGI Fortran Reference manual - The Portland Group

PGI Fortran Reference manual - The Portland Group

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

OpenMP Directives for <strong>Fortran</strong><strong>The</strong> CRITICAL... END CRITICAL directive pair defines a subsection of code within a parallelregion, referred to as a critical section, which is executed one thread at a time.<strong>The</strong> first thread to arrive at a critical section is the first to execute the code within the section. <strong>The</strong>second thread to arrive does not begin execution of statements in the critical section until the firstthread exits the critical section. Likewise, each of the remaining threads wait its turn to executethe statements in the critical section.You can use the optional name argument to identify the critical region. Names that identifycritical regions have external linkage and are in a name space separate from the name spaces usedby labels, tags, members, and ordinary identifiers. If a name argument appears on a CRITICALdirective, the same name must appear on the END CRITICAL directive.Critical sections cannot be nested, and any such specifications are ignored. Branching into or out of acritical section is illegal.Example of Critical...End Critical directivePROGRAM CRITICAL_USEREAL A(100,100),MX, LMXINTEGER I, J MX = -1.0LMX = -1.0CALL RANDOM_SEED()CALL RANDOM_NUMBER(A)!$OMP PARALLEL PRIVATE(I), FIRSTPRIVATE(LMX)!$OMP DODO J=1,100DO I=1,100LMX = MAX(A(I,J),LMX)ENDDO ENDDO!$OMP CRITICALMX = MAX(MX,LMX)!$OMP END CRITICAL!$OMP END PARALLELPRINT *,"MAX VALUE OF A IS ", MXENDThis program could also be implemented without the critical region by declaring MX as areduction variable and performing the MAX calculation in the loop using MX directly rather thanusing LMX. Refer to PARALLEL...END PARALLEL and DO...END DO for more informationon how to use the REDUCTION clause on a parallel DO loop.8.7.4. C\$DOACROSS<strong>The</strong> C$DOACROSS directive, while not part of the OpenMP standard, is supported forcompatibility with programs parallelized using legacy SGI-style directives.SyntaxC$DOACROSS [ Clauses ]< <strong>Fortran</strong> DO loop to be executed in parallel ><strong>PGI</strong> <strong>Fortran</strong> <strong>Reference</strong> Guide 166

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!