Skip to content

Instantly share code, notes, and snippets.

@Yuichiroh
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yuichiroh/6c1f0c9df80786ee13c2 to your computer and use it in GitHub Desktop.
Save Yuichiroh/6c1f0c9df80786ee13c2 to your computer and use it in GitHub Desktop.
object ParallelWritingWithApp extends App {
val seq = (0 until 100).map(_ * args(1).toInt)
for (w <- new PrintWriter(args(0)))
seq foreach w.println
implicit class Using[T <: AutoCloseable](resource: T) {
def foreach[R](op: T => R): R = {
try op(resource)
catch { case e: Exception => throw e }
finally resource.close()
}
}
}
object ParallelWritingTest extends App {
val maxes = (1 to 5).par.map { i =>
(1 to 3).par.map { j =>
val id = s"$i-$j.txt"
Console.err.println(s"write $id")
ParallelWritingWithApp.main(Array(id, i.toString))
Console.err.println(s"read $id")
Source.fromFile(id).getLines().map(_.toInt).sum
}.zipWithIndex
}
println(maxes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment