30.html
来自「国外MPI教材」· HTML 代码 · 共 53 行
HTML
53 行
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <style type="text/css"> body { font-family: Verdana, Arial, Helvetica, sans-serif;} a.at-term { font-style: italic; } </style> <title>Reduction Operations</title> <meta name="Generator" content="ATutor"> <meta name="Keywords" content=""></head><body> <p>A <em><a href="../glossary.html#reduction+operation" target="body" class="at-term">reduction operation</a></em> is a global calculation or comparison, involving data (e.g., partial sums) from several different threads. The reduction clause allows you to automatically perform such operations in a safe way. </p>
<p>Basic syntax: </p>
<pre><code>reduction(operator|intrinsic:var1[, var2...])</code></pre>
<p>The operator or intrinsic indicates the operation or comparison to be performed. The listed variables indicate the data on which the operations act. Each thread gets a private copy of each listed variable, which is initialized in a standard way depending on the operation or intrinsic specified. For example, for a sum
the local copies are initialized to zero. </p>
<p>Example: </p>
<pre><code>c$omp do shared(x) private(i)
c$omp& <em>reduction(+:sum)</em>
do i = 1, N
sum = sum + x(i)
end do</code></pre>
<p> In this example, each thread automatically gets a private copy of the variable <var>sum</var>, initialized to zero. The threads compute the partial sums corresponding to their share of the loop iterations. Finally, the partial sums are combined from each thread to obtain the global sum. </p>
<p>Global minimum example: </p>
<pre><code>c$omp do shared(x) private(i)
c$omp& <em>reduction(min:globalmin)</em>
do i = 1, N
globalmin = min(globalmin, x(i))
end do</code></pre>
<p>In this example, the local minima computed by individual threads are compared to form the global minimum. Note that the variables listed in the reduction
clause must be shared in the enclosing parallel context.</p>
<p>In Fortran, allowed operators are <code>+, *, -, .AND., .OR., .EQV., .NEQV.</code>
Allowed intrinsics are <code>MAX, MIN, IAND, IOR, IEOR.</code>
<p>
<p>In C/C++, allowed operators are <code>+, *, -, &, ^, |, &&, ||. </code> </p>
<p>Pointers and reference variables are not allowed in reductions. </p></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?