MATLAB PARALLEL COMPUTING TOOLBOX - S Podręcznik Użytkownika Strona 470

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
Przeglądanie stron 469
11 Functions — Alphabetical List
11-126
Examples
This example shows how to calculate the sum and maximum values for x among all
workers.
p = parpool('local',4);
x = Composite();
x{1} = 3;
x{2} = 1;
x{3} = 4;
x{4} = 2;
spmd
xsum = gop(@plus,x);
xmax = gop(@max,x);
end
xsum{1}
10
xmax{1}
4
This example shows how to horizontally concatenate the column vectors of x from all
workers into a matrix. It uses the same 4-worker parallel pool opened by the previous
example.
x{1} = [3;30];
x{2} = [1;10];
x{3} = [4;40];
x{4} = [2;20];
spmd
res = gop(@horzcat,x);
end
res{1}
3 1 4 2
30 10 40 20
This example shows how to use an anonymous function with gop to join character strings
with spaces between them. In this case, the strings are created from each worker’s
labindex value.
afun = @(a,b)[a,' ',b]
Przeglądanie stron 469
1 2 ... 465 466 467 468 469 470 471 472 473 474 475 ... 655 656

Komentarze do niniejszej Instrukcji

Brak uwag