diff options
Diffstat (limited to 'examples/src/main/python/pi.py')
-rwxr-xr-x | examples/src/main/python/pi.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/examples/src/main/python/pi.py b/examples/src/main/python/pi.py index 234720b55f..21d94a2cd4 100755 --- a/examples/src/main/python/pi.py +++ b/examples/src/main/python/pi.py @@ -29,9 +29,11 @@ if __name__ == "__main__": sc = SparkContext(appName="PythonPi") slices = int(sys.argv[1]) if len(sys.argv) > 1 else 2 n = 100000 * slices + def f(_): x = random() * 2 - 1 y = random() * 2 - 1 return 1 if x ** 2 + y ** 2 < 1 else 0 + count = sc.parallelize(xrange(1, n+1), slices).map(f).reduce(add) print "Pi is roughly %f" % (4.0 * count / n) |