[Users] Generalising to OpenMP
Chris Stevens
c.stevens at ru.ac.za
Wed Mar 28 03:24:04 CDT 2018
Hi everyone,
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:
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.
function blah ()
{
for (....)
{
computation involving scratch array
}
}
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.
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?
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.
Solution 3: One could do something like
#pragma omp parallel
{
create scratch space
#pragma omp parallel for
for
{
computation involving thread specific scratch space
}
}
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.
Is there perhaps another way that fits better with the OpenMP paradigm?
Many thanks!
Chris
--
Dr Chris Stevens
Claude Leon Postdoctoral Fellow
Department of Mathematics
Rhodes University
Room 5
Ph: +27 46 603 8932
Web: www.chrisdoesmaths.com <http://www.chrisdoesmaths.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.einsteintoolkit.org/pipermail/users/attachments/20180328/6c03a832/attachment-0001.html
More information about the Users
mailing list