Installing Open MPI 1.6.5 (Ubuntu 12.04, 13.04, fedora)

The OpenMPI logo. A box filled with useful tricks!
Open MPI ( )  is one of the most liberating tools out there. In a world where time is of the essence and most computers these days have more than one core, why let them sit around idle doing nothing, put them to good use!!

It stands for Message Parsing Interface (MPI) and allows you to do a whole manner of parallelised computing applications. For an in-depth idea of what it can do visit the website but a few key things that are useful to know are:

  1. Collective functions: Main example is the MPI Reduce function, which allows you to perform simple operations such as a summation using the family of processors to do so.
  2. Point-to-Point communication: Most common example I can think of is the use of a head node splitting a dataset into smaller memory chunks based on the number of sub-processors that are available, where each will then compute the same task in parallel. This operations protocol is usually called a master-to-slave process.
  3. Communicators: These connect all the MPI processes into groups, called process groups. An example is the world communicator which contains attributes such as the size (number of processors) and rank (ordered topology) of the group. They also allow for the manipulation of process groups.

How to Install
Open MPI is relatively simple to install, I should point out I have not tried this on a Fedora machine but as long as you have the same libraries/dependencies then it should be the same procedure. There are two methods; the first (and not my preferred method!) is to simply find the latest version from the on-line repositories as of today the latest version was 1.6.5. To do this you can

sudo apt-get update
sudo apt-get install -y autotools-dev g++ build-essential openmpi1.5-bin openmpi1.5-doc libopenmpi1.5-dev
# remove any obsolete libraries
sudo apt-get autoremove

That should get you what you need, if you are on Fedora simply “sudo yum search openmpi” that should bring you up something similar to openmpi, openmpi-devel. The next method and my preferred way as you get the most recent update version(currently 1.6.5) is to take it directly from the website. The below script worked for me on Ubuntu 13.04 tested on 25/07/2013.

The script below will install Open MPI in your /usr/local area, this can be modified by changing the parameter installDIR in the script to the desired location. After install the libraries are placed in $installDIR/lib/openmpi and you can now begin playing with Open MPI. One thing to note is that I apply ldconfig to the /usr/local/lib, this is a much better method than setting paths explicitly. To do this you need to modify your directory to make it look in the /usr/local/xxx area if it doesn’t already. Now with Ubuntu you may already have this linked up so check if your machine has a file called “/etc/” and a path explicitly showing “/usr/local/lib” and that should be all. If you do then you can ignore this step, else you can add the path using the following:

sudo echo "/usr/local/lib" >> /etc/
sudo ldconfig -v

I prefer this method as you do not have to keep adding things to your LD_LIBRARY_PATH all the time which is not really recommended, see for a couple of examples for the case against setting this path. I should have mentioned this in previous blogs too!!

# Matthew M Reid. install open mpi shell script

# install destination
# First get necessary dependencies
sudo apt-get update
sudo apt-get install -y gfortran autotools-dev g++ build-essential autoconf automake 
# remove any obsolete libraries
sudo apt-get autoremove

# Build using maximum number of physical cores
n=`cat /proc/cpuinfo | grep "cpu cores" | uniq | awk '{print $NF}'`

# grab the necessary files
tar xzvf openmpi-1.6.5.tar.gz
cd openmpi-1.6.5

echo "Beginning the installation..."
./configure --prefix=$installDIR
make -j $n
make install
# with environment set do ldconfig
sudo ldconfig
echo "...done."

So finally to test the installation here is a simple example that just prints out some information from each processor.

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

