Hi,

There are some strange behavior/s. I reduced the code to no much more than the data declaration, allocation and a minimum DO, more specifically:

- Code: Select all
`program Colleau_red ! "red" for "reduced" ...`

implicit none

INTEGER :: i, j, k, l, m, n, io, irow, icol, numAnim, ierr, jerr, numOfThreads

REAL(8), DIMENSION(:,:), ALLOCATABLE :: A, Ainv, T, Tinv, Asub

REAL(8), DIMENSION(:), ALLOCATABLE :: D, Dinv, Sol, Rhs, r, v, s, w, y, x

INTEGER, DIMENSION(:,:), ALLOCATABLE :: Ped

INTEGER, DIMENSION(:), ALLOCATABLE :: indx, indx1

real(8) :: a1

real :: start_time, end_time

numOfThreads = 8

!CALL OPM_SET_NUM_THREADS(numOfThreads)

call cpu_time(start_time)

n = 10;

ALLOCATE (D(n), Sol(n), Rhs(n), stat=ierr)

if (ierr.ne.0) then

print*," Allocation request for D, Sol, Rhs denied! "

stop

endif

ALLOCATE (Ped(n,3), v(n), indx(n), indx1(n), stat=jerr )

if (jerr.ne.0) then

print*," Allocation request for Ped, v, indx denied! "

stop

endif

PRINT*, " Commencing Colleau calculations for sub-matrix : "

m = 10

print*, " Number of animals in the subset matrix of A is : " , m

ALLOCATE (Asub(m,m), stat=jerr )

if (jerr.ne.0) then

print*," Allocation request for Asub denied! "

stop

endif

! !$OMP PRIVATE(i, j, k) SHARED(m, n, Ped, D, indx1, Sol, v) ! Works

! !$OMP PRIVATE(i, j, k, Rhs) SHARED(m, n, Ped, D, indx1, Sol, v) ! Doesn't work

! !$OMP PRIVATE(i, j, k, Rhs, Sol, v) SHARED(m, n, Ped, D, indx1) ! Doesn't work

!$OMP PARALLEL DO &

!$OMP PRIVATE(i, j, k) SHARED(m, n, Ped, D, indx1, Sol, v)

do k = 1, m

if (k .eq. 1) print*, ' k = ', k

enddo

!$OMP END PARALLEL DO

call cpu_time(end_time)

print*, " Elapsed time taken to calculate a subset of A is : ", end_time - start_time

print *, "Sol(n) = ", Sol(n)

end program

and I've played a little bit with three options for private and shared data:

! !$OMP PRIVATE(i, j, k) SHARED(m, n, Ped, D, indx1, Sol, v) ! Works

! !$OMP PRIVATE(i, j, k, Rhs) SHARED(m, n, Ped, D, indx1, Sol, v) ! Doesn't work

! !$OMP PRIVATE(i, j, k, Rhs, Sol, v) SHARED(m, n, Ped, D, indx1) ! Doesn't work

Using the first option, i.e.

!$OMP PARALLEL DO &

!$OMP PRIVATE(i, j, k) SHARED(m, n, Ped, D, indx1, Sol, v)

everything works as expected for the code (I know this is not what you need, I'm just playing around...):

$ ifort -openmp colleau-red.f90 -o colleau-redifort

$ ./colleau-redifort

Commencing Colleau calculations for sub-matrix :

Number of animals in the subset matrix of A is : 10

k = 1

Elapsed time taken to calculate a subset of A is : 8.8987000E-02

Sol(n) = 0.000000000000000E+000

The second option , i.e. using

!$OMP PARALLEL DO &

!$OMP PRIVATE(i, j, k, Rhs) SHARED(m, n, Ped, D, indx1, Sol, v)

fails...

$ ifort -openmp colleau-red.f90 -o colleau-redifort

$ colleau-redifort

Commencing Colleau calculations for sub-matrix :

Number of animals in the subset matrix of A is : 10

k = 1

*** glibc detected *** *** glibc detected *** *** glibc detected *** colleau-redifort*** glibc detected *** colleau-redifort: munmap_chunk(): invalid pointer: 0x00007fee2ad28610 ***

*** glibc detected *** colleau-redifort: *** glibc detected *** colleau-redifort: munmap_chunk(): invalid pointer: 0x00007fee2a125610 ***

======= Backtrace: =========

/lib64/libc.so.6[0x3196e74576]

colleau-redifort[0x40ad39]

colleau-redifort[0x403eca]

======= Backtrace: =========

*** glibc detected *** colleau-redifort: munmap_chunk(): invalid pointer: 0x00007fee2a526610 ***

Abortado (`core' generado)

and I think it should not fail... Also, it doesn't fail with gfortran:

$ gfortran -fopenmp colleau-red.f90 -o colleau-redgfortran

$ colleau-redgfortran

Commencing Colleau calculations for sub-matrix :

Number of animals in the subset matrix of A is : 10

k = 1

Elapsed time taken to calculate a subset of A is : 2.19959989E-02

Sol(n) = 0.0000000000000000

And the third option, the one suggested by MarkB, i.e. with

!$OMP PARALLEL DO &

!$OMP PRIVATE(i, j, k, Rhs, Sol, v) SHARED(m, n, Ped, D, indx1)

again does not work with ifort:

$ ifort -openmp colleau-red.f90 -o colleau-redifort

$ colleau-redifort

Commencing Colleau calculations for sub-matrix :

Number of animals in the subset matrix of A is : 10

k = 1

(note the missed lines). And it works as expected (at least by me...) with gfortran:

$ gfortran -fopenmp colleau-red.f90 -o colleau-redgfortran

$ colleau-redgfortran

Commencing Colleau calculations for sub-matrix :

Number of animals in the subset matrix of A is : 10

k = 1

Elapsed time taken to calculate a subset of A is : 2.19959989E-02

Sol(n) = 0.0000000000000000

Well, right now, I think you should ask the ifort people about this... feel free to use the code I've included, and please tell us about the result/s...

Just for completeness:

$ ifort -v

ifort version 12.1.3

$ gfortran -v

...

gcc version 4.6.3 20111216 (prerelease) (GCC)

HTH,

Fernando.