Book Image

Mastering Python Scientific Computing

Book Image

Mastering Python Scientific Computing

Overview of this book

Table of Contents (17 chapters)
Mastering Python Scientific Computing
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Example of performing parallel computing


The following program is a simple example of performing parallel computing using IPython. It calculates the power on the cluster in a single engine or in parallel in all the engines. Before executing this program, you are advised to check whether the zmq package is installed or not, as it is required.

To run these programs in IPython, first start the IPython cluster using the ipcluster start --n=4 --profile=testprofile command. It will create the ipcontroller-engine.json and ipcontroller-client.json files in the <userhome>/.ipython/profile_testprofile/security directory. These files will be searched through when we create the client by passing profile='testprofile'. If we create the client using parallel.Client(), then it will search for JSON files in the profile_default folder.

First, the program defines a function to calculate power, and then it creates a client using a test profile. To call a Python function in an engine, we can use the apply...