I was using the following code to access elements of the physical boundary in a global array A irrespective of the number of locales the code runs on. For this, I was following the Modifying Exterior Ghost Cells section in Chapel documentation on Stencil distribution
import StencilDist.stencilDist;
config const n = 10;
const Space = {1..n};
const Dist = Space dmapped new stencilDist(Space, fluff=(2,), periodic=false);
var A: [Dist] real;
// Initialize interior values
forall i in A.domain do
A[i] = i:real;
// Print full array including ghost cells
writeln("Full array including ghost cells:");
for i in A.domain do
writeln("A[", i, "] = ", A[i]);
// Access and print the ghost boundaries
const physical_ghostLeft = A.domain.boundaries(0, -1);
const physical_ghostRight = A.domain.boundaries(0, 1);
writeln("\nLeft ghost boundary:");
for i in physical_ghostLeft do
writeln("A[", i, "] = ", A[i]);
writeln("\nRight ghost boundary:");
for i in physical_ghostRight do
writeln("A[", i, "] = ", A[i]);
However, compiling this code gives me the following error:
stencil-demo.chpl:19: error: unresolved call 'StencilDom(1,int(64),one,false).boundaries(0, -1)'
stencil-demo.chpl:19: note: because no functions named boundaries found in scope
I'm not sure if this is the correct way to use this procedure. I would appreciate any help in this regard.
Apologies for shooting in the dark. The following changes made your code compile for me:
import --> use
A.domain.boundaries(....) --> A.boundaries() // no arguments
print out the values yielded by this iterator directly
use StencilDist;
config const n = 10;
const Space = {1..n};
const Dist = Space dmapped new stencilDist(Space, fluff=(2,), periodic=false);
var A: [Dist] real;
// Initialize interior values
forall i in A.domain do
A[i] = i:real;
// Print full array including ghost cells
writeln("Full array including ghost cells:");
for i in A.domain do
writeln("A[", i, "] = ", A[i]);
// Access and print the ghost boundaries
const physical_ghostLeft = A.boundaries();
const physical_ghostRight = A.boundaries();
writeln("\nLeft ghost boundary:");
for a in physical_ghostLeft do
writeln(a);
writeln("\nRight ghost boundary:");
for a in physical_ghostRight do
writeln(a);
From the module doc: "This iterator yields a tuple where the first component is the ghost cell element to be modified, and the second component is a tuple indicating the side on which this ghost cell lives. This direction tuple will contain values in the range -1..1."
@vass Thanks a lot! Following your suggestion, the below code now compiles. But nothing gets printed in the for loop using the iterator returned by boundaries()
Since I was creating 2 fluff cells, I was expecting 4 prints (2 on each side).
import StencilDist.stencilDist;
import StencilDist.boundaries;
config const n = 10;
const Space = {1..n};
const Dist = Space dmapped new stencilDist(Space, fluff=(2,), periodic=false);
var A: [Dist] real;
// Initialize interior values
forall i in A.domain do
A[i] = i:real;
// Print full array including ghost cells
writeln("Full array including ghost cells:");
for i in A.domain do
writeln("A[", i, "] = ", A[i]);
A.updateFluff();
// Access and print the ghost boundaries
writeln("\nGhost boundaries:");
for (val, edge) in A.boundaries() do
writeln((val, edge));
To clarify, do you really want this stencil-distributed array to be periodic? If not, you could just write directly to those indices:
use StencilDist;
config const n = 10;
const Space = {1..n};
const Dist = Space dmapped new stencilDist(Space, fluff=(2,), periodic=false);
var A: [Dist] real;
// Initialize interior values
forall i in A.domain do
A[i] = i:real;
const Outer = Space.expand(2);
// For ghost cells, set to -1.0
for i in Outer {
// Note 'A.domain.contains(i)' includes ghost cells, so we use 'Space'
if !Space.contains(i) {
A[i] = -1.0;
}
}
A.updateFluff();
// Print full array including ghost cells
writeln("Full array including ghost cells:");
for i in Outer do
writeln("A[", i, "] = ", A[i]);
@benharsh Awesome! I guess what I wanted was things to be periodic b default with the ability to be changed. I can mix your code and the one I previously had to achieve precisely that. This works. Thanks a lot!