forked from spagnuolocarmine/FLY-language
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
24 additions
and
20 deletions.
There are no files selected for viewing
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
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 |