LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-13-2012, 10:46 AM   #1
ToscaBallerini
LQ Newbie
 
Registered: Sep 2012
Posts: 1

Rep: Reputation: Disabled
exchange data between two independent programs that run (almost) in parallel


Hi all,

I am new to Fortran and UNIX and I was wondering if you can give me some hints on how to solve the following:

I have a physical model that forces a biogeochemical model and creates netCDF files with plankton biomass data. This program
(Symphonie/Eco3M) is written in Fortran 77 and Fortran 90.

I have a high trophic level model that reads the netCDF files with the plankton biomass and uses them as food sources for fish. This program (OSMOSE) is written in Java. This model produces as outputs netCDF files with plankton mortality rates.

Currently, I use Symphonie/Eco3M to force OSMOSE. The two programs run independently and I run both of them with UNIX commands.

My task is to couple the two models. I have already written the
Fortran programs / subroutines that write and read the netCDF files
with the plankton biomass data and the plankton mortality rates. I
also have written a FAKE_Symphonie/Eco3M program in Fortran that I use for my experiments. This program writes netCDF files with plankton biomass data and reads netCDF files with plankton mortality rates, but does not run all the physics, just uses dummy values and runs very fast.

Now I am the point in which I have to actually couple the two models, so that:
1- Symphonie/Eco3M starts, runs for 15 days, writes the netCDF files
with plankton biomass data
2- Symphonie/Eco3M pauses
3- OSMOSE starts, reads the netCDF files with plankton biomass data,
uses them, runs for 15 days, writes netCDF files with plankton
mortality rates
4 - OSMOSE pauses
5 - Symphonie/Eco3M resume running
6 - Symphonie/Eco3M reads the netCDF data with plankton mortality
rates and uses them, runs for 15 days, writes the netCDF files with
plankton biomass data
7 - Symphonie/Eco3M pauses
8 - OSMOSE starts, reads the netCDF files with plankton mortality data, ....
and so on.

My question is: what command can I use for telling Symphonie/Eco3M
(written in Fortran 77 and Fortran 90) to pause at step 2 and wait
until when the files created by OSMOSE are available at step 5 and 6?

I have already chosen the names of the netCDF files that let the two
programs talk to each other, but I am not sure how to implement the
actual coupling between the two models.

Any suggestion would be highly appreciated.
Thanks in advance.

Tosca
 
Old 12-14-2012, 08:58 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Assuming you're working on Linux (since you're posting here...) the simplest thing I can think of that will work is to create a supervisor program that waits for the appropriate files to be created/updated via the inotify interface (see inotify(7)). The Symphonie/Eco3M programs OSMOSE both do their work and wait for a signal (e.g. SIGUSR1) from the supervisor program before continuing - the supervisor prompts when the appropriate files are available. Alternatively the programs themselves could watch via inotify(), but I'd think it best to have a supervisor program. Also, this has the disadvantage that if anything/one else modifies the files, the supervisor will think it's time to set the programs running again.

For a non-Linux application (or for one without the file modification problem) you could use semaphores (see sem_overview(7)), though this is a bit more work. Both applications will need to sem_post() to let the other one know it's done and then sem_wait() when they themselves are done, as opposed to just writing the files and waiting on aforementioned signal.

Last edited by JohnGraham; 12-14-2012 at 09:02 AM.
 
Old 12-14-2012, 11:17 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
OSMOSE starts, reads the netCDF files with plankton biomass data,
uses them, runs for 15 days, writes netCDF files with plankton
mortality rates
Is the writing interleaved with the reading, or does all the reading happen before the writing? If the the latter, I think if you just make the communication files fifos then the act of reading from them will pause the reader until data is written into them. You will probably also want to write the data to a real file as backup so unexpected interruption won't require starting everything from the beginning.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How encrypt a flash memory with independent run app ...? alirezaimi Linux - Security 3 09-19-2012 01:01 PM
user-specific , window manager independent startup programs? chessonly Linux - General 2 11-04-2006 08:32 AM
LXer: Independent Data and Formatting with Microformats LXer Syndicated Linux News 0 07-12-2006 04:21 AM
How do I run os independent software? DNC General 1 03-01-2006 04:16 PM
Is the Beowulf cluster used for only Parallel programs? Jack Poer Linux - General 6 10-11-2004 09:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration