How to apply parallel.pool.constant?

조회 수: 5 (최근 30일)
Amy
Amy 2017년 10월 11일
답변: Edric Ellis 2017년 10월 12일
Hello,
I use a parfor-loop and I would like to reduce the amounts of bytes sent between the workers. I hope this is possible by using parallel.pool.constant, but I am wondering how to apply this.
Currently 50000 bytes are sent from/to each of the workers. The input-data and output-data that are changing are only 816 bytes. All the other data that is accessed during the calculations stays the same throughout the calculations.
The structure of my program is as follows:
  • Inside my parfor-loop, I use ode-solver ode15s.
  • odes15s calls the file with the differential equations. Inside this file, a .mat-file is being called that contains non-changing parameters.
More specifically:
1. This is my parforloop:
parfor k=1:partot
tmp = my_mfile(inputvector(k,:),inputscalar,K1,K2);
outputvector(:,k) = tmp;
end
2. My_mfile.m contains:
function [outputvector]=mfile(inputvector(k,:),inputscalar,K1,K2)
[~,outputvector] = ode15s(@(~,C0)diff_eqns_mfile(inputscalar, inputvector,'parameters.mat'),[0 inputscalar], inputvector);
end
3. diff_eqns_mfile.m looks like:
function F = diff_eqns_mfile.m(~,inputscalar,parameters)
load(parameters.mat);
F(1) = * long equation *
F(2) = * long equation *
...
end
Any suggestions or comments are welcome!
Best, Amy

답변 (1개)

Edric Ellis
Edric Ellis 2017년 10월 12일
A parallel.pool.Constant only really helps if you're calling multiple parfor loops - it stops you having to transfer constant data multiple times for each loop. In your case, inputvector is a sliced input, and this is already efficient in terms of data transfer.
The only possible benefit you could get from parallel.pool.Constant is if K1 and K2 are large, and you've got an outer loop over the parfor loop - in that case, you could avoid sending K1 and K2 to the workers multiple times.

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by