You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "srowen (via GitHub)" <gi...@apache.org> on 2023/06/02 12:42:36 UTC
[GitHub] [spark] srowen commented on a diff in pull request #41384: [SPARK-43297][ML]Use scala parallel collection ParVector to accelarate LocalKMeans.
srowen commented on code in PR #41384:
URL: https://github.com/apache/spark/pull/41384#discussion_r1214326896
##########
mllib/src/main/scala/org/apache/spark/mllib/clustering/LocalKMeans.scala:
##########
@@ -38,15 +41,29 @@ private[mllib] object LocalKMeans extends Logging {
points: Array[VectorWithNorm],
weights: Array[Double],
k: Int,
- maxIterations: Int
+ maxIterations: Int,
+ threadNumber: Int
Review Comment:
Maybe make this an optional arg defaulting to -1 (meaning use max cores)?
##########
mllib/src/main/scala/org/apache/spark/mllib/clustering/LocalKMeans.scala:
##########
@@ -38,15 +41,29 @@ private[mllib] object LocalKMeans extends Logging {
points: Array[VectorWithNorm],
weights: Array[Double],
k: Int,
- maxIterations: Int
+ maxIterations: Int,
+ threadNumber: Int
): Array[VectorWithNorm] = {
val rand = new Random(seed)
val dimensions = points(0).vector.size
val centers = new Array[VectorWithNorm](k)
// Initialize centers by sampling using the k-means++ procedure.
centers(0) = pickWeighted(rand, points, weights).toDense
- val costArray = points.map(EuclideanDistanceMeasure.fastSquaredDistance(_, centers(0)))
+
+ val pointsParVector: Seq[VectorWithNorm] = threadNumber match {
+ case 1 => points
+ case _ =>
+ logInfo(s"kMeansPlusPlus run in thread nums: $threadNumber.")
+ val pointsPar = new ParVector(points.toVector)
+ val taskSupport = new ForkJoinTaskSupport(
+ ThreadUtils.newForkJoinPool("localKMeans-task-support", threadNumber))
Review Comment:
shutdown() the ForkJoinPool with try-finally here
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org