parallel processing - OpenMP not work with an array access indirect -


i'm trying optimize loop in parallel way openmp.

  double precision, intent(inout) :: x(13541)   integer         , intent(in)    :: nelem,nelmax !nelmax = 25996    integer         , intent(in)    :: ikle(nelmax)   double precision, intent(in)    :: w(nelmax) !$omp parallel private(ielem) reduction(+:x)   ielem = 1 , nelem     x(ikle(ielem)) = x(ikle(ielem)) + w(ielem)   enddo !$omp end parallel 

for , j different, it's possible ikle(i)=ikle(j)

increasing number of threads, found takes longer run loop. use omp_get_wtime() time job.

1 t  0.21943306922912598      2 t  0.30610203742980957      3 t  0.43688893318176270      4 t  0.53783702850341797      5 t  0.61055016517639160      6 t  0.96715998649597168      7 t  0.89582014083862305      8 t   1.3073339462280273 

i think problem caused array access indirect don't know how deal in openmp

if it's possible ikle(i)=ikle(j) have worse problem irregular access trashing hopes of efficient use of cached data, have data race -- there no protection in code against multiple threads writing same location 'simultaneously'. depending on frequency of occurrence of ikle(i)=ikle(j) may lucky , never experience race in practice. or may unlucky. either way, written, program wrong 'un.

fwiw agree suspicion irregular pattern of access elements of x root of timing peculiarity have reported, requires lot more movement of data through caches.

also, while i'm writing, line

  integer, intent(in) :: nelem,nelmax = 25996 

is wrong too, it's syntax error try initialise routine argument.

edit, in response op's comment:

the dependence surely problem -- not way of thinking, dependence (by take mean call data race) makes program wrong, broken, erroneous. poor scaling inconvenience. problem arises in openmp version of program because two, or more, threads may try update same element of x @ same time. update not atomic, various operations go on behind scenes (read data register, add values in 2 registers together, write data memory location, sort of thing) may interleaved in way, , of interleavings not leave value in x have been in sequential execution of program.

would give hints movement of data said? not @ time, i've written enough.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -