Last active
December 11, 2015 16:49
-
-
Save pkukielka/4630522 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.pkukielka | |
import scala.actors.Futures._ | |
object ScalaSum { | |
def sum(r: Range): Long = { var i = r.start; var sum = 0L; while (i <= r.end) { i += r.step; sum += i }; return sum } | |
val cores = Runtime.getRuntime().availableProcessors() | |
val jobs = (1 to cores).map(_ to 1234567890 by cores).map(range => future(sum(range))) | |
def main(args: Array[String]) { | |
println(awaitAll(5000, jobs: _*).map(_.get.asInstanceOf[Long]).sum) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment