Git Product home page Git Product logo

pybind_mpi's Introduction

Example for using C++ library, pybind11, mpi4py & MPI

Introduction

Demonstrates how to call a C++ class from Python using pybind11 together with MPI.

To fetch this repository use the following command:

git clone --recursive https://codev-tuleap.cea.fr/plugins/git/helix/test_pybind_mpi.git

or

git clone https://codev-tuleap.cea.fr/plugins/git/helix/test_pybind_mpi.git
git submodule init
git submodule update --init

Derived from the following URLs:

Contents

Main files:

  • mpi_lib.cpp: C++/MPI library code
  • helloWorld.py: python code that call the C++/MPI library (using pybind11 and mpi4py)

How to configure your system

An easy way to setup the needed package is to use 'spack' machinery.

git clone https://github.com/spack/spack
source spack/share/spack/setup-env.sh # you should also put this line into you .bashrc
spack install openmpi
spack install [email protected]
spack install py-mpi4py
spack install py-numpy
spack install [email protected]

Each time you want to use the installed package, you will do:

spack load -r openmpi
spack load [email protected]
spack load -r py-mpi4py
spack load -r py-numpy
spack load -r [email protected]

Another way to go without spack for a quicker installation (however requiring root user access) can be:

apt install openmpi
apt install python3
apt install cmake
pip3 install numpy
pip3 install https://bitbucket.org/mpi4py/mpi4py/get/master.tar.gz

How to build this demo

cd test_pybind_mpi
mkdir build
cd build
export CC=<my C compiler>
export CXX=<my C++ compiler>
cmake ..
make

Example test run

mpirun -n 8 python3 helloWorld.py
[Python] Hello from machine skylake095.cluster, MPI rank 3 out of 8
[C++]    Hello from machine skylake095.cluster, MPI rank 3 out of 8
[Python] Hello from machine skylake095.cluster, MPI rank 2 out of 8
[C++]    Hello from machine skylake095.cluster, MPI rank 2 out of 8
[Python] Hello from machine skylake090.cluster, MPI rank 1 out of 8
[C++]    Hello from machine skylake090.cluster, MPI rank 1 out of 8
[Python] Hello from machine skylake099.cluster, MPI rank 5 out of 8
[C++]    Hello from machine skylake099.cluster, MPI rank 5 out of 8
[Python] Hello from machine skylake099.cluster, MPI rank 4 out of 8
[C++]    Hello from machine skylake099.cluster, MPI rank 4 out of 8
[Python] Hello from machine skylake100.cluster, MPI rank 6 out of 8
[C++]    Hello from machine skylake100.cluster, MPI rank 6 out of 8
[Python] Hello from machine skylake100.cluster, MPI rank 7 out of 8
[C++]    Hello from machine skylake100.cluster, MPI rank 7 out of 8
[Python] Hello from machine skylake090.cluster, MPI rank 0 out of 8
[C++]    Hello from machine skylake090.cluster, MPI rank 0 out of 8
Detected thread level MPI_THREAD_FUNNELED
Hello World from thread = 0
Hello World from thread = 5
Hello World from thread = 4
Hello World from thread = 10
Hello World from thread = 1
Hello World from thread = 2
Hello World from thread = 13
Hello World from thread = 3
Hello World from thread = 11
Hello World from thread = 8
Hello World from thread = 9
Hello World from thread = 6
Hello World from thread = 14
Hello World from thread = 7
Hello World from thread = 12
Hello World from thread = 15
Number of threads = 16

pybind_mpi's People

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.