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

are include statements in subroutines safe for mutithreading?

William_G_
Beginner
386 Views

HI 

This may the the first of many questions about running or rewriting an application with

ThreadModel Free  ( the application works fine in ThreadModel Apartment)

I upgraded to visual fortran compiler XE 15.04.221 , but still using IA-32 build. 

 

I have read that COMMON blocks are a problem for multithreading because they can

lead to racing , is that correct??

So when now passing arrays between subroutines on the subroutine argument list

instead of in common blocks, does the use of include statements in subroutines

to dimension arrays on the subroutine argument list, or to dimension arrays

local to the subroutine cause racing, or is it threadsafe??  

Example

apple is an include with two parameter statements 

INTEGER, PARAMETER ::NPCOUNT =405

INTEGER,PARAMETER :: KREAL = 355

 

So then are these ok to do, the first subroutine dimensions an array on the calling list with the include parameter value,

the second subroutine dimensions a local array in the subroutine with the include parameter value....

SUBROUTINE Fort01(MAIN1)

INCLUDE 'apple'

DIMENSION MAIN1(NPCOUNT)

RETURN

END

 

and

SUBROUTINE Fort02(MAIN1,IMAIN1)

INCLUDE 'apple'

DIMENSION MAIN1(IMAIN1)

DIMENSION LOCAL1(KREAL)

RETURN

END 

Thanks

BIll

0 Kudos
2 Replies
Lorri_M_Intel
Employee
386 Views

Include files are read only at compile time, not run time and therefore a multi-threaded application has no effect one way or another.   And, PARAMETER statements have compile-time values ONLY, and also are not affected by a multi-threaded application.

The issue with COMMON variables in a multithreaded application is that they are global, shared data, and the "usual care" must be taken when multiple threads are accessing the SAME memory locations.

           Does this help at all?

                                   --Lorri

0 Kudos
William_G_
Beginner
386 Views

HI Lorri,

yes, I think your reply is helpful to me. Thank you.

I will continue organizing a few subroutines to see

how the application is behaving for me after the commons have been

eliminated, and see what happens next

 

thanks

bill

 

0 Kudos
Reply