minloc gives value outside array bounds

General OpenMP discussion

minloc gives value outside array bounds

Postby lstagner » Tue Apr 15, 2014 1:26 am

I have some code that is something like this
Code: Select all
subroutine track(in,out)
...
minpos=minloc(local_array) !local array has three elements
...
end subroutine track

!$OMP PARALLEL DO private(in,out,i)
do i=1,100000
    ...
    call track(in,out)
    ...
enddo
!$OMP END PARALLEL DO



When running with one thread it works fine. When running in parallel minloc will return an index that is outside the array bounds.

I am compiling with gfortran 4.7.3 with the following compiler flags -g -O0 -fopenmp -Wall -fbacktrace -fbounds-check

Any help would be much appreciated.
lstagner
 
Posts: 5
Joined: Mon Feb 17, 2014 7:04 pm

Re: minloc gives value outside array bounds

Postby MarkB » Tue Apr 15, 2014 6:46 am

I presume local_array is declared inside track() and doesn't have the SAVE attribute (and is therefore implicitly private to each thread)?

If so, it could be a compiler bug: are you able to try a more recent version of gfortran or a different compiler?
MarkB
 
Posts: 450
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: minloc gives value outside array bounds

Postby lstagner » Tue Apr 15, 2014 12:55 pm

Yes, local_array is declared inside the track function. I have compiled the code with the Intel Fortran compiler and there is no obvious breakage. I added the -fno-automatic flag which causes a different out of bounds error.

I might as well just show you the source code.
https://github.com/D3DEnergetic/FIDASIM ... .f90#L2624 <= original segfault track is called by ndmc
https://github.com/D3DEnergetic/FIDASIM ... .f90#L1176 <= segfault with -fno-automatic compiler flag
lstagner
 
Posts: 5
Joined: Mon Feb 17, 2014 7:04 pm

Re: minloc gives value outside array bounds

Postby MarkB » Tue Apr 15, 2014 1:45 pm

Ah, I think the problem is with minpos - it's declared as module data and so is shared between threads by default, which results in race conditions.
MarkB
 
Posts: 450
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: minloc gives value outside array bounds

Postby lstagner » Tue Apr 15, 2014 1:49 pm

Ah... any suggestions on how to fix it?
lstagner
 
Posts: 5
Joined: Mon Feb 17, 2014 7:04 pm

Re: minloc gives value outside array bounds

Postby MarkB » Tue Apr 15, 2014 2:04 pm

You can declare minpos local to each routine where is it used - as far as I can see this should work as you don't ever carry the value between routines.
If not, then you could list it in a threadprivate directive in the module.

By the way, you shouldn't ever use -fno-automatic with OpenMP - I'm surprised the compiler even allows it!
MarkB
 
Posts: 450
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 12 guests