2

I am writing some parallel Fortran90/95 code and I just came across some thing I can't understand.

I work on a Toshiba laptop with 6Go RAM.

  • In Windows 10, I use code::blocks. I have imported gfortran from MinGW as a compiler and compile my code with the -fopenmp flag.
  • I have Ubuntu 18.04 inside VirtualBox. I let it use half of my ram, that is 3Go. I compile my code on this one using gfortran -fopenmp as well.

A minimal version of the encountered code causing issue is:

program main
  implicit none

  integer :: i
  integer, parameter :: n=500000
  real, dimension(n) :: A, B
  real :: som

  som=0

  do i =1, n
    A(i)= 1.0
    B(i)= 2.0
  end do

  do i=1, n
    som = som + A(i)*B(i)
  end do

  print *,"somme:", som
end program main

I then let vary the value of the parameter n.

  • Running on Windows. For n up to approx 200.000 everything's fine. Above, I get "Process returned -1073741571 (0xC00000FD)"
  • Running on Ubuntu I can go up to 1.000.000 with no issue. Seems that the barrier is around 2.000.000 after which I got a segfault.

My question is how one can explain that ubuntu, in spite of having far less memory available can handle 10 times more iterations ?

Is there anything I can do on the Windows size to make it able to handle more loop iterations ?

EdouardIFP
  • 273
  • 2
  • 10
  • 1
    `-fopenmp` in gfortran implies `frecursive`, that allocates all local arrays on stack. Configure your stack size with `-fmax-stack-var-size=n` passing a suitable `n` and check if the problem persists – Rodrigo Rodrigues Nov 28 '18 at 09:02
  • I added -fmax-stack-var-size=65535 as a flag and I am now able to loop over 100 million elements on both Windows and Ubuntu. I guess the default setting was not the same. Thank you very much – EdouardIFP Nov 28 '18 at 09:25

2 Answers2

0

According to Rodrigo Rodrigues comment, I added one more flag to my compiler setting:

-fmax-stack-var-size=65535

Documentation says default is 32767 but I assume there is a different setting in code blocks and in ubuntu's native gfortran.

EdouardIFP
  • 273
  • 2
  • 10
  • The stack size setting is not affected by your build tools, except to the extent that you specify it at link time. You could probably achieve your goal by the alternative of setting OMP_STACK_SIZE. Default sizes are smaller for Windows, or for 32- vs 64-bit mode. In 32-bit Windows, they might be barely large enough to avoid false sharing between stacks. – tim18 Nov 28 '18 at 11:07
-1
program main

  implicit none
  real,allocatable :: A(:),B(:)
  real :: som
  integer :: i
  integer, parameter :: n=500000
  allocate(A(n))
  allocate(B(n))


  som=0

  do i =1, n
    A(i)= 1.0
    B(i)= 2.0
  end do

  do i=1, n
    som = som + A(i)*B(i)
  end do

  print *,"somme:", som
end program main

Replacing

real, dimension(n) :: A, B

with

real,allocatable :: A(:),B(:)
allocate(A(n))
allocate(B(n))

solved the problem, please check.