Parallel_Function error 598 and fprintf
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Thomas Ibbotson
2011-1-21
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?
回答(3 个)
Walter Roberson
2011-1-21
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 个评论
Walter Roberson
2011-1-22
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
2011-1-22
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 个评论
Walter Roberson
2011-1-24
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!