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

Answers (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 Comment

"idle" workers consuming 100% of the CPU resources for the whole process? Why?
Also, why is optional number of workers better in this case?

Sign in to comment.

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...

Categories

Find more on Parallel Computing in Help Center and File Exchange

Asked:

on 11 Nov 2015

Answered:

on 16 Sep 2016

Community Treasure Hunt

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

Start Hunting!