LOCAL

From Jacket Wiki

Jump to: navigation, search
Back to Function List

Declare a variable local to each GFOR iteration

Usage

Jacket for M Language
    Supported Syntax
    
gfor i = 1:n
  a = local(i, A); % create local copy
  a(i) = 0; % each tile writes '0' in different position
  ...
gend
    

GFOR Supported

Yes

GCOMPILE Supported

No

Types Supported

-  GDOUBLE   GSINGLE   GLOGICAL   GINT32   GINT8   GUINT32   GUINT8   COMPLEX 

Types Not Supported

-

More Details

This function is available with Jacket development builds following 20 Dec 2011, and packaged in Jacket versions 2.1 and above.

Use LOCAL to indicate when a variable is unique to each iteration, i.e. each iteration has its own copy of the data for modification independent of other iterations.

For example, when using the equal sign, Jacket thinks you are subscripting into B shared by all iterations:

n = 5;
A = gsingle(1:n);
gfor ii = 1:n
  B = A; % fake copy
  B(ii) = 0; % write zeros in positions '1:n' of original matrix
  C(ii) = sum(B);
gend
C  % all zeros (==gzeros(1,n))

Compare that to indicating local copies:

A = gsingle(1:n);
gfor ii = 1:n
  B = local(ii,A); % create local copy
  B(ii) = 0;  % each tile has its own B with a different index zeroed out
  D(ii) = sum(B); % different sum for each tile
gend
D  % all unique summations

Produces:

C =
     0
     0
     0
     0
     0
D =
    14
    13
    12
    11
    10


See Also

GFOR

Views
Personal tools