MATLAB PARALLEL COMPUTING TOOLBOX - S Guía de usuario Pagina 468

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 656
  • Tabla de contenidos
  • SOLUCIÓN DE PROBLEMAS
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 467
11 Functions — Alphabetical List
11-124
Examples
Create a 2-by-22 codistributed array among four workers, and view the global indices on
each lab:
spmd
C = zeros(2,22,codistributor1d(2,[6 6 5 5]));
if labindex == 1
K = globalIndices(C,2) % returns K = 1:6.
elseif labindex == 2
[E,F] = globalIndices(C,2) % returns E = 7, F = 12.
end
K = globalIndices(C,2,3) % returns K = 13:17.
[E,F] = globalIndices(C,2,4) % returns E = 18, F = 22.
end
Use globalIndices to load data from a file and construct a codistributed array
distributed along its columns, i.e., dimension 2. Notice how globalIndices makes the
code not specific to the number of workers and alleviates you from calculating offsets or
partitions.
spmd
siz = [1000,1000];
codistr = codistributor1d(2,[],siz);
% Use globalIndices to figure out which columns
% each worker should load.
[firstCol,lastCol] = globalIndices(codistr,2);
% Call user-defined function readRectangleFromFile to
% load all the values that should go into
% the local part for this worker.
labLocalPart = readRectangleFromFile(fileName, ...
1,siz(1),firstCol,lastCol);
% With the local part and codistributor,
% construct the corresponding codistributed array.
C = codistributed.build(labLocalPart,codistr);
end
See Also
getLocalPart | labindex
Vista de pagina 467
1 2 ... 463 464 465 466 467 468 469 470 471 472 473 ... 655 656

Comentarios a estos manuales

Sin comentarios