- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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 kopiert
6 Antworten
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Thank you! I didn't realize this would affect arrays that small.
Jeremy
Jeremy
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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?
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
This example has no problem running on my 3 year old laptop, with current ifort 9.1.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
OK, so it is probably fixed already in 9.1
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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.

Antworten
Themen-Optionen
- RSS-Feed abonnieren
- Thema als neu kennzeichnen
- Thema als gelesen kennzeichnen
- Diesen Thema für aktuellen Benutzer floaten
- Lesezeichen
- Abonnieren
- Drucker-Anzeigeseite