How to pause matlab a specific amount of time between iterations??

Hello everyone,
I am using Matlab with a CFD solver. In my code there is this a for loop, and at the end of each iteration some job submitted to the solver. I want Matlab to wait till I get the solution files from the solver, and proceed to next iteration afterwards, with this newly created solution files. It takes more or less 3 hours to get the solution files so is there any way that I can pause Matlab for 3 hours between sucsessive iterations??
Any help would be appriciated. Thank you in advance.

 Accepted Answer

Yes, use a timer for this; not a while-loop!
What I would do is put a 'StartDelay' on the timer for say 2hrs and 45 minutes. Then check every 10s or whatever (The timer's 'Period'). Until the file is found or whatever else you are using to know when the CFD simulation is complete.
Then simply have the 'TimerFcn' stop the timer and the 'StopFcn' do whatever else you need to do.

7 Comments

Waiting until a file is found is a dangerous procedure: The file could be incomplete. This is a general problem, when one program should wait for the other and a reliable inter-process communication is not trivial.
In that case, try to fopen() the file and if it's open somewhere else, it shouldn't be touchable (at least on Windows).
Or even better, have the CFD simulator create a second file that is just a flag indicating that the first file is complete. When the flag file exists, the other should be all set...
@Sean: This is a good approach. Let's ask Walter, who has experiences with the existence of files written to a network drive. I think that it cannot be guaranteed, that the files are written from the memory cache to the disk in a specific order e.g. on NFS drives. Therefore I'm afraid it is cleaner to append a magic cookie to the output file as an End-of-file signal, e.g. a ^Z character or 'ready'. Then the existence of this cookie signals that the creation of the file is ready. However, I call this cleaner, but hesitate to claim it is clean. I'm not sure if this racing condition can be avoided completely, so finally I would use a TRY-CATCH and the output of a meaningful error message like "please try it again, perhaps a concurrent file access has...".
I wonder how Ceren calls this simulator. There might be a way to do it with batch() in PCT. Thus you would create a job. Then if it is a system call, or whatever else, we could wait for the job to complete, possibly?
Yes, Sean, this is a clean approach: Wait until the process has finished. Then you can be sure, that the process has finished :-)
But it kind of depends on how this intantiate the CFD suimulation. We're just guessing right now.
Guys thank you for all these commands, I am sending the jobs to the CFD solver with say "qsub batchfile_case1" command as you guess. I will try the suggestions and update status here :) Any other commands would be appriciated though.

Sign in to comment.

More Answers (2)

If you have Parallel Computing Toolbox, you can set up an integration with your cluster (I'm guessing it's PBS Pro or Torque), and you could use the batch() command to submit your job. You can then check the state of the job as it progresses through the queued, executing and finished stages. It might work for your situation.
If you don't have PCT, setting up the timer to look for the files or exit condition would be a nice and clean approach.
Ryan G
Ryan G on 31 Jan 2013
Edited: Ryan G on 31 Jan 2013
You could enter a while loop until you are able to retrieve the data.
You could also potentially use a timer object to test for solution files periodically and continue on once they are found.

Categories

Find more on Computational Fluid Dynamics (CFD) in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!