log() much slower in parallel

9 次查看(过去 30 天)
I run a MATLAB parallel job using the local scheduler to increase performance of the calculation. However, my function is much slower in the parallel job compared to its serial execution. By profiling I found out that some operations take much more time in parallel tasks (e.g. calling the built-in function log() about 6 times more). Any idea why it is slower?
A simplified example, let us have the following three functions:
function par_test()
Scheduler = findResource('scheduler', 'type', 'local');
Job = createJob(Scheduler);
createTask(Job, @par_func, 1, {});
submit(Job);
waitForState(Job, 'finished')
OutputArgCell = getAllOutputArguments(Job);
pInfoVector = [OutputArgCell{:, 1}];
mpiprofile('viewer', pInfoVector);
destroy(Job);
end
function pInfo = par_func()
mpiInit;
mpiprofile on
par_calc()
pInfo = mpiprofile('info');
end
function par_calc()
U = unifrnd(0, 1, 10000, 10000);
R = log(U);
end
Run
>> par_test
to execute par_calc in one parallel task and generate a profile report.
Run
>> profile on
>> par_calc
>> profile viewer
to execute par_calc serially and generate a profile report. Compare the execution time of log().

采纳的回答

Walter Roberson
Walter Roberson 2012-11-15
log() is, I believe, normally automatically parallized over the number of available cores, even without the Parallel Computing Toolbox. If you have 6 cores then 1/6 of the work (approximately) would go to each core. But then when you run in parallel, each session only has access to a single core and cannot distribute the session's work.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Parallel Server 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by