File: parallel_tasks_with_mpi.rst

package info (click to toggle)
python-cogent 1.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 16,424 kB
  • ctags: 24,343
  • sloc: python: 134,200; makefile: 100; ansic: 17; sh: 10
file content (16 lines) | stat: -rw-r--r-- 935 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Distribution of tasks across multiple CPUs using ``mpi``
========================================================

.. warning:: This example requires execution on 2 CPUs. It can be run using: ``$ mpirun -n 2 python path/to/parallel_tasks.rst``

All I'm doing here is illustrating the use of ``parallel.map`` with the simplest example I could come up with. I create a list which will have an integer appended to it -- hardly useful, but hopefully demonstrates how a series of data can be mapped onto a function in parallel. In this case, the data is just a list of numbers.

.. doctest::
    
    >>> from cogent.util import parallel
    >>> passed_indices = []
    >>> series = range(20)
    >>> result = parallel.map(passed_indices.append, series)
    >>> assert passed_indices == range(0,20,2) or passed_indices == range(1,20,2)

The result is either the list of even numbers up to (but not including) 20 or the list of odd numbers.