How to simulate in Python
In this section, we will look at the results of Amdahl's Law through a Python program. Still considering the task of determining whether an integer is a prime number, as discussed in Chapter 8, Advanced Introduction to Concurrent and Parallel Programming, we will see what actual speedup is achieved through concurrency. If you already have the code for the book downloaded from the GitHub page, we are looking at the Chapter09/example1.py
file.
As a refresher, the function that checks for prime numbers is as follows:
# Chapter09/example1.py from math import sqrt def is_prime(x): if x < 2: return False if x == 2: return x if x % 2 == 0: return False limit = int(sqrt(x)) + 1 for i in range(3, limit, 2): if x % i == 0: return False return x
The next part of the code is a function that takes in an integer that indicates the number of processors (workers) that we will be utilizing to concurrently...