0
votes

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?

1
What is your reason for -I /usr/include/ -L /usr/lib -lm -lpthread? Why? Try to use as few flags as possible to be sure what causes it. This was enough for me : gfortran statica.f90 -frecursive. Ceterum censeo integer(8) or kind=8 is very ugly code smell.Vladimir F

1 Answers

1
votes

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.