Azzera filtri
Azzera filtri

How to apply parallel.pool.constant?

5 visualizzazioni (ultimi 30 giorni)
Amy
Amy il 11 Ott 2017
Risposto: Edric Ellis il 12 Ott 2017
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

Risposte (1)

Edric Ellis
Edric Ellis il 12 Ott 2017
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.

Categorie

Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by