Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
651 views

Data Copy in Copy Out

The document discusses data copy-in and copy-out operations when parallelizing a program with OpenMP. It introduces the firstprivate, lastprivate, copyin, and copyprivate clauses that allow copying data between threads. It provides an example of converting a color image to black and white in parallel using firstprivate to initialize private variables for each thread.

Uploaded by

bsgindia82
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
651 views

Data Copy in Copy Out

The document discusses data copy-in and copy-out operations when parallelizing a program with OpenMP. It introduces the firstprivate, lastprivate, copyin, and copyprivate clauses that allow copying data between threads. It provides an example of converting a color image to black and white in parallel using firstprivate to initialize private variables for each thread.

Uploaded by

bsgindia82
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Data Copy-in & Copy-out: When you parallelize a program, you would normally have to deal with how

w to copy in the initial value of a private variable to initialize its private copy for each thread in the team.We would also copy out the value of the private variable computed in the last iteration/section to its original variable for the master thread at the end of parallel region.
OpenMP standard provides four clauses

firstprivate lastprivate copyin and copyprivate

For you to accomplish the data copy in and copy out operations whenever necessary based on your program and parallelization scheme.

!he semantics of the "cheme is described below,


Firstprivate:provides a way to initialize the value of a private variable for each thread with the value of variable from the master thread. #ormally, temporary private variables have an undefined initial value saving the performance overhead of the copy. lastprivate provides a way to copy out the value of the private variable computed in the last iteration/section to the copy of the variable in the master thread. $ariables can be declared both firstprivate and lastprivate at the same time. copyin provides a way to copy the master thread%s threadprivate variable to the threadprivate variable of each other member of the team e&ecuting the parallel region. copyprivate provides a way to use a private variable to broadcast a value from one member of threads to other members of the team e&ecuting the parallel region. !he copyprivate clause is allowed to associate with the single construct' the broadcast action is completed before any of threads in the team left the barrier at the end of construct.

code converts a color image to black and white.


for ( row = 0; row < height; row++ ) { for ( col = 0; col < width; col++ ) { pGray[col] = (B !") ( p#GB[row]$red % 0$&'' + p#GB[row]$green % 0$()* + p#GB[row]$+l,e % 0$--. ); / pGray += Gray0tride; p#GB += #GB0tride;

!he address computation for each pi&el can be done with the following code( p)est*oc + p,ray - col - row . ,ray"tride' p"rc*oc + p/,0 - col - row . /,0"tride' Improved Version:
1prag2a o2p parallel for private (row3 col) 4 firstprivate(do5nit3 pGray3 p#GB) for ( row = 0; row < height; row++ ) { 66 7eed this init test to +e a+le to start at an 66 ar+itrary point within the i2age after threading$ if (do5nit == !#8") { do5nit = 9:;0"; p#GB += ( row % #GB0tride ); pGray += ( row % Gray0tride ); / for ( col =0; col <width; col++ ) { pGray[col] = (B !") ( p#GB[row]$red % 0$&'' + p#GB[row]$green % 0$()* + p#GB[row]$+l,e % 0$--. ); / pGray += Gray0tride; p#GB += #GB0tride; /

You might also like