Fortran OpenMP question

Fortran OpenMP question


Is it possible to call an internal subroutine from inside a PARALLEL DO loop? Specifically, the loop variable and others declared PRIVATE (by openmp clause) are referenced in the internal subroutine. My experiments so far with XLF, Gfortran, and IVF say no. Looking for confirmation or advice to make it work.

Al Greynolds
www.ruda.com

4 posts / 0 new

Quoting - AlGreynolds
Is it possible to call an internal subroutine from inside a PARALLEL DO loop? Specifically, the loop variable and others declared PRIVATE (by openmp clause) are referenced in the internal subroutine. My experiments so far with XLF, Gfortran, and IVF say no. Looking for confirmation or advice to make it work.

Al Greynolds
www.ruda.com

Hi Al,

I will have to check the OMP spec, but I can see where this would be a real problem. Let's take a case where your program declares the loop index I as integer. In the DO loop, you declare I as PRIVATE.

Ok, assume your internal procedure uses I from host association, that is, it uses I from the host program. At compile time, the compiler has to bind this I to an address. It will bind to the address for I that the main program is using, the master thread is it were, it has no way to know that I will be coming from a dynamic address within a parallel region. So my suspicion is that since internal procedures bind to addresses at compile time, I really doubt that this is allowed or advised.

I will check the spec though.

ron


I haven't found anything in the spec so far, but it is clear from the spec that the PRIVATE clause sets the scope for the private variables to be within that parallel region. In this way, your private variables are almost 'renamed' within that PRIVATE region and they are not visible outside of this scope.

You can, of course, pass these private variables to the internal procedure as arguments. I did find an example of doing this on the Internet. But I suspect you were hoping for the shorthand way of doing this without having to pass each and every PRIVATE variable as an argument.

ron


I think passing the private variables to the internal subroutine as argumentswould be the safest route.

I can see potential problems with the optimization process in the compiler if/when the internal subroutine is called from outside a parallel region AND called inside a parallel region AND using private variables not passed as arguments.

Jim Dempsey

Leave a Comment

Please sign in to add a comment. Not a member? Join today