-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmp2.py
More file actions
42 lines (33 loc) · 947 Bytes
/
mp2.py
File metadata and controls
42 lines (33 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/local/bin/python3
####################################################
#
from multiprocessing import Pool, cpu_count
from timeit import default_timer as timer
cpu_cnt=cpu_count()
print("Ich nutze", cpu_cnt, "Prozesse")
prim_range = 1000000
chunk_size = 1000
# Funktionen
def primrechner(ps):
pc=[]
print(" Starte von", ps, "bis", ps+chunk_size-1)
for z in range(ps, ps + chunk_size):
pc.append(z)
for z2 in range(2, z):
if not z % z2:
pc.remove(z)
break
# print(len(pc))
return(len(pc))
def main():
start = timer()
with Pool(processes=cpu_cnt) as pool:
start_values=list(range(1,prim_range, chunk_size))
# print(start_values)
res = pool.map(primrechner, start_values)
# Abschluss
print("Es wurden", sum(res), "Primzahlen gefunden")
end = timer()
print(end - start)
if __name__ == '__main__':
main()