Segmentation fault (Fortran 77)

General OpenMP discussion

Segmentation fault (Fortran 77)

Postby jvdp » Thu Dec 26, 2013 11:01 am

Dear,

I am trying to parallelize with OpenMP* an Fortran77 subroutine written many years ago. This subroutine originates from a package (FSPAK90 for sparse matrices) available on Internet.
Because this is a lot of code, I only put below the code that I think needed to understand the problem. I tried to parallelize a loop in the subroutine 'fsinverse1'. This subroutine is called by the subroutine fspak. However, the use of OpenMP* as implemented below gave me the error « Segmentation fault (core dumped) ». I think that the reason is that the loop tried to write in a array outside its limits. But the code runs fine without parallelization. Please, could you help me to solve this problem ?

In advance thank you.

Happy New Year.


File 1 :
c ----------------
subroutine fspak
c ----------------
+ (option,n,ia,ja,a,b,flag,iout,ioor,
+ available,needed,is,fnode,bnode,
+ fnseg,bnseg,fx,feqb,irank,optfspak)
implicit none
integer order,symfac,numfac,solve,sinit,ssolve,samp_inv
+ ,det,ldet,check,spin,spin1,restart,stat,equal,mx_st,samp_ori
parameter (spin1=61)
integer available
+ ,delta,flag,ioor,iout,n,ia(1),ja(1),is(available)
+ ,fnode(1),bnode(1),fnseg,bnseg,feqb,irank,ratio,fratio
+ ,path,found,fpath,fstart,fpnode,bpath,bstart,bpnode
+ ,maxju,maxu,needed,maxneed,i,adjncy,d,invp,iu,iju,ju,u
+ ,maxint,nza,nzad,option,perm,iap,jap,ap,xadj,first,ios
+ ,zja,za,zd,utia,utja,work1,work2,work3,work4,work5
+ ,even
real*8 a(1),b(1),fx(1),st(mx_st),t_t,t0,tol
real*4 second
equivalence (st(1),maxju),(st(2),maxu),(st(3),maxneed),(st(4),nza)
save ratio
data st/mx_st*0./,first/0/
+ ,tol/1.d-8/

c function to ensure that real*8 variables are assigned an even address.
even(i)=2*(i/2)+1

if (first.eq.0) then
ratio=fratio()
first=1
endif
nza=(ia(n+1)-1)
nzad=2*nza
perm = 1
invp = perm + n
c ----------------------------
if (option.eq.spin1) then
c ----------------------------
work1 = even(u + maxu*ratio)
work2 = even(work1 + n*ratio)
work5 = even(work2 + n*ratio)
needed = work5 + nza+n
call fsinverse1
+ (n,is(perm),is(invp),is(d),is(iju),is(ju),
+ is(iu),is(u),is(work1),is(work2),is(work1),
+ is(work2),is(work5),ia,ja,a)
endif

return
end

File 2 :
SUBROUTINE fsinverse1
* (N, P, IP, D, IJU,JU,IU,U, TMPu,tmpz,tmpi,tmpi1,
* jja,ia,ja,a)
use OMP_LIB

implicit none
INTEGER P(1), IP(1), IJU(1), JU(1), IU(1), TMPi1(1),
* tmpi(1),jja(1),ia(1),ja(1),n,j1,k1
real*8 D(1), U(1), a(1), TMPu(1),tmpz(1)

integer i,j,k,iiu,juii,juii1
C
C ADDITIONAL PARAMETERS
C TMPu,tmpz - real ONE-DIMENSIONAL WORK ARRAYS; DIMENSION = N
C jja - integer on-dimensional work array of order ia(n+1)-1
C tmpi,tmpi1 - integer one-dimensional work array; dimension=N,
c tmpi and tmpi1 can occupy the same storage as
c tmpu and tmpz
C-----------------------------------------------------------------------

do i=1,n
tmpz(i)=0
tmpu(i)=0
enddo

do i=n,1,-1
juii=iju(i)-iu(i)
do j=iu(i), iu(i+1)-1
j1=ju(juii+j)
tmpu(j1)=u(j)
tmpz(j1)=u(j)*d(j1)
enddo

do j=iu(i),iu(i+1)-1
j1=ju(juii+j)
juii1=iju(j1)-iu(j1)
c$omp parallel default(none)
c$omp& shared(iu,j1,ju,juii1,tmpu,u)
c$omp& private(k,k1) reduction(+:tmpz)
c$omp do schedule(auto)
do k=iu(j1),iu(j1+1)-1
k1=ju(juii1+k)
tmpz(j1)=tmpz(j1)+tmpu(k1)*u(k)
enddo
c$omp end do
c$omp end parallel
do k=iu(j1),iu(j1+1)-1
k1=ju(juii1+k)
tmpz(k1)=tmpz(k1)+tmpu(j1)*u(k)
enddo
enddo
enddo
end
jvdp
 
Posts: 2
Joined: Thu Dec 26, 2013 3:23 am

Re: Segmentation fault (Fortran 77)

Postby MarkB » Mon Jan 06, 2014 10:22 am

I think the problem arises because of the use of the array tmpz(). This is declared as tmpz(1), but the code deliberately writes outside the bounds of this. This is OK sequentially because the out of bounds accesses are actually somewhere into the is() array. With OpenMP, tmpz is declared as a reduction, the private copies of the array created for each thread will only be one element long, and the out-of-bounds access to these private copies are not anywhere sensible!

One solution would be to declare an array of size N inside the fsinverse1 routine, use this as the reduction array, and copy it back into tmpz before exiting the routine.

Hope that helps,
Mark.
MarkB
 
Posts: 480
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Segmentation fault (Fortran 77)

Postby jvdp » Thu Jan 09, 2014 2:01 am

Dear,

Thank you for your answer,explanation and advice. It help me. Now, this part of the code is parallelized with OpenMP and works fine.

Thank you

Jérémie
jvdp
 
Posts: 2
Joined: Thu Dec 26, 2013 3:23 am

Re: Segmentation fault (Fortran 77)

Postby MarkB » Thu Jan 09, 2014 3:28 am

You're very welcome: glad to be of assistance!

Mark.
MarkB
 
Posts: 480
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests