12.07.2015 Views

PGI Fortran - Servidor WWW del Cluster Ladon-Hidra

PGI Fortran - Servidor WWW del Cluster Ladon-Hidra

PGI Fortran - Servidor WWW del Cluster Ladon-Hidra

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

In the presence of an IF clause, the parallel region will be executed in parallel only if thecorresponding scalar_logical_expression evaluates to .TRUE.. Otherwise, the code within theregion will be executed by a single processor regardless of the value of the environment variableOMP_NUM_THREADS.8.3 CRITICAL ... END CRITICALThe OpenMP END CRITICAL directive uses the following syntax.!$OMP CRITICAL [(name)]< Fortran code executed in body of critical section >!$OMP END CRITICAL [(name)]Within a parallel region, you may have code that will not execute properly when multiple threadsact upon the same sub-region of code. This is often due to a shared variable that is written and thenread again.The CRITICAL...END CRITICAL directive pair defines a subsection of code within a parallelregion, referred to as a critical section, which will be executed one thread at a time. The optionalname argument identifies the critical section. The first thread to arrive at a critical section will bethe first to execute the code within the section. The second thread to arrive will not beginexecution of statements in the critical section until the first thread has exited the critical section.Likewise, each of the remaining threads will wait its turn to execute the statements in the criticalsection.Critical sections cannot be nested, and any such specifications are ignored. Branching into or outof a critical section is illegal. If a name argument appears on a CRITICAL directive, the samename must appear on the END CRITICAL directive.PROGRAM CRITICAL_USEREAL A(100,100), MX, LMXINTEGER I, JMX = -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)END DOEND DO!$OMP CRITICALOpenMP Directives for Fortran 291

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

Saved successfully!

Ooh no, something went wrong!