0% found this document useful (0 votes)
13K views1 page

Effective Use of Reduction:: Department CSE, SCAD CET

The document discusses using reduction clauses in OpenMP to calculate a sum across threads instead of explicit synchronization. It notes that giving a reduction clause to a variable: 1) Creates a private copy for each thread that is initialized and combined at the end to update the original 2) Keeps the value of the original variable undefined until reduction is complete 3) Has an unspecified order of combining values between threads so results may differ between runs

Uploaded by

bsgindia82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13K views1 page

Effective Use of Reduction:: Department CSE, SCAD CET

The document discusses using reduction clauses in OpenMP to calculate a sum across threads instead of explicit synchronization. It notes that giving a reduction clause to a variable: 1) Creates a private copy for each thread that is initialized and combined at the end to update the original 2) Keeps the value of the original variable undefined until reduction is complete 3) Has an unspecified order of combining values between threads so results may differ between runs

Uploaded by

bsgindia82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Effective use of Reduction: Loops that reduce a collection of values to a single value are fairly common.

Consider the following simple loop that calculates the sum of the return value of the integer-type function call func(k) with the loop index value as input data.
sum = 0; for ( k = 0; k < 100; k++ ){ sum = sum + func(k); // func has no side-effects}

Instead of Providing Synchronisation use Reduction:


sum = 0; #pragma omp parallel for reduction(+ sum) for (k = 0; k < 100; k++) { sum = sum + func(k); !

Given the reduction clause, the compiler creates private copies of the variable sum for each thread, and when the loop completes, it adds the values together and places the result in the original variable. For each variable specified in a reduction clause, a private copy is created, one for each thread, as if the pri"ate clause is used. he private copy is then initiali!ed to the initiali!ation value for the operator."t the end of the region or the loop for which the reduction clause was specified, the original reduction variable is updated by combining its original value with the final value from each thread.

#hile identifying the opportunities to explore the use of the reduction clause for threading, you should $eep the following three points in mind.
he value of the original reduction variable becomes undefined when the first thread reaches the region or loop that specifies the reduction clause and remains so until the reduction computation is completed. %f the reduction clause is used on a loop to which the no#ait is also applied, the value of original reduction variable remains undefined until a barrier synchroni!ation is performed to ensure that all threads have completed the reduction. he order in which the values are combined is unspecified. herefore, comparing se&uential and parallel runs, even between two parallel runs, does not guarantee that bit-identical results will be obtained or that side effects, such as floating-point exceptions,will be identical.

Department CSE, SCAD CET

You might also like