int main(int argc, char *argv[])
    int numprocessors, rank, namelen;
    char processor_name[MPI_MAX_PROCESSOR_NAME];

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocessors);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Get_processor_name(processor_name, &namelen);

    if ( rank == 0 )
        std::cout << "Processor name: " << processor_name << "\n";
	std::cout << "master (" << rank << "/" << numprocessors << ")\n";
    } else {
        std::cout << "slave  (" << rank << "/" << numprocessors << ")\n";
   return 0;

When compiling C++ with Open MPI you can use the executable wrapper, mpic++, which makes compiling much easier. On execution of your script you need to call mpirun where you can specify the number of processors via the -np flag. The output is as follows running from my local machine. Dont worry about the ordering in which these are spit back at you.

matt@matt-W250ENQ-W270ENQ:$ mpic++ -W -Wall test.cpp -o test.o
matt@matt-W250ENQ-W270ENQ:$ mpirun -np 4 test.o
Slave   (3/4)
Processor name; matt-W!112332-NZ10
Master  (0/4)
Slave   (1/4)
Slave   (2/4)

The thing I would like to come onto will be Boost.MPI. This is a very nice interface to the MPI framework and also allows the use of prerequisite parallel graph libraries, which have been well developed and implemented. So the next blog will be about installing Boost which alone has a vast amount to offer, followed by some examples of the Boost.MPI framework in action. The thing that is really clever about this is the Boost.Serialization architecture which allows you to send more complex data structures such as user defined classes via the MPI framework, so you can make “almost” anything parallel.

26 comments on “Installing Open MPI 1.6.5 (Ubuntu 12.04, 13.04, fedora)

  1. martin says:

    Great post. Worked on the first try!

  2. Nitin says:

    Thank you very much for the post! what a nice treat this sunday morning? The script did not work due to permissions set on my system, also i work with mercurial to manage software and so tried the script one line at a time as below. Worked just perfect.
    Thank you.

    #install gfort
    sudo apt-get install gfortran

    # install destination
    echo $installDIR

    # Build using maximum number of physical cores
    n=`cat /proc/cpuinfo | grep “cpu cores” | uniq | awk ‘{print $NF}’`
    echo $n

    # grab the necessary files
    tar xzvf openmpi-1.6.5.tar.gz
    cd openmpi-1.6.5

    echo “Beginning the installation…”
    ./configure –prefix=$installDIR
    make -j $n
    sudo make install

    #so cool

  3. Blobby says:

    Thank you so much! I’ve been trying all day to get this installed, your script worked perfectly.

  4. irvanda says:

    I got this message (bash: /usr/local/lib: Is a directory) while I was entering “/usr/local/lib” >> /etc/ Is that an error?

    I can compile using mpic++ and run using mpirun, but I’m not sure whether if I did it right or not.

    • mattreid9956 says:

      Hey, yes this was certainly a typo, I missed off the echo command. I have added this in and in fact made a note that it is not always necessary. If you have libc installed and I am certain you will do, then this path is already linked as I have now explained in the text. Anyway, have fun with this mpi is really cool I keep meaning to do some more posts but seriously lacking time at the moment, check out the Boost aspects also in my other blog!

      • Terry Jones says:

        What you probably want is

        echo “/usr/local/lib” | sudo tee -a /etc/

        The reason the failure happens in the description above is that the shell tries to open the file for writing (due to the >>) and that fails. That has nothing to do with the sudo on the command line, it’s the shell preparing file descriptors for the process. The echo | tee trick gets around it.

  5. says:

    Thanks very much for the script. As a relative newbie to Linux scripts, this was really helpful to install open MPI. I ran into two problems, which puzzled me for quite some time. I’m offering the solutions here, for future readers, who may be as perplexed as I was.

    First, turns out, my Ubuntu install didn’t include C++, so I used the software manager to install. It’s easy to write this in one sentence, but it took me a long time to figure out that was a problem! The error I got listed a bunch of compilers, and then stopped executing with an error message which I didn’t record. The solution was straightforward, as the software manager in Ubuntu is pretty painless, even for newbies.

    Second, there is a permissions problems in /usr/local, even though ldconfig is executed in sudo. (by sudo?) Took me a little while to figure out that I could solve this by executing the script itself from sudo. My script is called “”. I ran it this was:
    $ sudo ./
    and that did it.

    Thanks again!

    • mattreid9956 says:

      Hey, thanks for sharing you experience. I will make a comment about dependencies to aid newcomers, but most of all have fun!

  6. Ben says:

    First off, thank you for the post–seems to be working quite well!

    One issue though, when I run the “n=`cat /proc/cpuinfo | grep “cpu cores” | uniq | awk ‘{print $NF}’`” I get that n=2 (which is correct), but when running the test C++ code it only picks up 1 core (regardless of what I supply for the “-np” variable).

    This is my output (I added a cout to check for # of cores found):
    There are 1 available…
    Processor name: Ben-Ubuntu
    master (0/1)
    There are 1 available…
    Processor name: Ben-Ubuntu
    master (0/1)

    Any help on this?


    • mattreid9956 says:

      Hi Ben,

      OK this is certainly odd you should get the following
      slave (3/4)
      Processor name: matt-W250ENQ-W270ENQ
      master (0/4)
      slave (1/4)
      slave (2/4)

      Occurring in some random order… I am not sure your installation will have worked exactly in this case. Before that lets just double check a few things, did you run the exact code example posted on the blog? Did you compile it with mpic++ like it suggests on the blog? hmmm maybe try the example from scratch once more then if it still does not work then we will have to debug the installation from scratch and see what the output says. Cheers and have a great New Year!

      • Ben says:

        Hi Matt,

        I got the install to work better (I needed to use a “sudo” before the “make install”). This, however, begot a new error:

        mpic++: error while loading shared libraries: cannot open shared object file: No such file or directory

        I found the libopen files in my /usr/local/lib/ directory, but cannot figure out why it thinks the file does not exist.

        I’m guessing that either it ties back to me using “sudo” with the make file or (I’m a 5 year Python programmer and this happens with the sys path) the compiler isn’t looking in the right place (though /usr/local/lib/ should be THE place lol)

        Sorry this has been a bother, I really appreciate the help.

        Thanks and happy new year to you as well!


      • Ben says:

        I got it to work..the issue was with the LD_LIBRARY_PATH not knowing to look at /usr/local/lib.

        I added this line: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
        to the end of /etc/bash.bashrc and it now works.

        Thanks and hope this helps (I’ve seen others with similar issues on the Open MPI forums).


      • mattreid9956 says:

        Hi Ben,

        Your method will of course work. I have to wonder if you did the following step mentioned in the blog post

        sudo echo “/usr/local/lib” >> /etc/
        sudo ldconfig -v

        This would create a file called local.conf in the area which allows you to place a configuration file for linking of libraries. Like I say I prefer this method but it doesn’t really matter as long as it works for you, simply as you can delete the file local.conf. Have fun and have a great new year!!

      • Ben says:

        As Homer Simpson would say, “Doh!” In my cursory glancing for code snippets I passed right over that. Funny how something like that makes a difference…

        I’m looking forward to following the blog and using Open MPI for future projects!

        Thanks again!

  7. Brian says:

    I have a new installation of Ubuntu 14.04 64-bit srever. I downloaded the latest package openmpi-1.8.1.tar.gz to my /download directory and tried to follow your script, but after I enter sudo apt-get install -y autotools-dev autoconf-dev automake-dev I get the error:

    f-dev automake-dev
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package autoconf-dev
    E: Unable to locate package automake-dev

    what am I doing wrong? do I need to put the mpi package somewhere specific?

    • mattreid9956 says:

      Hi Brian,
      You did nothing wrong, this is just an old snippet of code I forgot to change, essentially I have now removed the lines regarding automake, you should now be able to run the new script without problem although I am assuming that you have automake as the MPI build requires this (I am tempted to write the cmake compilation if I find a few moments). Let me know if you still have any problem, but as long as you have already installed autoconf and automake the script should still work. I have edited the post hope that helps (NOTE: I have not tested this as I have no linux machine to hand, should be ok but like I say, let me know if not).

      • Brian says:

        Thanks Matt. Your updated script ran all the way through with no obvious errors. But, the test script failed on my system with:

        bsimison@ubuntu:~/Documents$ sh -x 4: Syntax error: “(” unexpected

        I could see any obvious misplaced “(“.

      • mattreid9956 says:

        Hi Brian, Can you just post to me what is in the script? Like I said right now I don’t have access to a Linux machine annoyingly assuming the install occurred without glitch. Then you should at least be able to type “mpirun” in the terminal and something will happen (it will probably moan about not specifying a file…). Let me know


      • Brian says:

        Hi Matt,
        I used your installation test script above and named it “”. Sorry for the confusion.

  8. Note : sélection de « libgphoto2-port0 » au lieu de « libgphoto2port »
    E: Impossible de trouver le paquet autotools-dev
    E: Impossible de trouver le paquet build-essential
    E: Impossible de trouver le paquet openmpi1.5-bin
    E: Impossible de trouver de paquet correspondant à l’expression rationnelle « openmpi1.5-bin »
    E: Impossible de trouver le paquet openmpi1.5-doc
    E: Impossible de trouver de paquet correspondant à l’expression rationnelle « openmpi1.5-doc »
    E: Impossible de trouver le paquet libopenmpi1.5-dev
    E: Impossible de trouver de paquet correspondant à l’expression rationnelle « libopenmpi1.5-dev »
    asma@ubuntu:~$ # remove any obsolete libraries
    asma@ubuntu:~$ sudo apt-get autoremove


    • mattreid9956 says:

      My french is not excellent but it seems you cant even find the package “build-essential”… This is odd. Have you tried “sudo apt-get build-essential”? What Linux distro and architecture are you running? As I say in most of my posts, please don’t just copy and paste code without reading it first and understanding what it is doing.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s