Wrap-@'s in A-ZPL

This page gives a summary of how to use A-ZPL's new "Wrap-@" operator. This is a means of implementing periodic boundary conditions without allocating boundary data values (either explicitly or implicitly) or using the wrap statement. If you find any bugs or inconsistencies in our implementation of the wrap-@ operator, pleae let us know at zpl-bugs@cs.washington.edu.

Wrap-@ Overview

A very common idiom in ZPL programs is to use wraps to implement boundary conditions. For example:

   program periodic;

   config var n:integer = 4;

   region R = [1..n,1..n];

   direction north = [-1, 0];
             south = [ 1, 0];
             east  = [ 0, 1];
             west  = [ 0,-1];

   var A:[R] double;

   
   procedure periodic();
   [R] begin
         A := ...;
         [east of R] wrap A;
         [west of R] wrap A;
	 [north of R] wrap A;
	 [south of R] wrap A;
	 
         A := A@east + A@west + A@north + A@south;
       end;

To make this common idiom more efficient and concise, a new operator, wrap-@ (@^) has been added which causes the @ operator to wrap around to the other side of the array when it falls off of the array's declared elements. Thus for example, the main procedure of the above program could be rewritten:

   procedure periodic();
   [R] begin
         A := ...;

         A := A@^east + A@^west + A@^north + A@^south;
       end;

The result is a code that is cleaner, more concise, and more efficiently executed in the absence of advanced optimizations.

Note that in cases where a reference does not spill over an array's declared boundaries, the wrap-@ behaves just as normal. For example:

   [1..10,5] A := A@^east;

is the same as:

   [1..10,5] A := A@east;

given the above declarations due to the fact that the references to the east are within the declared bounaries of A.

Note furthermore that wrap-@ does not make the wrap statement useless, due to the fact that the wrap statement can apply to regions other than those immediately adjacent to an array's declared region and can be used to set up boundaries for use by operators other than @.

A Note on Syntax

We have yet to come up with a syntax for wrap-@'s that is sufficiently mnemonic to please us, and so have adopted @^ for the time being as a placeholder. Any suggestions would be much appreciated.

Further Questions?

If you have further questions about the wrap-@ operator in A-ZPL, please don't hesitate to contact us at zpl-info@cs.washington.edu.