local

Create local copy of variable for iteration. More...

array local (const array &variable)
 Indicate when a variable is unique to each iteration, i.e. More...
 

Detailed Description

Create local copy of variable for iteration.

Function Documentation

array af::local ( const array &  variable)

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, ArrayFire thinks you are subscripting into B shared by all iterations:

int n = 5;
array A = seq(n), C = constant(0,A.dims(), A.type());
gfor (array ii, n) {
array B = A; // mistakenly only sharing (fake copy)
B(ii) = 0; // write zeros in positions '1:n' of original matrix
C(ii) = sum(B);
}
print(C); // all zeros

Compare that to indicating local copies:

int n = 5;
array A = seq(n), D = constant(0,A.dims(), A.type());
gfor (array ii, n) {
array B = local(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
}
print(D); // all unique summations

Produces:

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