diff --git a/src/MultiTypeSymEntry.chpl b/src/MultiTypeSymEntry.chpl index 4718a1574..c75c6340f 100644 --- a/src/MultiTypeSymEntry.chpl +++ b/src/MultiTypeSymEntry.chpl @@ -727,13 +727,6 @@ module MultiTypeSymEntry return new shared SparseSymEntry(a, size, matLayout, eltType); } - proc makeSparseArray(size, type eltType, param matLayout) { - const dom = {1..size, 1..size}; - var spsDom: sparse subdomain(dom) dmapped new dmap(new CS(compressRows=(matLayout==layout.CSR))); - var A: [spsDom] eltType; - return A; - } - class GeneratorSymEntry:AbstractSymEntry { type etype; diff --git a/src/SparseMatrix.chpl b/src/SparseMatrix.chpl index 9b00ee037..e42cbe810 100644 --- a/src/SparseMatrix.chpl +++ b/src/SparseMatrix.chpl @@ -6,7 +6,7 @@ module SparseMatrix { use CommAggregation; // Quick and dirty, not permanent - proc fillSparseMatrix(ref spsMat, const A: [?D] ?eltType) throws { + proc fillSparseMatrix(ref spsMat, const A: [?D] ?eltType, param l: layout) throws { if A.rank != 1 then throw getErrorWithContext( msg="fill vals requires a 1D array; got a %iD array".format(A.rank), @@ -31,267 +31,257 @@ module SparseMatrix { moduleName=getModuleName(), errorClass="IllegalArgumentError" ); - for((i,j), idx) in zip(spsMat.domain,A.domain) { - spsMat[i,j] = A[idx]; + + // Note: this simplified loop cannot be used because iteration over spsMat.domain + // occures one locale at a time (i.e., the first spsMat.domain.parDom.localSubdomain(Locales[0]).size + // values from 'A' are deposited on locale 0, and so on), rather than depositing + // them row-major or column-major globally + // for ((i,j), idx) in zip(spsMat.domain,A.domain) { + // spsMat[i,j] = A[idx]; + // } + + if l == layout.CSR { + var idx = 0; + for i in spsMat.domain.parentDom.dim(0) { + for j in spsMat.domain.parentDom.dim(1) { + if spsMat.domain.contains((i, j)) { + spsMat[i,j] = A[idx]; + idx += 1; + } + } + } + } else { + var idx = 0; + for j in spsMat.domain.parentDom.dim(1) { + for i in spsMat.domain.parentDom.dim(0) { + if spsMat.domain.contains((i, j)) { + spsMat[i,j] = A[idx]; + idx += 1; + } + } + } } } + proc getGrid(const ref spsMat) where spsMat.chpl_isNonDistributedArray() { + return reshape([here,], {0..<1, 0..<1}); + } + + proc getGrid(const ref spsMat) where !spsMat.chpl_isNonDistributedArray() { + return spsMat.domain.targetLocales(); + } + + proc getLSD(const ref spsMat) where spsMat.chpl_isNonDistributedArray() { + return spsMat.domain; + } + + proc getLSD(const ref spsMat) where !spsMat.chpl_isNonDistributedArray() { + return spsMat.domain.localSubdomain(); + } + + proc getLSA(const ref spsMat, rowBlockIdx: int, colBlockIdx: int) const ref + where spsMat.chpl_isNonDistributedArray() + { + return spsMat; + } + + proc getLSA(const ref spsMat, rowBlockIdx: int, colBlockIdx: int) const ref + where !spsMat.chpl_isNonDistributedArray() + { + return spsMat.getLocalSubarray(rowBlockIdx, colBlockIdx); + } + /* Fill the rows, cols, and vals arrays with the non-zero indices and values from the sparse matrix in row-major order. */ proc sparseMatToPdarrayCSR(const ref spsMat, ref rows, ref cols, ref vals) { - // serial algorithm (for reference): - for((i,j), idx) in zip(spsMat.domain,0..) { - rows[idx] = i; - cols[idx] = j; - vals[idx] = spsMat[i, j]; - } - - // // matrix shape - // const m = spsMat.shape[0], - // n = spsMat.shape[1]; - - // // info about matrix block distribution across a 2D grid of locales - // const grid = spsMat.domain.targetLocales(), - // nRowBlocks = grid.domain.dim(0).size, - // nColBlocks = grid.domain.dim(1).size; - - // // number of non-zeros in each row, for each column-block of the matrix - // // TODO: use zero-based indexing for SparseSymEntry - // const nnzDom = blockDist.createDomain({1..m, 0..