Output file names with [conflict]

2 views (last 30 days)
Jeremy Hendrix
Jeremy Hendrix on 29 Apr 2015
Answered: Edric Ellis on 29 Apr 2015
I have a simulation that runs a lot of iterations at multiple design points. There are three nested loops to run through the complete set of configurations. Each one is independent, so to speed things up a bit I made the outer loop a parfor.
At the conclusion of each iteration of the innermost loop, the results are written out to a text file. The code looks like
FileIDResults = -1;
while FileIDResults == -1
FileIDResults = fopen('plus_plus_resources.txt', 'a');
end
fprintf(FileIDResults, '%3d, %6.5f, %6.5f, %6.5f \r\n', RunNumber, PlusPlusResourcesAlpha, DepartureRate, PlusPlusResourcesScore);
fclose(FileIDResults);
FileIDResults = -1;
This has always worked fine for me...but this time around I wound up with several output files
plus_plus_resources.txt plus_plus_resources [conflict].txt plus_plus_resources [conflict 1].txt
So at this point I have two questions: 1. Most immediately, can I just cat these together to get the complete output set? Or is there likely to be some overlap, or what? It took almost 48 hours to do the complete run, so I'd really like to not have to do it all over again.
2. I'm assuming this is because two workers tried to write to the file at the same time? If that's the case, is there a better way to handle the file control? I'd prefer not to have each worker write to its own file...but if that's the best way then so be it.
Thanks!

Answers (1)

Edric Ellis
Edric Ellis on 29 Apr 2015
The best way really is to have each worker write a separate file, especially if you're on Windows. The simplest way is to use the Worker Object Wrapper. There's an example in the help text there showing you how to do that.

Categories

Find more on Loops and Conditional Statements 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!