Why can't my function write to a file when executed in parallel? (parfeval)
Afficher commentaires plus anciens
"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 commentaires
Kojiro Saito
le 31 Mai 2022
2.のときのparfevalの出力はどうなっていますか?
f = parfeval(@timestamp,0);
として、f.Errorにメッセージが書かれていないでしょうか?
Takafumi Shiino
le 1 Juin 2022
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!