In parfor, how to create a temp folder for every worker
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Friedrich
el 26 de Jul. de 2013
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 comentarios
Más respuestas (1)
Matt J
el 26 de Jul. de 2013
Editada: Matt J
el 26 de Jul. de 2013
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 comentarios
Ver también
Categorías
Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!