Parallel_Function error 598 and fprintf
2 views (last 30 days)
Show older comments
I am running the parallel version of Genetic Algorithm and am running into some parallel issues. When I try to run on Parallel I recieve the error:
Error using ==> parallel_function at 598 Error in ==> filename at 63 Invalid format.
The line it refers to has a simple fprintf line where the file it is writing to is a simple text file:
fid=fopen('textfile_lab.txt','w');
i=1;
while i<=length(text)
Line 63 fprintf(fid,text{i});
i=i+1;
end
I have different text files for the four different labs that should be running simultaneously. Does any one have any ideas why this is coming up or how to fix it? Thank you.
7 Comments
Thomas Ibbotson
on 21 Jan 2011
Are you able to reduce your code to a minimal example that reproduces the problem you are seeing? Does the code work without using the parallel features?
Answers (3)
Walter Roberson
on 21 Jan 2011
This was also asked in the newsgroup. My answer there was:
You are writing to a fixed filename in each of the parallel threads. Sometimes when you try to open the file, another thread will already have the file open. In such a case the fopen will fail and return a negative number. You do not test for that possibility, and you use the negative number in fprintf. fprintf recognizes that the negative number cannot be a valid file identifier and tries to make sense of it as a format instead.
To this I would add that 'filename_lab.txt' is taken literally. Try
sprintf('filename_%d.txt,lab)
to get a lab-dependent name.
5 Comments
Walter Roberson
on 22 Jan 2011
Can you say more about the hidden characters? Are you able to obtain their value, such as by reading the file as binary and double() the string to determine the character values?
Walter Roberson
on 22 Jan 2011
Your present code
i=1;
while i<=length(text)
fprintf(fid,text{i});
i=i+1;
end
can be replaced entirely by
fprintf(fid, '%s\n', text{:});
(Assuming, that is, that text is not actually a 2D cell array of strings.)
0 Comments
Walter Roberson
on 24 Jan 2011
An answer from the newsgroup is that labindex is a constant for PARFOR and is only distinct for SMPD . A method to get the job id was shown in the newsgroup.
0 Comments
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!