In parfor, how to create a temp folder for every worker
11 次查看(过去 30 天)
显示 更早的评论
Hallo all,
i asked a question here: http://www.mathworks.de/matlabcentral/answers/83158-workers-in-parfor-writing-to-files-of-a-simulink-model
Summarized is: I use parfor to running a simulink model, after running of the model come out some temp files. But because multiple workers attempt to write to the same file, that can sometimes an error results. So i remove these files every time after running of this model. But by next time this model is called, some files will compiled and run again (e.g. some C files), so that the running time of this model is very long. (I don't know well about simulink, so maybe i described not exactly)
My idea is to create a temp folder for each worker, so that there is no conflict between workers. And all files for the model will only once installed at the beginning it's called. So will time saved.
(update1) i wrote code like this
tmpdir = tempname
mkdir(tmpdir)
cd(tmpdir)
sim('XRSimWWPen01');
so there is a different folder for each worker and each loop. What i want to do is, that i create only four folder(four core) for four workers.
0 个评论
采纳的回答
Friedrich
2013-7-26
Hi,
I would use the process ID for that:
matlabpool open 4
parfor i=1:20
w=getCurrentWorker;
mydir = fullfile(tempdir,['myfolder',num2str(w.ProcessId)]);
disp(mydir)
end
(Note: tempdir is a MATLAB function not the variable from your example)
0 个评论
更多回答(1 个)
Matt J
2013-7-26
编辑:Matt J
2013-7-26
so there is a different folder for each worker and each loop.
You can do this using SPMD, but I don't think you should do it through PARFOR, since operations within a parfor loop are expected to be worker-independent. You can't count on parfor loop iterations always being assigned to the same worker or done in the same order each time the loop is called.
So maybe you can do something like this, instead:
spmd
mkdir(['myfolder' num2str(labindex)])
end
spmd
back=cd;
cd(['myfolder' num2str(labindex)]);
%do stuff...
cd(back)
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!