Hello Again,

Working through some basic linear algebra to get some experience with
Chapel. I specifically wanted to use and think about Domains, data
locality, chplvis, etc.

- A is a square matrix (dimension x dimension), where each row is
cyclically distributed to the locales
- B is a vector (dimension), replicated on each locale
- C is a vector (dimension), each value is cyclically distributed to match
the row of A

That seemed like the logical initial distributions (may or may not be
best?). I set all values of A and B to 1, that way each value in C is just
the dimension. The problem is when I use 2 locales, the second one is
mainly doing communication (used chplvis, nice tool by the way). I know the
values are local, by doing (for A, B, and C):

forall a in A do a = a.locale.id;
writeln(A);

The entire code:

[code]
// Matrix Vector Multiply
// \mat(A) \times B = C

use BlockCycDist;
use ReplicatedDist;
use VisualDebug;

config const tasksPerLocale : int = 1;

// The problem dimensions
config const dimension : int = 10;

// MatrixDomain, rows distributed to locales using BlockCyclic Distribution
const MatrixSpace = {0..#dimension, 0..#dimension};
const MatrixDomain : domain(2) dmapped BlockCyclic(startIdx =
MatrixSpace.low, blocksize = (1, dimension)) = MatrixSpace;

var A : [MatrixDomain] int;

// VectorDomain
// -> B is replicated across locales
// -> C is reduced, but BlockCylic similar to the MatrixDomain
const VectorSpace = {0..#dimension};
const VectorReplicatedDomain : domain(1) dmapped ReplicatedDist() =
VectorSpace;
const VectorCyclicDomain : domain(1) dmapped BlockCyclic(startIdx =
VectorSpace.low, blocksize = 1) = VectorSpace;

var B : [VectorReplicatedDomain] int;
var C : [VectorCyclicDomain] int;

// Initialize variables
forall a in A do a = 1;
forall b in B do b = 1;

startVdebug("chplvis");

// Distribute tasks
forall (i, c) in zip({0..#dimension}, C(..)) {
    forall (j, a) in zip({0..#dimension}, A(i, ..)) with ( + reduce c ) {
        c += a * B(j);
    }
}

stopVdebug();

// Print results
forall c in C do writeln(c);
[/code]

Am I way off the mark here?

- Barry

-- 
Barry E Moore II, PhD
E-mail: [email protected]

Assistant Research Professor
Center for Simulation and Modeling
University of Pittsburgh
Pittsburgh, PA 15260
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to