- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
could someone explain to me why the attatched code ends with a segmentation fault? It doesn't seem like a big enough array to be causing memory type problems, at least it doesn't to me!
program testmatrix
use module_2
implicit none
real, dimension(:, :), allocatable :: matrix
allocate(matrix(3000, 3000))
matrix = 1.0
call trythis(matrix)
deallocate(matrix)
end program testmatrix
module module_2
use module_1
implicit none
contains
subroutine trythis(x)
real, dimension(:, :) :: x
print*, x
end subroutine trythis
end module module_2
thanks
Jeremy
could someone explain to me why the attatched code ends with a segmentation fault? It doesn't seem like a big enough array to be causing memory type problems, at least it doesn't to me!
program testmatrix
use module_2
implicit none
real, dimension(:, :), allocatable :: matrix
allocate(matrix(3000, 3000))
matrix = 1.0
call trythis(matrix)
deallocate(matrix)
end program testmatrix
module module_2
use module_1
implicit none
contains
subroutine trythis(x)
real, dimension(:, :) :: x
print*, x
end subroutine trythis
end module module_2
thanks
Jeremy
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're getting a stack overflow on the assignment to the array. I guess the compiler is constructing a temporary array for the constant 1.0. Increase the stacklimit to work around this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! I didn't realize this would affect arrays that small.
Jeremy
Jeremy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do not think the compiler creates temporary for the array asignment (that would be silly, anyway). Check out the following code:
compiled with ifort 9.0 (default settings), it produces
the output:
(and creates a huge file).
The fault evidently occurs at write, and the strange thing is that it doesn't in trythis2, where an array of the same size is written. Perhaps this is a bug after all?
module module_2
implicit none
contains
subroutine trythis(x)
real, dimension(:, :) :: x
open(10,file='test.out')
print *,'file opened'
write(10,*) x
print *,'array written'
close(10)
end subroutine
subroutine trythis2
real, dimension(:, :) :: x
allocatable:: x
allocate(x(3000,3000))
x = 1.0
open(10,file='test.out')
write(10,*) x
close(10)
end subroutine
end module module_2
program testmatrix
use module_2
implicit none
real, dimension(:, :), allocatable :: matrix
allocate(matrix(3000, 3000))
matrix = 1.0
call trythis2
print *,'trythis2 returned'
call trythis(matrix)
deallocate(matrix)
end program
compiled with ifort 9.0 (default settings), it produces
the output:
trythis2 returned
file opened
Segmentation fault
(and creates a huge file).
The fault evidently occurs at write, and the strange thing is that it doesn't in trythis2, where an array of the same size is written. Perhaps this is a bug after all?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This example has no problem running on my 3 year old laptop, with current ifort 9.1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, so it is probably fixed already in 9.1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There were definitely some bugs fixed for allocatable arrays passed as a subroutine argument. There are (or were) cases where allocatable arguments end up requiring a temporary stack array. I would not be suprised if there are not still a few issues with certain uses of allocatable arrays, especially when using the features that are extensions to F95.
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