MATLAB PARALLEL COMPUTING TOOLBOX - S Guide de l'utilisateur Page 49

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 656
  • Table des matières
  • DEPANNAGE
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 48
Variables and Transparency in parfor-Loops
2-21
temp = struct();
temp.myfield1 = rand();
temp.myfield2 = i;
end
parfor i = 1:4
temp = struct('myfield1',rand(),'myfield2',i);
end
Slicing Structure Fields
You cannot use structure fields as sliced input or output arrays in a parfor-loop; that is,
you cannot use the loop variable to index the elements of a structure field. For example,
in the following code both lines in the loop generate a classification error because of the
indexing:
parfor i = 1:4
outputData.outArray1(i) = 1/i;
outputData.outArray2(i) = i^2;
end
The workaround for sliced output is to employ separate sliced arrays in the loop, and
assign the structure fields after the loop is complete, as shown in the following code.
parfor i = 1:4
outArray1(i) = 1/i;
outArray2(i) = i^2;
end
outputData = struct('outArray1',outArray1,'outArray2',outArray2);
The workaround for sliced input is to assign the structure field to a separate array before
the loop, and use that new array for the sliced input.
inArray1 = inputData.inArray1;
inArray2 = inputData.inArray2;
parfor i = 1:4
temp1 = inArray1(i);
temp2 = inArray2(i);
end
Scalar Expansion with Sliced Outputs
You cannot use scalar expansion to define a set of values assigned to a sliced output
array. For example, the following code attempts to expand the value idx for assignment
to each element of the vector defined by x(:,idx); this generates an error.
Vue de la page 48
1 2 ... 44 45 46 47 48 49 50 51 52 53 54 ... 655 656

Commentaires sur ces manuels

Pas de commentaire