Why can't my function write to a file when executed in parallel? (parfeval)
Ältere Kommentare anzeigen
"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 Kommentare
Kojiro Saito
am 31 Mai 2022
2.のときのparfevalの出力はどうなっていますか?
f = parfeval(@timestamp,0);
として、f.Errorにメッセージが書かれていないでしょうか?
Takafumi Shiino
am 1 Jun. 2022
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!