Hi all,
I have a question about how global variables are treated when running ROMS in parallel mode.
I'm working on parallelizing a new module I wrote to treat ROMS SOURCES terms. In this module I defined some global variables that are shared among several subroutines. These variables are changed each time the main function is called.
I wonder if anyone know that when running in parallel mode, if these variables are sheared among all threads, or each of them will have a separate memory location. For example, if X is an integer and is set to 0 at the beginning of a subroutine, and somewhere in the subroutine we have X=X+1. When this subroutine is executed in N tiles, will the final value of X be N or 1?
If X is sheared among threats I imagine there will be issues with my application. If so, is there any common way to privatize these global variables?
Best,
Chuning
Global variables in parallel mode
Re: Global variables in parallel mode
First of all, there's more than one way to run a parallel code. Are you using OpenMP or MPI? I only use MPI and only really understand how it works - OpenMP is different for these questions. OpenMP is when they talk about threads.
For MPI, each process has its own memory and its own copy of each variable. If your master process updates X and wants the rest to know about it, it will have to broadcast the updated value. An example in inp_par.F:Or you can have each process update independently.
For MPI, each process has its own memory and its own copy of each variable. If your master process updates X and wants the rest to know about it, it will have to broadcast the updated value. An example in inp_par.F:
Code: Select all
IF (Master) CALL get_date (date_str)
CALL mp_bcasts (1, model, date_str)
Re: Global variables in parallel mode
Hi Kate,
Thanks for the quick response.
In my case I want to keep variables independent among tiles. I'm using MPI, so at least the cases I was running was solid. Nevertheless, I plan to rewrite the code to cope with the shared memory case.
I had this question because earlier today I read somewhere that OpenMP shares global variables among threads. I then checked the ROMS source code and it seems that only parameters are globalized, and global variables are avoided. Not sure if it is intentional or not.
Cheers,
Chuning
Thanks for the quick response.
In my case I want to keep variables independent among tiles. I'm using MPI, so at least the cases I was running was solid. Nevertheless, I plan to rewrite the code to cope with the shared memory case.
I had this question because earlier today I read somewhere that OpenMP shares global variables among threads. I then checked the ROMS source code and it seems that only parameters are globalized, and global variables are avoided. Not sure if it is intentional or not.
Cheers,
Chuning
kate wrote:First of all, there's more than one way to run a parallel code. Are you using OpenMP or MPI? I only use MPI and only really understand how it works - OpenMP is different for these questions. OpenMP is when they talk about threads.
For MPI, each process has its own memory and its own copy of each variable. If your master process updates X and wants the rest to know about it, it will have to broadcast the updated value. An example in inp_par.F:Or you can have each process update independently.Code: Select all
IF (Master) CALL get_date (date_str) CALL mp_bcasts (1, model, date_str)