Quantcast
Channel: Intel Developer Zone Articles
Viewing all articles
Browse latest Browse all 3384

Distributing with Python*: Quick Guide to Using Intel® MPI (updated for Python 3.6)

$
0
0

 

Introduction

Intel® MPI is an optimized library for standard MPI applications, designed to deliver high-speed and scalable cluster messaging on Intel® based architecture. For Python users, the Intel® MPI runtime is included in Intel® Distribution for Python (IDP) and can be used in Python through mpi4py* - a Python binding package for MPI.

This article will discuss the key benefits of using Intel® MPI over standard MPI libraries, Intel® MPI’s simplicity in integrating with Python, and illustrate a Python usage example using Intel® MPI libraries.

Highlights of Intel® MPI

Optimized MPI application performance Application-specific tuning

  • Automatic tuning
  • Support for Intel® Xeon Phi™ Processor
  • Support for Intel® Omni-Path Architecture Fabric

Lower latency and multi-vendor interoperability

  • Industry leading latency
  • Performance optimized support for the fabric capabilities through OpenFabrics*(OFI)

Faster MPI communication

  • Optimized collectives

Sustainable scalability up to 340K cores

  • Native InfiniBand* interface support allows for lower latencies, higher bandwidth, and reduced memory requirements

More robust MPI applications

  • Seamless interoperability with Intel® Trace Analyzer and Collector

Intel® MPI with Python*(3.6)

In the Intel® Distribution for Python, mpi4py offers Python binding packages for MPI standards and wraps around Intel® MPI, thus enabling an optimized message passing interface and requiring no execution code changes in command line terminal.

Section below implements a simple master-slave python routine (mpi-sample.py) that sends partial arrays from all slave nodes to the master node

As mentioned, Intel® MPI is offered in Intel® Distribution for Python which should be installed prior to using Intel® MPI.

Intel® Distribution for Python is available for free for Windows*, Linux* and macOS*. The recommended install method is through Anaconda’s distribution cloud.

1. Install Intel® Distribution for Python with Anaconda

conda create -n IDP intel -c python=3.6

2.  Activate Intel® Distribution for Python on Linux

source activate IDP

3.  Activate Intel® Distribution for Python on Windows

activate IDP

4.  Install Intel® MPI

conda install mpi4py –c intel # installs Python binding packages that wraps Intel® MPI

5. Create MPI program (Below is an example of a basic Master-Slave python routine – mpi-sample.py)

from mpi4py import MPI
import numpy as np
import sys
# MPI Initialization
size = MPI.COMM_WORLD.Get_size ()
rank = MPI.COMM_WORLD.Get_rank ()
name = MPI.Get_processor_name ()

numRows = int (sys.argv[1])
numCols = int (sys.argv[2])
seeded = np.random.RandomState (42)
partialArray = seeded.rand (numRows, numCols)

if rank == 0:
    fullArray = [0] * size
    print ("Master begins receiving partial arrays....")
    if size > 1:
        for i in range (1, size):
            rank, size, name, fullArray[rank] = MPI.COMM_WORLD.recv (source=MPI.ANY_SOURCE, tag=1)
    print ("Master completes receiving all partial arrays")
else:
    MPI.COMM_WORLD.send ((rank, size, name, partialArray), dest=0, tag=1)

6. Run on terminal

Linux terminal

mpirun –n 4 python mpi-sample.py 100000 10

Windows terminal

mpiexec -n 4 python mpi-sample.py 100000 10

Viewing all articles
Browse latest Browse all 3384

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>