Hitting a memory issue with the below sparse matrix multiply routine.
Works fine for very large sparse very sparse matrices, but as the density of the matrices increases it grinds to a halt.
Looks like it leaking memory here.
kk <- (A.colPtrs(jj) to (A.colPtrs(jj + 1)-1)) // fails over here
def sparseMatrixMultiply(A:CSCMatrix[Double], B:CSCMatrix[Double]) = {
val n = B.cols
val Bvals = B.activeValuesIterator.toArray
val Avals = A.activeValuesIterator.toArray
val entries =
for {
j <- (0 to (n-1))/*.par*/
k <- (B.colPtrs(j) to (B.colPtrs(j + 1)-1))
jj = B.rowIndices(k)
kk <- (A.colPtrs(jj) to (A.colPtrs(jj + 1)-1)) // get stuck here
i = A.rowIndices(kk)
} yield {
println(s"$j $k $jj $kk $i ${Bvals(k)} ${Avals(kk)}")
(i, j, Bvals(k) * Avals(kk))
}
}
val coo = SparseMatrix.fromCOO(A.rows,B.cols, entries/*.seq*/)
//converting back to breeze CSCMatrix
new breeze.linalg.CSCMatrix[Double](coo.values, coo.numRows, coo.numCols, coo.colPtrs, coo.rowIndices)
}
I have tried splitting it into separate blocks, but iteration quickly runs out of memory at the same step
kk <- (A.colPtrs(jj) to (A.colPtrs(jj + 1)-1))
Is it just allocating memory too fast for GC ? or are all the range instances held onto until the for/yield completes
looking for insight into how the GC manages memory in for/yeild comprehension
Thanks