Skip to content

Commit

Permalink
update pi.fly
Browse files Browse the repository at this point in the history
  • Loading branch information
MatDau authored May 24, 2019
1 parent 5d6529d commit ab29382
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions examples/pi/src/main/fly/fly/pi/pi.fly
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
env local = [type:"local"]
channel ch on local
func hit(data){
random r
var x = r.nextDouble()
var y = r.nextDouble()
var msg=0
if( (x*x)+(y*y) < 1.0 ){ msg=1 }
ch!msg
}
func estimation(){
var sum = 0
var crt = 0
for i in [0:10000] {
sum += ch? as Integer
crt += 1
}
println "PI approximation is "+ (sum*4.0)/crt
}
fly hit in [0:10000] on local thenall estimation
var local = [type="smp",nthread=4]

var ch = [type="channel"] on local

func hit(i){
var r = [type="random"]
var x = r.nextDouble()
var y = r.nextDouble()
var msg=0
if((x*x)+(y*y)<1.0){msg=1}
ch!msg
}

func estimation(){
var sum = 0
var crt = 0
for i in [0:1000000] {
sum += ch? as Integer
crt += 1
}
println "pi estimation: "+ (sum*4.0)/crt
}

fly hit in [0:1000000] on local thenall estimation

0 comments on commit ab29382

Please sign in to comment.