[Omp] allocatable memory and array in subroutine are not private - segfault issue
Micha Feigin
michf at post.tau.ac.il
Sat Nov 17 01:39:09 PST 2007
I am having a problem with prallelizing some code. It seems to be according to
spec but still causes errors.
I have a function called from within a parallel do loop which among other
things has several small arrays and some allocated and deallocated memory. The
spec seems to say that all that memory is private but it seems that different
instances of that function (different threads) stomp each others memory.
I haven't managed to make a minimal example since this depends on timing issues
apparantly but here are the relevant parts of the code (after cutting out what
I believe to be unrelated). This is run under linux and shows a problem with
both the intel compiler and gfortran and is run under intel core 2 duo in 64
bit mode.
There is one omp do loop directive near the start, the problematic function is EigenVecs.
The two points of problem when using more then one thread
1. the call to dsaupd (arpack eigenvalue calculation) tell me that the input values are
wrong (don't know which one because the error comes from farther). Not on the first
run of the loop, but a bit later
2. I get a segmentation fault with the two deallocate directives one line up from the end.
Removing them solves the segfault so there is some double deallocation going on
seems to me that the arrays/allocatable objects are forced to shared for some reason
the code:
-----------
integer function PeronaMalikIteration(in, out, pprms, eprms)
real*8, allocatable :: v(:, :), d(:)
!$omp parallel shared(in, out, eprms, pprms) private(ret, col, row, v, d)
allocate(v(eprms%ldv, eprms%ncv), d(eprms%neigs))
!$omp do schedule(dynamic, 1)
do col = 1,n
do row = 1,n
ret = EigenVecs(in, v, d, pprms, eprms)
end do
end do
!$omp end do nowait
deallocate(v, d)
!$omp end parallel
end function PeronaMalikIteration
! ------------------------------------------------------
! calculate eigenvectors
! ------------------------------------------------------
integer function EigenVecs(img, v, d, pprms, eprms)
type(PeronaParams), intent(IN) :: pprms
type(EigParams), intent(IN) :: eprms
real*8, intent(IN) :: img(eprms%windowSz, eprms%windowSz), &
v(eprms%ldv, eprms%ncv), d(eprms%neigs)
! Algorithm parameters
! Relative Tolerance, set to default - machine precision
real*8 :: tol = 0.0d0
real*8 :: sigma = 0.0d0
! Algorithm variables
integer :: ido, lworkl, info
integer, dimension(11) :: iparam, ipntr
real*8, allocatable, dimension(:) :: resid, workd, workl
!DEC$ ATTRIBUTES ALIGN: 16 :: resid, workd, workl
logical :: rvec = .true.
logical, allocatable, dimension(:) :: select
character(len=1) :: B = 'I'
character(len=2) :: which = 'LA'
! Set parameter values
! Default return, no error
EigenVecs = 0
! Initial parameters to the dsaupd routine
ido = 0
info = 0
! (/ ISHIFT, -, MXITER, NB, NCONV, -, MODE, NP, NUMOP, NUMOPB, NUMREO /)
iparam = (/ 1 , 0, 1000*eprms%neigs, 1 , 0 , 0, 1 , 0 , 0 , 0 , 0 /)
! Workspace
lworkl = eprms%ncv*(eprms%ncv + 8)
allocate(resid(eprms%n), workd(3*eprms%n), workl(lworkl))
do
call dsaupd(ido, B, eprms%n, which, eprms%neigs, tol, resid, &
eprms%ncv, v, eprms%ldv, iparam, ipntr, workd, workl, lworkl, info)
select case (ido)
case (-1,1)
! multiply y <- OP*x
! where x = workd(ipntr(1))
! y = workd(ipntr(2))
call PeronaMalikResponse(workd(ipntr(1)), workd(ipntr(2)), img, &
eprms, pprms)
case default
exit
end select
end do
! Error !!!
if (info /= 0) then
EigenVecs = info
goto 99999
end if
allocate(select(eprms%ncv))
call dseupd(rvec, 'A', select, d, v, eprms%ldv, sigma, B , eprms%n, &
which, eprms%neigs, tol, resid, eprms%ncv, v, eprms%ldv, iparam, &
ipntr, workd, workl, lworkl, info)
deallocate(select)
99999 deallocate(resid, workd, workl)
end function EigenVecs
More information about the Omp
mailing list