26.06.2015 Views

Parallel Programming in Fortran 95 using OpenMP - People

Parallel Programming in Fortran 95 using OpenMP - People

Parallel Programming in Fortran 95 using OpenMP - People

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

42 3. PRIVATE, SHARED & Co.<br />

In this case the thread that executes the lexically last SECTION updates the orig<strong>in</strong>al<br />

variable a, lead<strong>in</strong>g to a = 2.<br />

If the last iteration <strong>in</strong> the do-loop, or the lexically last SECTION, is not sett<strong>in</strong>g a value to<br />

the variable specified <strong>in</strong> the LASTPRIVATE clause, then the variable will have an undef<strong>in</strong>ed<br />

value after the scope of the directive-pair, like <strong>in</strong> the follow<strong>in</strong>g example:<br />

!$OMP SECTIONS LASTPRIVATE(a)<br />

!$OMP SECTION<br />

a = 1<br />

!$OMP SECTION<br />

a = 2<br />

!$OMP SECTION<br />

b = 3<br />

!$OMP END SECTIONS<br />

The process of updat<strong>in</strong>g the orig<strong>in</strong>al variable by the ”last” value assigned <strong>in</strong>side the<br />

scope of the directive-pair takes place at the synchronization between the different threads<br />

implied <strong>in</strong> the clos<strong>in</strong>g-directive. Therefore, if this implied synchronization is non-existent<br />

(because of the nature of the clos<strong>in</strong>g-directive or because it has been forced by a NOWAIT<br />

clause), then the value of the variable will be undef<strong>in</strong>ed until an implied or explicit synchronization<br />

is found. In this way it is ensured that the thread execut<strong>in</strong>g the sequentially<br />

last iteration has computed the f<strong>in</strong>al value of that variable.<br />

S<strong>in</strong>ce <strong>in</strong>formation is transferred from one memory location to another, to <strong>in</strong>clude<br />

a variable <strong>in</strong>side a LASTPRIVATE clause can be very time consum<strong>in</strong>g, if the size of the<br />

variable is large. In contrast to the previous FIRSTPRIVATE clause, <strong>in</strong> the present case<br />

only an amount of <strong>in</strong>formation equal to the size of the variable is moved, therefore not<br />

depend<strong>in</strong>g on the number of threads exist<strong>in</strong>g <strong>in</strong> the parallel region.<br />

3.1.6 COPYIN(list)<br />

When a variable has been declared as THREADPRIVATE, itsvalue<strong>in</strong>eachthreadcanbe<br />

set equal to the value <strong>in</strong> the master thread by us<strong>in</strong>g the present clause. The follow<strong>in</strong>g<br />

example shows its use:<br />

!$OMP THREADPRIVATE(a)<br />

!$OMP PARALLEL<br />

a = OMP_get_thread_num()<br />

!$OMP END PARALLEL<br />

!$OMP PARALLEL<br />

...<br />

!$OMP END PARALLEL<br />

!$OMP PARALLEL COPYIN(a)<br />

...<br />

!$OMP END PARALLEL

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

Saved successfully!

Ooh no, something went wrong!