Book Image

Parallel Programming with Python

By : Jan Palach, Jan Palach V Cruz da Silva
Book Image

Parallel Programming with Python

By: Jan Palach, Jan Palach V Cruz da Silva

Overview of this book

Table of Contents (16 chapters)
Parallel Programming with Python
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Using PP to calculate the Fibonacci series term on SMP architecture


Time to get into action! Let's solve our case study involving the Fibonacci series for multiple inputs using PP in the SMP architecture. I am using a notebook armed with a two-core processor and four threads.

We will import only two modules for this implementation, os and pp. The os module will be used only to obtain a PID of the processes in execution. We will have a list called input_list with the values to be calculated and a dictionary to group the results, which we will call result_dict. Then, we go to the chunk of code as follows:

import os, pp
input_list = [4, 3, 8, 6, 10]
result_dict = {}

Then, we define a function called fibo_task, which will be executed by parallel processes. It will be our func argument passed by the submit method of the Server class. The function does not feature major changes in relation to previous chapters, except that the return is now done by using a tuple to encapsulate the value received...