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

openMP - Handling global variables in fortran

Ajay_N_
Beginner
1,499 Views

Hi,
I am trying to parallelize a code that is already written and contains close to 102 subroutines in the function I am trying to parallelize. In the process I saw that there were many global variables that each subroutine access and this is not good for parallel programming.

I have two questions:
1 - Under such scenarios, what is the best way to fix this? Do I make the variables an array so that it can be a function of the thread? Its quite tideous though and I am looking for some good work around
2 - Is there any way I can detect global variables that my thread is trying to access without reverse engineering the code a lot ?

- Ajay

0 Kudos
4 Replies
TimP
Honored Contributor III
1,499 Views

Making arrays is a possible solution, but it would be better if the data can be made local with private effect.

A possible way to work up toward OpenMP is to turn on /Qparallel and the associated diagnostics then replace parallels with OpenMP incrementally where it shows promise.

Intel Inspector was originally intended to facilitate finding read/write conflicts among threads even when omp parallel is applied without full analysis of conflicts.  You might try it on 30 day trial to see if it looks helpful in the current form.

0 Kudos
Martyn_C_Intel
Employee
1,499 Views

I think when you are starting, Intel Advisor XE is the more appropriate tool. Intel Inspector XE is powerful,  but better suited to debugging after you've done the basic initial work. See http://software.intel.com/en-us/videos/avoid-common-fortran-parallelization-mistakes-with-the-help-of-intel-advisor-xe

The important distinction is between those variables that can be shared between threads, and those for which each thread needs a private copy (whether they are global or local). In the routine with the OpenMP constructs, you can use PRIVATE and SHARED clauses. If you need private copies of global variables, you can use a threadprivate directive for a common block or for module variables. If you're not already familiar with this, I suggest you read an introduction or tutorial for OpenMP.  For a subroutine without OpenMP directives that might be called from within a parallel region, local variables including arrays will be placed on the stack to make them threadsafe if you compile with /Qopenmp (and don't use SAVE statements, /Qsave, or data statements that imply SAVE). /Qopenmp effectively sets /Qauto.

Another reference for Fortran tips for OpenMP is  http://software.intel.com/en-us/articles/threading-fortran-applications-for-parallel-performance-on-multi-core-systems/

0 Kudos
Ajay_N_
Beginner
1,499 Views

Thanks, I am trying to use these tools for my project now. However after I have installed the tool the build is consistently failing with the error:

1>Linking...
1>LINK : fatal error LNK1104: cannot open file 'ifconsol.lib'

This happened after I have installed the intel inspector and advisor tools. Any idea why this should happen?

 

- Ajay

0 Kudos
Ajay_N_
Beginner
1,499 Views

Nevermind, for some reason I had to add the library location to additional dependencies and it worked fine. 

0 Kudos
Reply