zhengruifeng commented on pull request #30468:
URL: https://github.com/apache/spark/pull/30468#issuecomment-732093851
GEMV:
```
val ratings = srcFactorsBlocked.crossJoin(dstFactorsBlocked)
.as[(Array[Int], Array[Float], Array[Int], Array[Float])]
.mapPartitions { iter =>
var buffer: Array[Float] = null
val pq = new BoundedPriorityQueue[(Int,
Float)](num)(Ordering.by(_._2))
iter.flatMap { case (srcIds, srcMat, dstIds, dstMat) =>
require(srcMat.length == srcIds.length * rank)
require(dstMat.length == dstIds.length * rank)
val m = srcIds.length
val n = dstIds.length
if (buffer == null || buffer.length < n) {
buffer = Array.ofDim[Float](n)
}
Iterator.range(0, m).flatMap { i =>
BLAS.f2jBLAS.sgemv("T", rank, n, 1.0F, dstMat, 0, rank,
srcMat, i * rank, 1, 0.0F, buffer, 0, 1)
pq.clear()
var j = 0
while (j < n) { pq += dstIds(j) -> buffer(j); j += 1 }
val srcId = srcIds(i)
pq.iterator.map { case (dstId, value) => (srcId, dstId, value) }
}
} ++ {
buffer = null
pq.clear()
Iterator.empty
}
}
```
Then I switch to GEMV, which brings siginificent speedup. The size of
`buffer` is reduce to **n**.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]