Ocean Modeling Discussion

ROMS/TOMS

Search for:
It is currently Tue Sep 25, 2018 12:05 am




Post new topic Reply to topic  [ 3 posts ] 

All times are UTC

Author Message
PostPosted: Wed Jul 11, 2018 6:45 pm 
Offline

Joined: Thu Jan 21, 2016 6:06 pm
Posts: 3
Location: Rutgers University
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


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 11, 2018 6:53 pm 
Offline
User avatar

Joined: Wed Jul 02, 2003 5:29 pm
Posts: 3502
Location: IMS/UAF, USA
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:
Code:
      IF (Master) CALL get_date (date_str)
      CALL mp_bcasts (1, model, date_str)
Or you can have each process update independently.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 11, 2018 7:25 pm 
Offline

Joined: Thu Jan 21, 2016 6:06 pm
Posts: 3
Location: Rutgers University
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

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:
Code:
      IF (Master) CALL get_date (date_str)
      CALL mp_bcasts (1, model, date_str)
Or you can have each process update independently.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group