Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran - compilator dependent, intrinsic array manipulation, memory problem

  1. Nov 5, 2011 #1
    Welcome all,

    I have a following code:

    Code (Text):
    program aaaa
    implicit none

    double precision, dimension(:), allocatable :: inp,outp
    integer ::n,i

    read(*,*) n

    allocate(inp(n),outp(n))

    write(*,*) allocated(inp), allocated(outp)

    write(*,*) inp(1)
    inp=cshift(outp,-size(outp)/2)
    write(*,*) inp(1)

    end program aaaa
    It really does nothing - it just applies cyclic rotation of dynamically created array.
    But when I use is for large n (in my case - over 10^6) then Segmentation fault occurs. More precisely this is the output:

    Code (Text):

    T T
      0.000000000000000E+000
    Segmentation fault
     
    I also discovered that by increasing the limit for stack memory the segmentation fault can be avoided. Clearly I am using cshift not appropriately.

    Additionally the code perform does not exists when the compilation is done with gfortran, but it exists with ifort v12.0.0.

    What is going on? I tried to compile with -check all, but it provides no info.
     
  2. jcsd
  3. Nov 5, 2011 #2

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    I guess cshift() is creating a temporary array somewhere. That seems a reasonable thing for it to do, since it function doesn't "know" you are just assigning its output to another variable. For example your code might say something like
    Code (Text):
    inp=(cshift(outp,1) + cshift(outp,2))/2
    I think you need to find out if you can control where temporaries are created (on the stack or the heap) and/or how to make the stack big enough. Those things are compiler-dependent, which is why the defaults "work" for one compiler but not for the other.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran - compilator dependent, intrinsic array manipulation, memory problem
  1. Fortran, memory, page. (Replies: 14)

Loading...