title: Boost.MPI on Ubuntu 12.04
body: <h2>Background</h2>
  
  <p>Hi All,</p>
  
  <p>I'm trying to use Boost::MPI, at the moment I'm just trying to run the simple first example from the <a href="http://www.boost.org/doc/libs/1_45_0/doc/html/mpi/tutorial.html" rel="nofollow">tutorial</a>. I am having trouble building/running it.</p>
  
  <p>I installed boost using apt-get and installed boost_mpi &amp; boost_serialization (1.48.0) using synaptic package manager. I installed MPICH2 using apt-get.</p>
  
  <p>Even though OpenMPI was never explicitly installed it appears to be on my system, I assume this is a dependency for Boost::MPI but it appears MPICH2 and OpenMPI are treading on each other's toes.</p>
  
  <h2>Info</h2>
  
  <p>If I build using </p>
  
  <pre><code>g++ test.cpp -I/usr/include/mpich2 -L/usr/lib -lboost_mpi -lboost_serialization
  </code></pre>
  
  <p>then run using</p>
  
  <pre><code>mpiexec -n 2 ./a.out
  </code></pre>
  
  <p>It throws a bunch of errors which seem to come from OpenMPI. If I try and build by linking against the OpenMPI library using</p>
  
  <pre><code>g++ test.cpp -L/usr/lib -lboost_mpi -lboost_serialization -lmpi -I/usr/include/openmpi
  </code></pre>
  
  <p>I get the following errors:</p>
  
  <pre><code>/usr/bin/ld: /tmp/ccJ5ezv7.o: undefined reference to symbol 'ompi_op_set_cxx_callback'
  /usr/bin/ld: note: 'ompi_op_set_cxx_callback' is defined in DSO /usr/lib/libmpi.so.0 so try adding it to the linker command line
  /usr/lib/libmpi.so.0: could not read symbols: Invalid operation
  </code></pre>
  
  <p>If I try building using <code>mpic++</code> with the following command</p>
  
  <pre><code>mpic++ test.cpp -lboost_mpi -lboost_serialization
  </code></pre>
  
  <p>It will not link returning a bunch of errors of the form</p>
  
  <pre><code> /usr/lib/libmpich.so: undefined reference to `MPL_trid'
  </code></pre>
  
  <p>so I tried linking against libmpi i.e.</p>
  
  <pre><code>mpic++ test.cpp -lboost_mpi -lboost_serialization -lmpi
  </code></pre>
  
  <p>This builds but on running with <code>mpiexec</code> yields the following errors</p>
  
  <pre><code>Fatal error in PMPI_Errhandler_set: Invalid communicator, error stack:
  PMPI_Errhandler_set(118): MPI_Errhandler_set(comm=0x370500, errh=0x370be0) failed
  PMPI_Errhandler_set(70).: Invalid communicator
  </code></pre>
  
  <h2>Question</h2>
  
  <p>It seems to me that somehow OpenMPI and MPICH2 are getting intertwined where there really shouldn't. Does anybody know how I can build against only OpenMPI or MPICH2 then run using the correct <code>mpiexec</code>?</p>