Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

value from last iteration

roddur
Beginner
876 Views
hi friends,
i am back in square 1. this is my code!

411!$omp parallel do default(shared) &
412 !$omp private(il,ienrp,e,istart,iend,iie,xxa,yya) &
413 !$omp private(xa,ya)
414 orbital: do il=1,lorbit-2,2
415 xa=0.0;ya=0.0
416 write(*,'(1x,"Starting orbital loop",1x,i1,$)') il
417 ienrp=0
418 e=emin-de
419 istart=1
420
421 do iend=9,63,lorbit
422 e=e+de
423 iie=0
424
425 ienrp=ienrp+1
426 call hop(il,e,ienrp,map,srl,ap1, &
427 ap6,ap7,ap8,ap9,ap10,ap11, &
428 ap12,ap13,ap2,ap3,ap4,xa,ya)
429
430 istart=iend+1
431 write(*,'(".",$)')
432 end do
433 call fit(xa,ya,seed,xxa,yya,temp,il)
434 call spectral(il,xxa,yya,temp,spec)
435 write(*,'("done")')
436 end do orbital
437 !$omp end parallel do
438 !STOP

on line 415, if i comment it out, its running fine in serial mode; but in parallel its crashing out. actually i dont want to make xa,ya 0 in each step, rather it should carry its previous value. how ccan i do that?
0 Kudos
3 Replies
TimP
Honored Contributor III
876 Views
If you have multiple threads modifying a shared variable, you must do the updates in a critical region, or with atomic. That still won't achieve the serialization you appear to want. You could set a semaphore to require each thread to wait for completion of all updates in earlier iterations before reading the value. On the face of it, you have a contradiction, saying you want parallel execution without parallelization.
0 Kudos
roddur
Beginner
876 Views
Quoting - tim18
If you have multiple threads modifying a shared variable, you must do the updates in a critical region, or with atomic. That still won't achieve the serialization you appear to want. You could set a semaphore to require each thread to wait for completion of all updates in earlier iterations before reading the value. On the face of it, you have a contradiction, saying you want parallel execution without parallelization.
will you plz be a bit more explicit?
0 Kudos
jimdempseyatthecove
Honored Contributor III
876 Views

Do you want

1)xa and ya zeroed on the first iteration then remain untouched for the remainder iterations?
iterations being defined as inside your !$omp parallel do.

2)xa and ya zeroed at program start then pass the prior valuesfor each time you subsequentlyenter the!$omp parallel do?

If 1) do you realize as coded that xa and ya are computed seperately by each thread and will contain a partial result for each thread. So...

3) Do you want the sum of the individual threads private xa and ya from within the parallel do to be summed for export out of the parallel do for use in a total xa and ya outside the parallel do and also for use of initialization on the next time you enter the parallel do?

4) Do you want something else?

When you have multiple threads working you (the programmer) must be specific as to which thread is responsible for what computations (either partial results or total results), be specific on combining results and/or waiting for completion of generation of partial results, and so on and so on...

Think of the threads as workers in a factory and you are their boss. It is your job to divide up the work and assign jobs to worker and to instruct them as to how to coordinate their jobs. If one worker's job is to grab a bucket and fill it up with paint, and another worker's job is to take the bucket of paint to the another worker that is the painter, then your responsibility as boss is to instruct the second worker to wait until the bucket has finished filling and spigot turned off prior to taking bucket of paint to painter. Otherwise you have a mess. You cannot assume your workers are smart enough to do what you want (as opposed to doing what they are told).

Jim Dempsey


0 Kudos
Reply