1

My code is following:

 program
 ...
 ! Loop which I want to parallelize
 !$OMP parallel DO
 I = 1, N
 ...
 call FORD(i,j)
  ...
 !$OMP END parallel DO
 end program

  subroutine FORD(i,j)
  logical servo,genflg,lapflg
  dimension c(nvarc)
  dimension zl(3),zg(3),v1(3,3),v2(3,3),rn(3),
 .          rcg1(3),rcg2(3),ru1(3),ru2(3),
 .          rott1(3),rott2(3),velr(3),dt(3),
 .          dfs(3),ftu(3),fnr(3),amomet(3
  common /contact/ iab11,iab22,xx2,yy2,zz2,
 .                 ra1,rb1,rc1,ra2,rb2,rc2,
 .                 v1,v2,
 .                 xg1,yg1,zg1,xg2,yg2,zg2
  common /ellip/ b1,c1,f1,g1,h1,d1,
 .               b2,c2,f2,g2,h2,p2,q2,r2,d2
  common /root/ root1,root2
  common /tab1/
 .       itype(ndim1),nconti(5),nvarc,
 .       nconta,nconta1
  common /bal1/
 .       ra(5),rb(5),rc(5),
 .       amomen(ndim),fwall(6),press(3),wmomet(6,2),
 .       rot(ndim),ttheta(ndim*3),rstp(ndim*3),forces(ndim),
 .       ssampl(3,3),edserv(3,3),tdisp(ndim),adisp(ndim),vel(ndim),
 .       del(3),xmax(3)

CALL CONDACT(genflg,lapflg)
return
end subroutine

SUBROUTINE CONDACT(genflg,lapflg)
implicit double precision (a-h,o-z)
logical rflag,dflag,error,gmvflg,grvflg,ctrlflg,depflg
  parameter (ndim1 = 20002)
  parameter (ndim = 3*ndim1)
  parameter (nkmm = 9000000)
  parameter (nkwall = 50000)
  character*4 hed
  logical genflg,lapflg,fast
  dimension v1(3,3),v2(3,3)
  common /contact/ iab11,iab22,xx2,yy2,zz2,
 .                 ra1,rb1,rc1,ra2,rb2,rc2,
 .                 v1,v2,
 .                 xg1,yg1,zg1,xg2,yg2,zg2
  common /ellip/ b1,c1,f1,g1,h1,d1,b2,c2,f2,g2,h2,p2,q2,r2,d2
  common /switch/ nk
  common /root/ root1,root2
  common /nroot/ rt(5),nrt
  common /bal2/xmax(3)

 call function f(x)
 C
 C...... 
 C

 RETURN
 END

  function f(x)
  implicit double precision (a-h,o-z)
  common /contact/ iab11,iab22,xx2,yy2,zz2,
 .                 ra1,rb1,rc1,ra2,rb2,rc2,
 .                 v1,v2,
 .                 xg1,yg1,zg1,xg2,yg2,zg2
  common /ellip/ b1,c1,f1,g1,h1,d1,
 .               b2,c2,f2,g2,h2,p2,q2,r2,d2
  common /switch/ nk
  common /nroot/ rt(5),nrt
  dimension a(3,3),b(3),v1(3,3),v2(3,3)
  ..
  ..
  ..
  ..
  end

my question is inside the parallel loop, does all variable (within common block or outside of common block) in each subroutine are private? 1. If not, should I use threadprivate for the common blocks and private the variables in each subroutine after declaration? 2. Each thread passes through 2 subroutine and one function. Subroutines has some same common block and variables. if I use threadprivate common blocks for each subroutine, how do the variable values pass through the entire program for a single thread. Any help will be appreciated. Thanks!

Ross
  • 2,130
  • 14
  • 25
sam
  • 49
  • 6
  • 1
    Eliminate common blocks. – Jeff Hammond Aug 28 '15 at 03:06
  • Thanks Jeff. So, Will I just declare the variable? That will make them private for each thread? – sam Aug 28 '15 at 14:56
  • Remove common blocks means all local variables as arguments, among other things. – Jeff Hammond Aug 28 '15 at 14:57
  • Or make the common blocks `threadprivate` http://stackoverflow.com/questions/32209196/fortran-77-common-blocks-in-multithreading-c-application/32213488#32213488 – Vladimir F Героям слава Aug 30 '15 at 22:13
  • Thanks Vladimir! But I have tried with threadprivate but got segmentation failure. (I read somewhere that threadprivate common block takes huge memory space/stack.) – sam Aug 31 '15 at 16:32
  • 1
    Just to reiterate what Jeff was saying, you should spend some effort in making the serial version of your code work without common blocks. There are a lot of reasons why, but [here's](http://iprc.soest.hawaii.edu/users/furue/improve-fortran.html) a quick overview on the how. Once you have succeeded in doing this, then you can re-tackle the problem of serializing this program with OpenMP. – NoseKnowsAll Aug 31 '15 at 22:17
  • @VladimirF, can I rewrite the common block variable inside the subroutine or function, once I declared the common block in the main thread? or it will just pass the variable value of main thread? – sam Sep 05 '15 at 23:57
  • Ask a new question and show the code. – Vladimir F Героям слава Sep 06 '15 at 05:46
  • @VladimirF, here is the new question http://stackoverflow.com/questions/32446564/issue-with-common-blockfortran-in-open-mp-parallel-programming – sam Sep 08 '15 at 18:03

0 Answers0