Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Fortran OpenMP question

Greynolds__Alan
Beginner
602 Views
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
0 Kudos
3 Replies
Ron_Green
Moderator
602 Views
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
0 Kudos
Ron_Green
Moderator
602 Views
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
0 Kudos
jimdempseyatthecove
Honored Contributor III
602 Views

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
0 Kudos
Reply