The use of equivalence with OpenMP

I run the following code

program readit
    implicit none

    INTEGER :: S_time,E_time
    real  :: rate=1000000.000

	 call system_clock(s_time)

	 call equiv()

	 call system_clock(e_time)

     print*,"total time",(e_time-s_time)/rate
end program

Subroutine equiv()
    INTEGER(2),dimension(6,1024,1024,2):: traject
    INTEGER(2),dimension(6*1024*1024,2):: trajectt

    equivalence (traject,trajectt)


end subroutine equiv

When I compile with openmp on like so:

pgf90 -Mchkstk -mp=bind readit.f90

I blow the stack even though there are no openmp calls in my program.

But if I take out the openmp flag the program runs as expected or if i leave the openmp flag on and take out equivalence the program also runs as expected. The equivalence arrays should be referencing the same memory so I am perplexed by this behavior.


Hi chaines,

Without -mp, traject’s storage is located in the .BSS (data) section of the binary. However in order to be thread safe, with -mp all variables are placed on the stack. This occurs even if you don’t have any OMP directives.

Note that 'traject" and ‘trajectt’ are using the same storage so why it succeeds when you remove the equivalence statement is unclear (it fails in the same way for me). If anything it should be worse since you’re doubling the amount of memory on the stack.

Here’s the assembly from the “-mp” compile with equivalence where the compiler is making room for tracject on stack:

        subq    $25165840, %rsp   
        movq    %rbx, -25165832(%rbp)

Here I’ve removed the equivalence and the stack memory doubled:

        subq    $50331664, %rsp
        movq    %rbx, -50331656(%rbp)

You will need to increase your stack size or remove the “-mp” flag.

  • Mat