1+ import time
2+ import multiprocessing as mp
3+ from Algorthmic_Tests import primeCounter
4+
5+
6+ def multiPrimeCounting (numOfCores = 6 , countTo = 1001 ):
7+ counter = primeCounter .primeCounter (countTo )
8+
9+ if numOfCores == 3 :
10+ p1 = mp .Process (target = counter ).start ()
11+ p2 = mp .Process (target = counter ).start ()
12+ p3 = mp .Process (target = counter ).start ()
13+ elif numOfCores == 4 :
14+ p1 = mp .Process (target = counter ).start ()
15+ p2 = mp .Process (target = counter ).start ()
16+ p3 = mp .Process (target = counter ).start ()
17+ p4 = mp .Process (target = counter ).start ()
18+ elif numOfCores == 5 :
19+ p1 = mp .Process (target = counter ).start ()
20+ p2 = mp .Process (target = counter ).start ()
21+ p3 = mp .Process (target = counter ).start ()
22+ p4 = mp .Process (target = counter ).start ()
23+ p5 = mp .Process (target = counter ).start ()
24+ elif numOfCores == 6 :
25+ p1 = mp .Process (target = counter ).start ()
26+ p2 = mp .Process (target = counter ).start ()
27+ p3 = mp .Process (target = counter ).start ()
28+ p4 = mp .Process (target = counter ).start ()
29+ p5 = mp .Process (target = counter ).start ()
30+ p6 = mp .Process (target = counter ).start ()
31+ elif numOfCores == 8 :
32+ p1 = mp .Process (target = counter ).start ()
33+ p2 = mp .Process (target = counter ).start ()
34+ p3 = mp .Process (target = counter ).start ()
35+ p4 = mp .Process (target = counter ).start ()
36+ p5 = mp .Process (target = counter ).start ()
37+ p6 = mp .Process (target = counter ).start ()
38+ p7 = mp .Process (target = counter ).start ()
39+ p8 = mp .Process (target = counter ).start ()
40+ elif numOfCores == 10 :
41+ p1 = mp .Process (target = counter ).start ()
42+ p2 = mp .Process (target = counter ).start ()
43+ p3 = mp .Process (target = counter ).start ()
44+ p4 = mp .Process (target = counter ).start ()
45+ p5 = mp .Process (target = counter ).start ()
46+ p6 = mp .Process (target = counter ).start ()
47+ p7 = mp .Process (target = counter ).start ()
48+ p8 = mp .Process (target = counter ).start ()
49+ p9 = mp .Process (target = counter ).start ()
50+ p10 = mp .Process (target = counter ).start ()
51+ elif numOfCores == 12 :
52+ p1 = mp .Process (target = counter ).start ()
53+ p2 = mp .Process (target = counter ).start ()
54+ p3 = mp .Process (target = counter ).start ()
55+ p4 = mp .Process (target = counter ).start ()
56+ p5 = mp .Process (target = counter ).start ()
57+ p6 = mp .Process (target = counter ).start ()
58+ p7 = mp .Process (target = counter ).start ()
59+ p8 = mp .Process (target = counter ).start ()
60+ p9 = mp .Process (target = counter ).start ()
61+ p10 = mp .Process (target = counter ).start ()
62+ p11 = mp .Process (target = counter ).start ()
63+ p12 = mp .Process (target = counter ).start ()
64+ elif numOfCores == 14 :
65+ p1 = mp .Process (target = counter ).start ()
66+ p2 = mp .Process (target = counter ).start ()
67+ p3 = mp .Process (target = counter ).start ()
68+ p4 = mp .Process (target = counter ).start ()
69+ p5 = mp .Process (target = counter ).start ()
70+ p6 = mp .Process (target = counter ).start ()
71+ p7 = mp .Process (target = counter ).start ()
72+ p8 = mp .Process (target = counter ).start ()
73+ p9 = mp .Process (target = counter ).start ()
74+ p10 = mp .Process (target = counter ).start ()
75+ p11 = mp .Process (target = counter ).start ()
76+ p12 = mp .Process (target = counter ).start ()
77+ p13 = mp .Process (target = counter ).start ()
78+ p14 = mp .Process (target = counter ).start ()
79+ elif numOfCores == 16 :
80+ p1 = mp .Process (target = counter ).start ()
81+ p2 = mp .Process (target = counter ).start ()
82+ p3 = mp .Process (target = counter ).start ()
83+ p4 = mp .Process (target = counter ).start ()
84+ p5 = mp .Process (target = counter ).start ()
85+ p6 = mp .Process (target = counter ).start ()
86+ p7 = mp .Process (target = counter ).start ()
87+ p8 = mp .Process (target = counter ).start ()
88+ p9 = mp .Process (target = counter ).start ()
89+ p10 = mp .Process (target = counter ).start ()
90+ p11 = mp .Process (target = counter ).start ()
91+ p12 = mp .Process (target = counter ).start ()
92+ p13 = mp .Process (target = counter ).start ()
93+ p14 = mp .Process (target = counter ).start ()
94+ p15 = mp .Process (target = counter ).start ()
95+ p16 = mp .Process (target = counter ).start ()
96+ elif numOfCores == 18 :
97+ p1 = mp .Process (target = counter ).start ()
98+ p2 = mp .Process (target = counter ).start ()
99+ p3 = mp .Process (target = counter ).start ()
100+ p4 = mp .Process (target = counter ).start ()
101+ p5 = mp .Process (target = counter ).start ()
102+ p6 = mp .Process (target = counter ).start ()
103+ p7 = mp .Process (target = counter ).start ()
104+ p8 = mp .Process (target = counter ).start ()
105+ p9 = mp .Process (target = counter ).start ()
106+ p10 = mp .Process (target = counter ).start ()
107+ p11 = mp .Process (target = counter ).start ()
108+ p12 = mp .Process (target = counter ).start ()
109+ p13 = mp .Process (target = counter ).start ()
110+ p14 = mp .Process (target = counter ).start ()
111+ p15 = mp .Process (target = counter ).start ()
112+ p16 = mp .Process (target = counter ).start ()
113+ p17 = mp .Process (target = counter ).start ()
114+ p18 = mp .Process (target = counter ).start ()
115+ else :
116+ pass
117+
118+ # Start timer
119+ startTimer = time .perf_counter ()
120+ startTimer2 = time .process_time ()
121+
122+ # Start prime counter
123+ multiPrimeCounting (numOfCores , countTo )
124+
125+ endTimer = time .perf_counter ()
126+ endTimer2 = time .process_time ()
127+
128+ print (f"Task Finished In Performance: { endTimer - startTimer :0.8f} s\n Task Finished In Process/CPU/Kernel + User Space: { endTimer2 - startTimer2 :0.8f} s" )
0 commit comments