- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Im getting a segmentation fault from the code below compiled with version 10 of ifort. the only flag im using is -stand to make sure that everything is portable.
*********************************************************
program precision
implicit none
integer, parameter :: sp = selected_real_kind(6,37)
integer, parameter :: dp = selected_real_kind(15,307)
integer, parameter :: qp = selected_real_kind(33,4931)
type particle
real(sp) :: h
real(sp) :: V
end type particle
type particle_system
integer :: n
real(sp) :: r
type(particle), allocatable :: par(:)
end type particle_system
integer :: N,i
integer :: aerr
type(particle_system) :: psys
N = 150**3
write(*,*) "N = ", N
psys%n = N
psys%r = 12.5
allocate( psys%par(N) ,stat=aerr)
if (aerr/=0) stop "cant allocate psys%par"
write(*,*) "allocated particle system"
psys%par(:)%h = 1.0
do i = 1,N
psys%par(i)%h = psys%par(i)%h * 2
end do
write(*,*) "ran loop"
psys%par(:)%h = psys%par(:)%h * 2
end program precision
********************************************************
the code runs up to the write statement which says "ran loop" then produces a seg fault while trying to accomplish the line just after the write statement (which does the same thing, just without a do loop). I dont know if it has something to do with the derived types because it doesn't seg fault for smaller values of N (the size of the array par). It whole array assignment does work with arrays that are not components of derived types ie ( h = 2 * h) would work with the proper declarations. It also compiles and runs fine with the free g95 compiler. Does anyone have some insight into what is actually happening behind the scenes when the whole array operations are invoked? Any ideas about what is causing the seg fault? Thanks for your time,
Gabe
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
>> The compiler is probably creating a stack temporary and running out of stack. Try raising your stacksize limit or compile with -heap-arrays.
The problem is the compiler is creating an unnecessary stack temporary to hold the array of structures.
The user should submit this to Intel Premier Support.
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>> I agree with Jim - please submit this to Intel Premier Support and indicate that the last assignment statement ought not to generate array temporary copies.
Also put in a gripe to request that a compiler option be available to report on instances of temporary array creation. These buggers are hard to spot except for when you use a profiler or happen to stumble into the code in Disassembly window. BTW there is a runtime option to make such a reportbut I found this of little use as the "traceback" info is insufficient. The place to catch the problem is at compile time.
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Now there are cases where the compiler thinks it might need to create a temporary copy of an array. In many cases where a copy is in fact not required the compiler figures this out, but allocatable arrays in derived types have interesting semantics on assignment and the compiler might not always remove unnecessary copies. This could manifest itself as segfaults due to stack overflow. Compiling with -heap-arrays can help with this.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page