Skip to content

Instantly share code, notes, and snippets.

@piotrga
Created December 26, 2011 02:20
Show Gist options
  • Save piotrga/1520404 to your computer and use it in GitHub Desktop.
Save piotrga/1520404 to your computer and use it in GitHub Desktop.
Matrix multiplication with parallel collections and idiomatic scala
def multiThreadedIdiomatic(m1:Seq[Array[Double]], m2:Array[Array[Double]] ) ={
val res = Array.fill(m1.length, m2(0).length)(0.0)
for(row <- (0 until m1.length).par;
col <- (0 until m2(0).length).par;
i <- 0 until m1(0).length){
res(row)(col) += m1(row)(i) * m2(i)(col)
}
res
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment