<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi everyone,</p>
<p>I am new to OpenMP programming, and have quickly come across an
(I think) interesting task that I want to parallelise with OpenMP
that does not seem straightforwardly generalisable. I would like
to hear your feedback on the potential solutions and whether there
is a better way to do it:<br>
</p>
<p>Task: Create a scratch array, say of CCTK_REAL, during an
initialisation phase that is shared with other code using a header
file. This array is defined only once. This scratch array is then
used as temporary storage space in a function that does some
computation within a for loop. i.e.</p>
<p>function blah ()</p>
<p>{</p>
<p> for (....)</p>
<p> {</p>
<p> computation involving scratch array<br>
</p>
<p> }<br>
</p>
<p>}<br>
</p>
<p>This works fine when OpenMP is turned off. However when you add
to the for loop above #pragma omp parallel for, then one sees that
this one scratch array will be being used by multiple threads at
once, thus causing issues.</p>
<p>Solution 1: Each thread has its own scratch space. I am not sure
if it is within the OpenMP paradigm to create scratch spaces for
each thread within the initialisation file, and share them through
a header. This doesn't seem to work and I am thinking this
shouldn't be possible?</p>
<p>Solution 2: Create one serial scratch space during initialisation
that has size dependent on omp_get_num_threads(). One would then
have to change the computation involving the scratch array to be
dependent on omp_get_thread_num() so as to use its allocated part
of the scratch space.</p>
<p>Solution 3: One could do something like</p>
<p>#pragma omp parallel</p>
<p>{</p>
<p> create scratch space<br>
</p>
<p> #pragma omp parallel for</p>
<p> for <br>
</p>
<p> {</p>
<p> computation involving thread specific scratch space<br>
</p>
<p> }<br>
</p>
<p>}<br>
</p>
<p>In summary: Solution 1 doesn't seem to work and probably doesn't
fit into the OpenMP paradigm. Solution 2 would work but doesn't
seem very nice. Solution 3 is nicer but inefficient as I don't
want to be creating scratch spaces all the time.</p>
<p>Is there perhaps another way that fits better with the OpenMP
paradigm?<br>
</p>
<p>Many thanks!</p>
<p>Chris</p>
<div class="moz-signature">-- <br>
<font size="-1" face="Cantarell" color="#666666">Dr Chris Stevens<br>
<br>
Claude Leon Postdoctoral Fellow<br>
</font>
<div class="moz-signature">
<div class="moz-signature">
<div class="moz-signature"> <font size="-1" face="Cantarell"
color="#666666"> </font>
<p><font size="-1" face="Cantarell" color="#666666">Department
of Mathematics</font></p>
<font size="-1" face="Cantarell" color="#666666"> </font>
<p><font size="-1" face="Cantarell" color="#666666">Rhodes
University</font></p>
<p><font color="#666666"><font size="-1"><font
face="Cantarell">Room 5</font></font></font></p>
<p><font color="#666666"><font size="-1"><font
face="Cantarell"> Ph: +27 46 603 8932</font></font></font></p>
<p><font color="#666666"><font size="-1"><font
face="Cantarell">Web: <a moz-do-not-send="true"
href="http://www.chrisdoesmaths.com">www.chrisdoesmaths.com</a></font></font></font></p>
</div>
</div>
</div>
</div>
</body>
</html>