use spmd in matlab (parallel) to apply a function to parts of vector -


i working in matlab parallel computing toolbox.

task

i have vector v. have 4 cores. want split vector on each core (so each core handles 1/4th of vector, assuming length(v) divisible 4) , apply function f() on each part.

so core 1: f1 = f(v belongs part 1)

and core 2: f2 = f(v belongs part 2)

and on.

then want gather results that, after have: f = "one vector containing elements of f1, , elements of f2, etc." on main core (root if wish, maybe matlab calls "client", not sure).

attempt

spmd      v_dist    = codistributed( v ); %split v onto cores     lpv       = getlocalpart( v_dist ); %this core's part ("my part")      f1        = f( lpv ); %apply f part of v      %i want piece outputs?     f_tmp     = codistributed( zeros(length(f1) * 4, 1) );      %get part of container want put output     f_tmp_lp  = getlocalpart( f_tmp );     %now put part of output here:     f_tmp_lp  = f1;      %and piece part      f_tmp     = codistributed.build( f_tmp_lp, getcodistributor( f_tmp ) );  end  %we should gather output on client? f = gather( f_tmp ); 

and?

this not work expected. right size of f, somehow seems happen "lpv" same piece given each core. not sure if issue.

help?

i have not done lot of matlab parallel programming. how accomplish task?

i think code pretty close, don't think need f_tmp. here's example:

v = 1:10; spmd     v_dist = codistributed(v);     lpv = getlocalpart(v_dist);     f1 = sqrt(lpv);     v2 = codistributed.build(f1, getcodistributor(v_dist)); end assert(isequal(gather(v2), sqrt(v))); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -