Reputation: 1090
When I link the following code
PROGRAM MAIN
implicit none
integer(8), PARAMETER :: N=2**9
complex(8) ::A(N,N),B(N,N),C(N,N)
C=matmul(A,B)
end program MAIN
with Lapack and OpenMP via:
gfortran test.f95 -O3 -Wall -g -std=f95 -cpp -I /usr/include/ -L /usr/lib -lm -fopenmp -lpthread -lblas -llapack -fexternal-blas
I get a segmentation fault. Reducing the dimension of the array to 2**8 or removing OpenMP removes the error. What is the reason for this?
Upvotes: 0
Views: 278
Reputation: 59998
This is because -fopenmp
implies -frecursive
(try that one instead). That will cause the arrays to be placed on the stack and you get a stack overflow. By default the arrays will be static.
Tho compiler does this internally (-fdump-tree-original
):
MAIN__ ()
{
complex(kind=8) a[262144];
complex(kind=8) b[262144];
complex(kind=8) c[262144];
You could argue that it is not necessary to affect the main program arrays, because the main program is not re-entrant, but -frecursive
does that. If you make th arrays allocatable
they won't be affected.
Upvotes: 1