|
From: Max R. <max...@un...> - 2011-04-04 14:48:30
|
Hi,
We are examining the Jacobi Iteration example
("examples/programs/jacobi.chpl") and have a specific
performance-relevant question regarding pointers and if they exist or
how to get something similar to that.
In the jacobi example (or many stencil-based problems), you have a
working set of data, and you calculate a point p, from points in the
neighborhood of p and set a value in a "new" array such as:
> forall ij in ProblemSpace do
> XNew(ij) = (X(ij+north) + X(ij+south) + X(ij+east) + X(ij+west)) / 4.0;
Now, as this iteration moves forward, we need to update the "working"
and "new" arrays every iterations, which is done in the example with an
implicit memory copy:
> // update X with next approximation
> X[ProblemSpace] = XNew[ProblemSpace];
If we were writing this in C, we would simply swap the pointers, and
save ourselves the memory copy.
> float* temp;
> temp = X; // assume X and XNew are of type float*
> X = XNew;
> XNew = temp;
Is there good way to do this in Chapel? I thought of a workaround where
we use a single large array and alternate having X be at the beginning
of it, or half-way down (with XNew visa-versa) so that there is no
memory transfer, but this seems a bit of a hack.
thanks,
Max
|