How to efficiently use spmd to load multiple files and perform execution?

I have the following function to load and process files in parallel. I was expecting the number of cores used to 100% during run time should be limited by "maxNumAllowedByMem" argument. However, I was pleasantly surprised to see 100% on all available cores on my computer. Why is that? I thought I have only provided data to the first (maxNumAllowedByMem)th worker data?
function output = spmd_process_files(fileNameInCells, maxNumAllowedByMem)
spmd
if labindex<=maxNumAllowedByMem
outputBuffer = load(fileNameInCells{labindex});
outputBuffer = aLongProcessFunction(outputBuffer);
end
end
output = outputBuffer{1};
for nthComp = 2:maxNumAllowedByMem
output = someCombineFunction(output, outputBuffer{nthComp});
end
end

Antworten (2)

Under some circumstances, the "idle" workers can consume CPU resources while waiting for the other workers to get to the end of the spmd block. You could try using the optional number of workers argument to the spmd block:
spmd (maxNumAllowedByMem)
outputBuffer = ...;
end

1 Kommentar

Ethan
Ethan am 12 Nov. 2015
Bearbeitet: Ethan am 12 Nov. 2015
"idle" workers consuming 100% of the CPU resources for the whole process? Why?
Also, why is optional number of workers better in this case?

Melden Sie sich an, um zu kommentieren.

Ben Gislason
Ben Gislason am 16 Sep. 2016
Does anyone know of any good examples that show step by step of how to use spmd to load and process multiple data sets? Ethan shows the overall structure to do this but I am running into difficulty setting up the load data and run function aspects. Any help would be greatly appreciated...

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 11 Nov. 2015

Beantwortet:

am 16 Sep. 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by