@@ -34,13 +34,13 @@ SCOOP 支持 Linux, Mac, 和 Windows 平台。和 Disco 一样,它的远程访
34
34
35
35
SCOOP 内置了很多适用于科学计算场景的功能,可以解决很多需要很多算力的科学问题。本文将以蒙特卡罗算法为例子。要说明白这个算法将占用很大的篇幅,但是在本例子中,只是想以并行执行一个蒙卡特罗算法解决问题展示 SCOOP。下面以计算 π 为例: ::
36
36
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
41
41
42
42
43
- def evaluate_number_of_points_in_unit_circle (attempts):
43
+ def evaluate_points_in_circle (attempts):
44
44
points_fallen_in_unit_disk = 0
45
45
for i in range (0,attempts) :
46
46
x = random()
@@ -54,8 +54,7 @@ SCOOP 内置了很多适用于科学计算场景的功能,可以解决很多
54
54
return points_fallen_in_unit_disk
55
55
56
56
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))
59
58
bt = time()
60
59
#in this point we call scoop.futures.map function
61
60
#the evaluate_number_of_points_in_unit_circle \
@@ -66,15 +65,15 @@ SCOOP 内置了很多适用于科学计算场景的功能,可以解决很多
66
65
[attempts] * workers)
67
66
taskresult= sum(evaluate_task)
68
67
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))
71
70
computationalTime = time() - bt
72
71
print("value of pi = " + str(piValue))
73
72
print ("error percentage = " + \
74
73
str((((abs(piValue - math.pi)) * 100) / math.pi)))
75
74
print("total time: " + str(computationalTime))
76
75
77
- if __name__ == "__main__":
76
+ if __name__ == "__main__":
78
77
for i in range (1,4):
79
78
# let's fix the numbers of workers...only two,
80
79
# but it could be much greater
0 commit comments