imported template.spark.scala.old
1d2a1e03
Hari Sekhon
committed
1 changed file
template.spark.scala.old
/template.spark.scala.old+26
/template.spark.scala.old
Add comment 1 Plus  /*
Add comment 2 Plus   Author: Hari Sekhon
Add comment 3 Plus   Date: 2015-03-15 20:33:50 +0000 (Sun, 15 Mar 2015)
Add comment 4 Plus  */
Add comment 5 Plus  
Add comment 6 Plus  import scala.math.random
Add comment 7 Plus  import org.apache.spark._
Add comment 8 Plus  
Add comment 9 Plus  object MyApp {
Add comment 10 Plus   def main(args: Array[String]){
Add comment 11 Plus   val conf = new SparkConf().setAppName("Hari's App")
Add comment 12 Plus   val spark = new SparkContext(conf)
Add comment 13 Plus  
Add comment 14 Plus   val slices = if (args.length > 0) args(0).toInt else 2
Add comment 15 Plus   val n = 100000 * slices
Add comment 16 Plus  
Add comment 17 Plus   val count = spark.parallelize(1 to n, slices).map { i =>
Add comment 18 Plus   val x = random * 2 - 1
Add comment 19 Plus   val y = random * 2 - 1
Add comment 20 Plus   if(x*x + y*y < 1) 1 else 0
Add comment 21 Plus   }.reduce(_ + _)
Add comment 22 Plus  
Add comment 23 Plus   spark.stop()
Add comment 24 Plus   }
Add comment 25 Plus  }
Add comment 26 Plus