Why can't my function write to a file when executed in parallel? (parfeval)
이전 댓글 표시
"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
Kojiro Saito
2022년 5월 31일
2.のときのparfevalの出力はどうなっていますか?
f = parfeval(@timestamp,0);
として、f.Errorにメッセージが書かれていないでしょうか?
Takafumi Shiino
2022년 6월 1일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!