7 import parallelize as p
14 @p.parallelize(method=p.Method.THREAD)
15 def compute_factorial_thread(n):
22 @p.parallelize(method=p.Method.PROCESS)
23 def compute_factorial_process(n):
30 @p.parallelize(method=p.Method.REMOTE)
32 """Calculates sum of all primes below given integer n"""
35 ret.append(math_utils.is_prime(x))
39 @decorator_utils.timed
40 def test_thread_parallelization() -> None:
43 results.append(compute_factorial_thread(_))
44 smart_future.wait_all(results)
45 for future in results:
46 print(f'Thread: {future}')
47 texecutor = executors.DefaultExecutors().thread_pool()
51 @decorator_utils.timed
52 def test_process_parallelization() -> None:
55 results.append(compute_factorial_process(_))
56 for future in smart_future.wait_any(results):
57 print(f'Process: {future}')
58 pexecutor = executors.DefaultExecutors().process_pool()
62 @decorator_utils.timed
63 def test_remote_parallelization() -> None:
66 n = random.randint(0, 100000)
67 results[n] = list_primes(n)
72 rexecutor = executors.DefaultExecutors().remote_pool()
78 test_thread_parallelization()
79 test_process_parallelization()
80 test_remote_parallelization()
84 if __name__ == '__main__':