Skip to content

Instantly share code, notes, and snippets.

@szaghi
Created November 6, 2016 07:31
Show Gist options
  • Save szaghi/822f37541557b610555960a73dcf2e09 to your computer and use it in GitHub Desktop.
Save szaghi/822f37541557b610555960a73dcf2e09 to your computer and use it in GitHub Desktop.
Test the Stack memory bias for Fortran allocatable/pointer variables

Test Fortran Satck Memory Bias

A testbased on Gary Scott's issue described here.

This test reproduction is devoted to Paul Rich & Co. for GNU gfortran users

The test code

program test
use iso_fortran_env

implicit none

type WPDataDef
  real(real32), pointer     :: selData(:,:)
  real(real32), pointer     :: selDataG(:,:)
  real(real32), allocatable :: set1Data(:,:)
  real(real32), allocatable :: set2Data(:,:)
  real(real32), allocatable :: set3Data(:,:)
end type

type (WPDataDef), target :: svWPData
type (WPDataDef)         :: wpDataSort

allocate(svWPData%set1Data(600,5000))
allocate(svWPData%set2Data(600,5000))
allocate(svWPData%set3Data(600,5000))

allocate(WPDataSort%set1Data(600,5000))

#ifdef STACK
svWPData%set1Data = wpDataSort%set1Data
#else
call safe_copy(to=svWPData%set1Data, from=wpDataSort%set1Data)
#endif

contains
  subroutine safe_copy(from, to)
    real(real32), intent(in)  :: from(:,:)
    real(real32), intent(out) :: to(:,:)
    to = from
  end subroutine safe_copy
end program

Running Architecture

Lenovo MIIX 700, Intel(R) Core(TM) m5-6Y54 CPU @ 1.10GHz, 4GB Ram, 4.4.0-45-generic #66-Ubuntu SMP Wed Oct 19 14:12:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Results

stefano@thor(08:21 AM Sun Nov 06)
~/downloads/test_stack 2 files, 28Kb
→ gfortran -DSTACK -Warray-temporaries test_stack.F90 

stefano@thor(08:28 AM Sun Nov 06)
~/downloads/test_stack 2 files, 28Kb
→ ./a.out 

stefano@thor(08:28 AM Sun Nov 06)
~/downloads/test_stack 2 files, 28Kb
→ gfortran -Warray-temporaries test_stack.F90 

stefano@thor(08:28 AM Sun Nov 06)
~/downloads/test_stack 2 files, 28Kb
→ ./a.out 

Compiler

GNU gfortran 6.2.0

Stack memory

ulimit -s 1024

Conclusions

Under GNU Linux, with GNU gfortran 6.2.0 the test shows that the stack memory is not used as expected, the stack memory being also reduced to 1MB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment