Giter VIP home page Giter VIP logo

mpi_python's Introduction

Table of Content

  1. Overview
  2. Usage
  3. Results
  4. Resources
  5. Report Issues
  6. Coming Up

Overview

This is a python repo for distributing evolutionary algorithms and distributing the runs of stochastic algorithms using Message Passing Interface (MPI). I use MPI4PY to distribute computation across processes running on parallel. The code is tested on the Lengau Cluster of the Center of High-Performance Computing (CHPC), South Africa.

This repo aims at demonstrating how to perform two tasks that are most often encountered in research in physical sciences (especially computer science) which are:

  • Distributing a computationally intensive algorithm.
  • Distriubting the runs of a stochastic algorithm.

An example of the first case is when you have an evolutionary algorithm with an expensive fitness evaluation. In this case, it is desirable to distribute the fitness evaluation where each process computes the fitness of individuals in a subpopulation. An example of the second case is when you need to run a stochastic algorithm several times where each run is seeded with a different seed for the random number generator to establish the statistical significance of the results.

This repo shows you how to do these two tasks with Python and MPI. I assume you have a basic knowledge of MPI and PBS to run this code on a cluster (the ideal scenario). You can run it in your personal computer. However, in this case a better option would be using the standard python multiprocessing library.

Usage

Ideally, this code should be run on a cluster. In general it is a good practice to test your MPI code before running it. For this, you need an interactive MPI job. The instructions of requesting an interactive job differs depending on the cluster your using. On the Lengau cluster, you need to issue the following commands:

qsub -I -P CSCI0806 -q test -l walltime=0:10:0 โ€“l select=1:ncpus=4:mpiprocs=4:nodetype=haswell_reg.
module load chpc/python/3.7.0

This will schedule an interactive MPI job and load Python. Then to run your MPI script:

mpirun -np 4 python script.py

where script.py is the main python program that starts the execution of your code.

After successfully testing your code in the interactive session, you need to submit it to an appropriate queue on the cluster. This is also differs per cluster. Please check your cluster manual to see how to run MPI jobs. On the Lengau cluster, your script will look like:

#!/bin/bash
 #PBS -l select=2:ncpus=24:mpiprocs=24:nodetype=haswell_reg
 #PBS -P CSCI0806
 #PBS -l walltime=01:00:00
 #PBS -o /home/username/out_dir/resultfile.txt
 #PBS -e /home/username/err_dir/errorfile.err
 #PBS -N job_name
 #PBS -q normal
 module load chpc/python/3.7.0
 cd path_to_dir_containing_your_python_script
 nproc=`cat $PBS_NODEFILE | wc -l`
 echo nproc is $nproc
 cat $PBS_NODEFILE
 time mpirun -np $nproc python script.py > /home/dir/resultfile.txt

Results

I ran the code in the Lengau cluster. The result of distributing the fitness evaluation of a genetic algorithm is shown in the figure below.

From the figure, as the number of processes increases the computational time decreases. However, you need to be aware that it is not always the case that adding more processes will map to significantly better performance. For more information, please see this demo.

The following figure shows the result of distributing the runs. The long bar the the execution time when we executes the runs sequentially while the short bar is when we use MPI to execute all runs in parallel.

Resources

This code is part of a tutorial I presented for the MSc and PhD students at NICOG. If you want a copy of the powerpoint presentation please reach me at [email protected].

Report Issues

If you find any bug in the code or have any ideas for improving it, please reach me at [email protected].

Coming Up

If you do not have access to a cluster and have a multicore machine (which most of modern machines have), I will soon drop a link in this page to a repo showing you how to distribute the algorithms and the runs of stochastic algorithm in pure Java (no MPI).

mpi_python's People

Contributors

al-madina avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.