How to distinctly assign job and get the result of each worker using "parfor"?

2 ビュー (過去 30 日間)
Bill Masters
Bill Masters 2020 年 5 月 6 日
コメント済み: Bill Masters 2020 年 5 月 7 日
Hello,
I'm using parallel computing toolbox in order to parallelize my computation. there is a need for assigning an identical job with different data to each worker and after the computation of workers is done, I need to distinctly get each woker's result in the client process and use each of them for another purpose. how can I do this?!
thanks

採用された回答

Edric Ellis
Edric Ellis 2020 年 5 月 7 日
This sounds more like a job for spmd . Read more about that here: https://www.mathworks.com/help/parallel-computing/spmd.html . Here's an extremely simple example:
spmd
myOutput = 2 * labindex; % labindex has a different value on each worker
end
myOutput{3} % gets the value from the 3rd worker
  4 件のコメント
Bill Masters
Bill Masters 2020 年 5 月 7 日
suppose that I have 4 workers and 4 input data as well,
conceptually I need the work be done as below, but I don't know how to organize it:
spmd
myOutput=func(data1,data2,data3,data4);
%func is a function defined before, to be done seperately
% by each worker with their own data in parallel
end
myOutput{1}
myOutput{2}
...
Bill Masters
Bill Masters 2020 年 5 月 7 日
the problem is solved, thank you for your time.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDistributed Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by