📄 37.html
字号:
<!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>The Master Region</title> <meta name="Generator" content="ATutor"> <meta name="Keywords" content=""></head><body> <p>The <em>master directive</em> designates a section of code (a structured block) that is executed <em>only</em> by the master thread, i.e., thread 0. This section of code is called the<b> master region</b>.</p>
<p class="codelang">Fortran syntax</p>
<pre><code>!$omp master
<em>structured block</em>
!$omp end master</code></pre>
<p class="codelang">C/C++ syntax</p>
<code><pre>#pragma omp master
<em>structured block</em></pre></code>
<p>Other threads simply skip over the master region and proceed to the subsequent code; there is no implicit barrier or other synchronization. The following example
illustrates the use of the master directive: </p>
<pre><code>!$omp parallel shared(c,scale) &
!$omp private(j,myid)
myid=omp_get_thread_num()
!$omp master
print *, 'T:', myid, ' enter scale'
read *,scale
!$omp end master
!$omp barrier
!$omp do
do j = 1, N
c(j) = scale * c(j)
enddo
!$omp end do
!$omp end parallel</code></pre>
<p>In this case the master thread (only) prompts for and reads the user input. The barrier is necessary to prevent the other threads from proceeding immediately
to the do loop, before <var>scale</var> has been entered. </p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -