Skip to content

Commit 1fb5c7f

Browse files
authored
Merge pull request #75 from laixintao/bugfix
Bugfix - reopen from #73
2 parents 7dafed1 + ae34e26 commit 1fb5c7f

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

chapter5/04_Scientic_computing_with_SCOOP.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ SCOOP 支持 Linux, Mac, 和 Windows 平台。和 Disco 一样,它的远程访
3434

3535
SCOOP 内置了很多适用于科学计算场景的功能,可以解决很多需要很多算力的科学问题。本文将以蒙特卡罗算法为例子。要说明白这个算法将占用很大的篇幅,但是在本例子中,只是想以并行执行一个蒙卡特罗算法解决问题展示 SCOOP。下面以计算 π 为例: ::
3636

37-
import math
38-
from random import random
39-
from scoop import futures
40-
from time import time
37+
import math
38+
from random import random
39+
from scoop import futures
40+
from time import time
4141

4242

43-
def evaluate_number_of_points_in_unit_circle(attempts):
43+
def evaluate_points_in_circle(attempts):
4444
points_fallen_in_unit_disk = 0
4545
for i in range (0,attempts) :
4646
x = random()
@@ -54,8 +54,7 @@ SCOOP 内置了很多适用于科学计算场景的功能,可以解决很多
5454
return points_fallen_in_unit_disk
5555

5656
def pi_calculus_with_Montecarlo_Method(workers, attempts):
57-
print("number of workers %i - number of attempts %i"
58-
%(rkers,attempts))
57+
print("number of workers %i - number of attempts %i" % (workers,attempts))
5958
bt = time()
6059
#in this point we call scoop.futures.map function
6160
#the evaluate_number_of_points_in_unit_circle \
@@ -66,15 +65,15 @@ SCOOP 内置了很多适用于科学计算场景的功能,可以解决很多
6665
[attempts] * workers)
6766
taskresult= sum(evaluate_task)
6867
print ("%i points fallen in a unit disk after " \
69-
%(Taskresult/attempts))
70-
piValue = (4. * Taskresult/ float(workers * attempts))
68+
%(taskresult/attempts))
69+
piValue = (4. * taskresult/ float(workers * attempts))
7170
computationalTime = time() - bt
7271
print("value of pi = " + str(piValue))
7372
print ("error percentage = " + \
7473
str((((abs(piValue - math.pi)) * 100) / math.pi)))
7574
print("total time: " + str(computationalTime))
7675

77-
if __name__ == "__main__":
76+
if __name__ == "__main__":
7877
for i in range (1,4):
7978
# let's fix the numbers of workers...only two,
8079
# but it could be much greater

0 commit comments

Comments
 (0)