Why can't my function write to a file when executed in parallel? (parfeval)
Show older comments
"timestamp.m" doesn't work as expected when running in parallel.
1.file_path = 'C:\Users\user\Downloads\filename.txt'
ファイルパスが上記の時は正常に動作します。
It works fine.
2.file_path = 'C:\filename.txt'
ファイルパスが上記の時はファイルは作成されませんし、エラーもでません。
No files are created and no errors occur.
訂正:エラーはでていました。
K>> f.Error
ans =
ParallelException のプロパティ:
identifier: 'MATLAB:FileIO:InvalidFid'
message: 'ファイルの識別子が無効です。有効なファイルの識別子を生成するには fopen を使用してください。'
cause: {}
remotecause: {[1×1 MException]}
stack: [1×1 struct]
Correction: []
function functionname
...
f = parfeval(@timestamp,0)
...
end
timestamp.m
function timestamp
stat = true;
while(stat==true)
dt = datetime('now');
fileID = fopen(file_path,'a');
fprintf(fileID,'%s\n',datestr(dt));
fclose(fileID);
pause(5)
end
end
2 Comments
Kojiro Saito
on 31 May 2022
2.のときのparfevalの出力はどうなっていますか?
f = parfeval(@timestamp,0);
として、f.Errorにメッセージが書かれていないでしょうか?
Takafumi Shiino
on 1 Jun 2022
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!