Skip to Content
A Concise Introduction to Programming in Python
book

A Concise Introduction to Programming in Python

by Mark J. Johnson
December 2011
Beginner
217 pages
8h
English
Chapman and Hall/CRC
Content preview from A Concise Introduction to Programming in Python
Chapter 27
Parallel Programming
Real-world problems often take too long to solve on a single processor because
of their size or computational demands. Parallel processing is a family of
mechanisms for coordinating multiple tasks that work in parallel to solve a
single problem. In this chapter, we explore the use of parallel programming
with the example from Chapter 10.
Listing 27.1: Monte Carlo Integration (Parallel Version)
1 # montecarlo.py
2
3 from random import uniform
4 from math import exp
5 import multiprocessing
6
7 def count_hits(f, a, b, m, n):
8 hits = 0
9 for i in range(n):
10 x = uniform(a, b)
11 y = uniform(0, m)
12 if y <= f(x):
13 hits += 1
14
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Standard Library

Python Standard Library

Fredrik Lundh
Numerical Computing with Python

Numerical Computing with Python

Pratap Dangeti, Allen Yu, Claire Chung, Aldrin Yim

Publisher Resources

ISBN: 9781439896952