- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am having a segmentation faul when running the following program :
it fails when doing the ptype%vmod(:,:,:) = ztab(:,:,:) + ptype%rmsk(:,:,:). If I do the loops explicitely then it works. If I define ptype's arrays as allocatable instead of pointer it works as well, but then AFAIK it won't be fortran95-standard anymore. I encounter this problem both on linux and OSX using the 11.1.088 version of ifort.
with other compilers such as gfortran or g95, this example works fine.
Am I doing something dodgy or is it a problem with the compiler ?
thanks,
Arthur
I am having a segmentation faul when running the following program :
[fortran]PROGRAM test
TYPE mytype
INTEGER :: i_i, i_j, i_k
REAL(KIND=8), POINTER, DIMENSION(:,:,:) :: &
& vmod, &
& rmsk
END TYPE mytype
INTEGER, PARAMETER :: kpi=360, kpj=180, kpk=50
TYPE(mytype) :: ptype
REAL(KIND=8), ALLOCATABLE, DIMENSION (:,:,:) :: ztab
ptype%i_i = kpi
ptype%i_j = kpj
ptype%i_k = kpk
ALLOCATE ( ptype%rmsk( kpi, kpj, kpk ))
ALLOCATE ( ptype%vmod( kpi, kpj, kpk ))
ALLOCATE ( ztab( kpi, kpj, kpk ) )
DO k = 1, kpk
DO j = 1, kpj
DO i = 1, kpi
ztab(i,j,k) = i*j*k
ptype%rmsk(i,j,k) = i+j+k
END DO
END DO
END DO
ptype%vmod(:,:,:) = ztab(:,:,:) + ptype%rmsk(:,:,:)
PRINT*,MINVAL(ptype%vmod),MAXVAL(ptype%vmod),SUM(ptype%vmod)
DEALLOCATE (ptype%rmsk, ptype%vmod,ztab)
END PROGRAM test[/fortran] it fails when doing the ptype%vmod(:,:,:) = ztab(:,:,:) + ptype%rmsk(:,:,:). If I do the loops explicitely then it works. If I define ptype's arrays as allocatable instead of pointer it works as well, but then AFAIK it won't be fortran95-standard anymore. I encounter this problem both on linux and OSX using the 11.1.088 version of ifort.
with other compilers such as gfortran or g95, this example works fine.
Am I doing something dodgy or is it a problem with the compiler ?
thanks,
Arthur
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi again,
If I reduce the size of the arrays, for instance using kpi=36, kpj=18, kpk=5, it does not fail anymore
If I reduce the size of the arrays, for instance using kpi=36, kpj=18, kpk=5, it does not fail anymore
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Two options:
1. Change the declarations of vmod and rmsk to ALLOCATABLE rather than POINTER
2. Add -heap-arrays to the compilation switches.
The problem is that in the assignment to ptype%vmod, the compiler can't tell, since vmod and rmsk are pointers, whether they overlap, so it creates a temporary array for the expression. By default, ifort creates this on the stack and you are getting a stack overflow. Adding -heap-arrays allocates the temp on the heap, which I think is what the other compiler does, and you avoid the error, though a copy is always bad.
By making these components ALLOCATABLE, which is supported in all reasonable Fortran compilers today, the compiler knows there is no overlap and avoids making a temp. This would be my preference.
1. Change the declarations of vmod and rmsk to ALLOCATABLE rather than POINTER
2. Add -heap-arrays to the compilation switches.
The problem is that in the assignment to ptype%vmod, the compiler can't tell, since vmod and rmsk are pointers, whether they overlap, so it creates a temporary array for the expression. By default, ifort creates this on the stack and you are getting a stack overflow. Adding -heap-arrays allocates the temp on the heap, which I think is what the other compiler does, and you avoid the error, though a copy is always bad.
By making these components ALLOCATABLE, which is supported in all reasonable Fortran compilers today, the compiler knows there is no overlap and avoids making a temp. This would be my preference.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page