471,309 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,309 software developers and data experts.

pyMPI and calling MPI functions using Boost.Python


I'm trying to wrap a c++ library using MPI inside with boost.python
(or SWIG).
I managed to find that calling `MPI::Init()` embeded in a c++ funtion
would not work. So, I decided to use `pyMPI`.
To avoid overhead of pickling and unpickling while calling `mpi.send`
in Python, I'd rather call c++ functions `MPI::Isend()` etc. embeded
in a c++ function.

What I'd like to know is the following:
After starting `pyMPI` session, it seems to work call c++ function
`MPI::Isend()` or `MPI::Irecv()`, etc. from the `pyMPI`,
at least for my small test code attached below.

Is it guaranteed to work for larger scale code?
I mean for larger memory allocation, heavily repeated message passing,
, many paralell processes.
Or, the example worked only with some luck?
As for now, `mpiCC` is built without shared library.

Any suggestions?

Thank you.


----- A small test code mpitest.so works like this -----
$ mpirun -np 2 /usr/bin/pyMPI
Python 2.2.1 (#1, Jan 22 2003, 19:07:20)
[GCC 2.95.3 20010315 (release)] on linux2
Copyright (c) 2001, 2002 Python Software Foundation.
All Rights Reserved.

Copyright (c) 2000 BeOpen.com.
All Rights Reserved.

Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.

Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved.
import mpi
import mpitest
print "hello ", mpi.rank, mpi.size hello 0 2
hello 1 2 bnd = mympi.bndry(6)
bnd.mpiTest(mpi.rank, mpi.size - 1 - mpi.rank)

100, 99, 98, 97, 96, 95, was a rtmp for node:0
100, 101, 102, 103, 104, 105, was a rtmp for node:1>>>
----- mpitest.so is made from the following using Boost.Python.
#include "ftest.h"

#include <iostream>
#include <mpi++.h>

class bndry{
MPI::Request sreq_, rreq_;
double* stmp_;
double* rtmp_;
int n_;
bndry(int n) : n_(n) {
stmp_ = new double[n];
rtmp_ = new double[n];
delete [] stmp_;
delete [] rtmp_;
void mpiTest(int me, int other) {
double c0 = 1.0;
if (me == 1) c0 = -1.0;
unsigned int ii = 0;
// Create diffrent arrays in diffrent nodes
for (int k = 0; k < n_; ++k) {
stmp_[ii++] = 100.0 + c0 * k;
sreq_ = MPI::COMM_WORLD.Isend(stmp_, ii, MPI::DOUBLE, other, me);
rreq_ = MPI::COMM_WORLD.Irecv(rtmp_, ii, MPI::DOUBLE,
other, other);
for (int k = 0; k < n_; ++k) {
cout << rtmp_[k] << ", ";
cout << " was a rtmp for node:" << me << endl;

#include <boost/python.hpp>
#include <boost/cstdint.hpp>
#include <fblock.h>
using namespace boost::python;
class_< bndry >("bndry", init< const bndry& >())
.def(init< int >())
.def_readwrite("n_", &bndry::n_)
.def("mpiTest", &bndry::mpiTest)

Jul 18 '05 #1
0 1967

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Wen Jiang | last post: by
10 posts views Thread by Simon Elliott | last post: by
1 post views Thread by stringy | last post: by
7 posts views Thread by Pankaj | last post: by
3 posts views Thread by gabriel.becedillas | last post: by
4 posts views Thread by Shawn McGrath | last post: by
reply views Thread by Stou Sandalski | last post: by
1 post views Thread by smithken04 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.