JetCracker

Life-time learner's blog

How to install MPI in Ubuntu

I am starting a series of articles devoted to distributed computing that we are now studying at MIPT. For programming we will use MPI.

Message Passing Interface (MPI) is a standardized and portable message-passing system designed by a group of researchers from academia and industry to function on a wide variety of parallel computers. The standard defines the syntax and semantics of a core of library routines useful to a wide range of users writing portable message-passing programs. We can use it for creating programmes for distributed computing systems (parallel computing).

MPI is a standard. There are different implementations of MPI for different platforms and programming languages. This article is about how to install MPI platform to your Ubuntu.

The  installation is very simple:

danon@danon-laptop:~$ sudo apt-get install libcr-dev mpich2 mpich2-doc

*** Added libcr-dev due to comment of Out310

You have to make sure that there is no other implementation of MPI installed. For example, if you have OpenMPI already installed, the result of execution of your programs will be unpredictable.

MPI Hello Wrold example

Now that we installed all necessary packages, we can write an “MPI Hello World”!

mpi_hello.c

/* C Example */
#include <mpi.h>
#include <stdio.h>

int main (int argc, char* argv[])
{
  int rank, size;

  MPI_Init (&argc, &argv);      /* starts MPI */
  MPI_Comm_rank (MPI_COMM_WORLD, &rank);        /* get current process id */
  MPI_Comm_size (MPI_COMM_WORLD, &size);        /* get number of processes */
  printf( "Hello world from process %d of %d\n", rank, size );
  MPI_Finalize();
  return 0;
}

To compile and execute your application run the following commands:

danon@danon-laptop:~$ mpicc mpi_hello.c -o hello
danon@danon-laptop:~$ mpirun -np 2 ./hello
Hello world from process 0 of 2
Hello world from process 1 of 2
danon@danon-laptop:~$

If you find any mistake or you have any problems with installation, please, let me know. Next time I’ll show you how to solve a real computing problem with MPI in C (when I learn how to).

UPD: How to calculate a sum(1/n!)?

MPI tutorial: http://www.mpitutorial.com/

Thanks for visiting.

Anton Danshin

References

  1. MPI: Hello World examples – http://www.dartmouth.edu/~rc/classes/intro_mpi/hello_world_ex.html
  2. MPI: installation in Ubuntu – http://puliu.blogspot.com/2008/03/how-to-install-mpi-in-ubuntu.html
  3. MPI: how to run – http://www.ats.ucla.edu/clusters/common/computing/parallel/using_mpi.htm
Advertisements

39 responses to “How to install MPI in Ubuntu

  1. out310 March 7, 2012 at 00:56

    So, Dear Anton
    It’s good, but today I have installed a new version of Ubuntu and I had some problems with mpi.
    After command in terminal:
    mpicc mpi_hello.c -o hello
    I had this one:
    /usr/bin/ld: cannot find -lmpi

    and something like that error.

    So the solution to this problem is:

    sudo apt-get install libcr-dev

    • jetcracker March 7, 2012 at 00:58

      Thank you! 🙂

  2. Pingback: MPI: Calculating sum 1/n! in parallel « JetCracker

  3. Pingback: [MPI] Solving the advection equation in parallel « JetCracker

  4. Pingback: [MPI] Calculating integral in parallel « JetCracker

  5. Pingback: Spring 2012: Overall stats « JetCracker

  6. Mike September 1, 2012 at 02:58

    how do i install or use mpe??

    from what I undestand mpich2 comes with mpe, but i cant compile programs that use

  7. robert November 28, 2012 at 02:28

    thank you!
    what version what that ubuntu ?

  8. Sal January 22, 2013 at 07:42

    I have been trying to install MPI for several days thanks for your guides it ran successfully with ubuntu 12.04 vmware installation.

    However, I wonder if you know anything related to HPL 2.1 benchmark, for measuring cpu speed and network bandwith.

    • jetcracker January 22, 2013 at 14:13

      Hi! Thank you for your comment.
      Unfortuantely, I don’t know anything about HPL…

  9. Jack January 29, 2013 at 20:42

    Hi,
    Thank you for your help. I tried executing a program exactly as you said and got this error:

    ./hello: symbol lookup error: /usr/lib/libmpich.so.3: undefined symbol: MPL_env2str
    ./hello: symbol lookup error: /usr/lib/libmpich.so.3: undefined symbol: MPL_env2str

    Can you please tell me what is it that I’m doing wrong?

  10. Rajeev Sharma February 20, 2013 at 10:10

    Hi I am currently working on a project based on server virtualization. The idea is this – My ubuntu server will function as a host while a Windows and Redhat VM will function as the guest. I need to run MPI matrix calculation programs on these machines whereby the host (master) initializes the calculation operands and sends the task to the VMs (slaves) so that the VMs are able to carry out the job and send the results back to the master. I would like to know if anyone could help me on this. Thanks!

    • jetcracker February 20, 2013 at 15:01

      Hi. I am a web developer… I studied mpi a year ago. So, I can’t help you with your problem.
      You should post your question on some forum or for example stackoverflow. There should be experts in mpi.
      Good luck!

  11. Joseph Maurer April 26, 2013 at 02:07

    Jack,

    To solve your problem, you will need to build mpich2 from source.

    Download from here: http://www.mpich.org/static/downloads/
    I used 1.4.1, which is the current version in the apt repositories.

    Extract and decompress the code. Enter the directory and run the following commands:

    ./configure –enable-lib-depend
    make
    make install

    The –enable-lib-depend ensures that these previously undefined symbols are included correctly.

    If you currently have a previous version of mpich2, you may wish to see which options were passed to ./configure by running the mpich2version script in the old build.

    • jetcracker April 29, 2013 at 20:29

      Thank you.

  12. ankit May 17, 2013 at 12:56

    i am thanck full to you sir this programe i install very eassy…

  13. DW June 29, 2013 at 17:25

    Thank you very much for your post. It’s easy to understand and fully-functional 🙂

  14. joana August 13, 2013 at 14:46

    hello . i want to install mpi to ubuntu. after i write the code (sudo apt-get install libcr-dev mpich2 mpich2-doc), it requests the password. i enter my password of ubuntu but i shows error. wrong password. is there any other specified password i should type?

    • jetcracker August 15, 2013 at 04:03

      Hi This is a weird behavior. It should work…
      Make sure your account have anough priveleges to install new packages.

  15. Manisha Vitthal Gaikwad October 22, 2013 at 08:28

    I installed all things which you give but nt running
    gives error like
    “manisha@Manisha:~$ mpicc mpi_hello.c -o hello
    manisha@Manisha:~$ mpirun -np 2 ./hello
    [Manisha:17885] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file ess_singleton_module.c at line 231
    [Manisha:17885] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file ess_singleton_module.c at line 140
    [Manisha:17885] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file runtime/orte_init.c at line 128
    ————————————————————————–
    It looks like orte_init failed for some reason; your parallel process is
    likely to abort. There are many reasons that a parallel process can
    fail during orte_init; some of which are due to configuration or
    environment problems. This failure appears to be an internal failure;
    here’s some additional information (which may only be relevant to an
    Open MPI developer):

    orte_ess_set_name failed
    –> Returned value A system-required executable either could not be found or was not executable by this user (-127) instead of ORTE_SUCCESS
    ————————————————————————–
    ————————————————————————–
    It looks like MPI_INIT failed for some reason; your parallel process is
    likely to abort. There are many reasons that a parallel process can
    fail during MPI_INIT; some of which are due to configuration or environment
    problems. This failure appears to be an internal failure; here’s some
    additional information (which may only be relevant to an Open MPI
    developer):

    ompi_mpi_init: orte_init failed
    –> Returned “A system-required executable either could not be found or was not executable by this user” (-127) instead of “Success” (0)
    ————————————————————————–
    [Manisha:17885] *** An error occurred in MPI_Init
    [Manisha:17885] *** on a NULL communicator
    [Manisha:17885] *** Unknown error
    [Manisha:17885] *** MPI_ERRORS_ARE_FATAL: your MPI job will now abort
    ————————————————————————–
    An MPI process is aborting at a time when it cannot guarantee that all
    of its peer processes in the job will be killed properly. You should
    double check that everything has shut down cleanly.

    Reason: Before MPI_INIT completed
    Local host: Manisha
    PID: 17885
    ————————————————————————–
    [Manisha:17886] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file ess_singleton_module.c at line 231
    [Manisha:17886] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file ess_singleton_module.c at line 140
    [Manisha:17886] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file runtime/orte_init.c at line 128
    ————————————————————————–
    It looks like orte_init failed for some reason; your parallel process is
    likely to abort. There are many reasons that a parallel process can
    fail during orte_init; some of which are due to configuration or
    environment problems. This failure appears to be an internal failure;
    here’s some additional information (which may only be relevant to an
    Open MPI developer):

    orte_ess_set_name failed
    –> Returned value A system-required executable either could not be found or was not executable by this user (-127) instead of ORTE_SUCCESS
    ————————————————————————–
    ————————————————————————–
    It looks like MPI_INIT failed for some reason; your parallel process is
    likely to abort. There are many reasons that a parallel process can
    fail during MPI_INIT; some of which are due to configuration or environment
    problems. This failure appears to be an internal failure; here’s some
    additional information (which may only be relevant to an Open MPI
    developer):

    ompi_mpi_init: orte_init failed
    –> Returned “A system-required executable either could not be found or was not executable by this user” (-127) instead of “Success” (0)
    ————————————————————————–
    [Manisha:17886] *** An error occurred in MPI_Init
    [Manisha:17886] *** on a NULL communicator
    [Manisha:17886] *** Unknown error
    [Manisha:17886] *** MPI_ERRORS_ARE_FATAL: your MPI job will now abort
    ————————————————————————–
    An MPI process is aborting at a time when it cannot guarantee that all
    of its peer processes in the job will be killed properly. You should
    double check that everything has shut down cleanly.

    Reason: Before MPI_INIT completed
    Local host: Manisha
    PID: 17886
    ————————————————————————–
    manisha@Manisha:~$ ^C

    • jetcracker October 29, 2013 at 18:21

      Please tak a look at this: http://stackoverflow.com/questions/7011519/mpiexec-fails-as-mpi-init-aborts

      Let me know if it solves your problem.

  16. Ali El-Moursy October 23, 2013 at 11:41

    I have tried the procedure provided above and I have got the following error message at execution stage:

    pvsdp@ubuntu11srv:~/MPIHelloWorld$ mpicc mpi_hello.c -o hello
    pvsdp@ubuntu11srv:~/MPIHelloWorld$ mpirun -np 2 ./hello
    [ubuntu11srv:18546] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file ../../../../../../orte/mca/ess/singleton/ess_singleton_module.c at line 357
    [ubuntu11srv:18547] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file ../../../../../../orte/mca/ess/singleton/ess_singleton_module.c at line 357
    [ubuntu11srv:18546] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file ../../../../../../orte/mca/ess/singleton/ess_singleton_module.c at line 230
    [ubuntu11srv:18546] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file ../../../orte/runtime/orte_init.c at line 132
    [ubuntu11srv:18547] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file ../../../../../../orte/mca/ess/singleton/ess_singleton_module.c at line 230
    [ubuntu11srv:18547] [[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file ../../../orte/runtime/orte_init.c at line 132
    ————————————————————————–
    It looks like orte_init failed for some reason; your parallel process is
    likely to abort. There are many reasons that a parallel process can
    fail during orte_init; some of which are due to configuration or
    environment problems. This failure appears to be an internal failure;
    here’s some additional information (which may only be relevant to an
    Open MPI developer):

    orte_ess_set_name failed
    –> Returned value A system-required executable either could not be found or was not executable by this user (-127) instead of ORTE_SUCCESS
    ————————————————————————–
    ————————————————————————–
    It looks like orte_init failed for some reason; your parallel process is
    likely to abort. There are many reasons that a parallel process can
    fail during orte_init; some of which are due to configuration or
    environment problems. This failure appears to be an internal failure;
    here’s some additional information (which may only be relevant to an
    Open MPI developer):

    orte_ess_set_name failed
    –> Returned value A system-required executable either could not be found or was not executable by this user (-127) instead of ORTE_SUCCESS
    ————————————————————————–
    ————————————————————————–
    It looks like MPI_INIT failed for some reason; your parallel process is
    likely to abort. There are many reasons that a parallel process can
    fail during MPI_INIT; some of which are due to configuration or environment
    problems. This failure appears to be an internal failure; here’s some
    additional information (which may only be relevant to an Open MPI
    developer):

    ompi_mpi_init: orte_init failed
    –> Returned “A system-required executable either could not be found or was not executable by this user” (-127) instead of “Success” (0)
    ————————————————————————–
    ————————————————————————–
    It looks like MPI_INIT failed for some reason; your parallel process is
    likely to abort. There are many reasons that a parallel process can
    fail during MPI_INIT; some of which are due to configuration or environment
    problems. This failure appears to be an internal failure; here’s some
    additional information (which may only be relevant to an Open MPI
    developer):

    ompi_mpi_init: orte_init failed
    –> Returned “A system-required executable either could not be found or was not executable by this user” (-127) instead of “Success” (0)
    ————————————————————————–
    *** The MPI_Init() function was called before MPI_INIT was invoked.
    *** This is disallowed by the MPI standard.
    *** Your MPI job will now abort.
    [ubuntu11srv:18546] Abort before MPI_INIT completed successfully; not able to guarantee that all other processes were killed!
    *** The MPI_Init() function was called before MPI_INIT was invoked.
    *** This is disallowed by the MPI standard.
    *** Your MPI job will now abort.
    [ubuntu11srv:18547] Abort before MPI_INIT completed successfully; not able to guarantee that all other processes were killed!

    • jetcracker October 29, 2013 at 18:19

      Take a look at this:
      http://stackoverflow.com/questions/7011519/mpiexec-fails-as-mpi-init-aborts

      Maybe you have both mpich2 and open-mpi installed?

      • Ali El-Moursy October 30, 2013 at 13:54

        That works for me
        Thanks!

  17. Breno Riba October 24, 2013 at 04:00

    Man.. thank you! I was crazy searching for a sample like this! Very good!

    • jetcracker October 29, 2013 at 18:15

      De nada! 🙂

  18. Ryan October 30, 2013 at 13:24

    I exactly followed what you said above but i got an message “Hello from processor 0 of 1
    Hello from processor 0 of 1 ”
    How can i solve that problem.. ?

  19. Linus February 18, 2014 at 13:47

    Doing this tutorial quite messed up mpi for mi, since I noticed I had a default inmplementation in ubuntu of openmpis mpirun (but not mpicc) rather than mpich2.

    This link helped me to successfully set up openmpi: http://lsi.ugr.es/~jmantas/pdp/ayuda/datos/instalaciones/Install_OpenMPI_en.pdf

    Basically you run this line:

    sudo apt-get install openmpi-bin openmpi-common openssh-client openssh-server libopenmpi1.3 libopenmpi-dbg libopenmpi-dev

    • jetcracker February 21, 2014 at 00:30

      Thank you for your feedback.
      I think it will be very helpful to other users who struggle with installing MPI in Ubuntu!
      Good job!

  20. Pingback: Basic Introduction of MPI | Xianwei

  21. suresh March 22, 2014 at 17:19

    Dont we have to set any path for this ???

  22. obedullah April 18, 2014 at 21:17

    When i tried to install through command :- apt-get install libcr-dev mpich2 mpich2-doc , i got following errors in ubuntu12.04.3, Please help me.
    Errors were encountered while processing: phpldapadmin

    • jetcracker February 14, 2015 at 16:45

      I am very sorry, but I don’t work with MPI any more… a year course at my university finished long time ago and I don’t use MPI in my current work.

  23. shiva sankari September 6, 2014 at 11:27

    lam4-dev
    * libmpich-mpd1.0-dev
    * libmpich-shmem1.0-dev
    * libmpich1.0-dev
    * libmpich2-dev
    * libopenmpi-dev
    * libopenmpi1.6-dev
    when i try to execute my hello world program i get this error…i don’t know how to recover it…could u please help me

  24. asma feloussi October 31, 2014 at 14:18

    Lecture des informations d’état… Fait
    E: Impossible de trouver le paquet libcr-dev
    E: Impossible de trouver le paquet mpich2
    E: Impossible de trouver le paquet mpich2-doc

    solution???????????????

  25. Stephen Russell December 8, 2014 at 07:39

    I installed mpich on Ubuntu 14.10 just minutes ago. Hello.c runs but as my machine has 4 processors, and Hello.c only said “Hello” twice, I altered the “mpirun -np 2 ./hello”, changing the 2 to 4, then to 16 and then to 87. In each case Hello.c output “Hello” the number of times that I specified. (2 -> two “Hellos”, 4 -> four “Hellos”, 16 -> sixteen “Hellos” and 87 -> eighty-seven “Hellos”. What does this mean, other than something is running. Is it a new and inexpensive way to upgrade my hardware / 🙂
    Steve

    • jetcracker December 10, 2014 at 03:55

      If you have a machine with multiple CPUs or a configured cluster of machines you can utilise their computing power.
      MPI encapsulates a protocol that you must follow when you write your program. Also it provides means to run your program on all machines in the cluster.

      If you want to gain a performance boost, you should divide the computation problem into small parts and write a program using MPI primitives. Your task is to distribute (map) the parts of the whole computation problem between all running nodes (usually at the beginning of the code), and then collect (reduce) the result into one main node (usually the node number 0, at the end of your program).

      You can easily get a performance boost when you want to find a solution for a multi-dimentional differential equation.

      But nowadays, I’m quite far from parallel programming. I write apps for Android now. Good luck 🙂

  26. marios December 8, 2014 at 18:39

    How can I unistall ?

  27. Pingback: How To Fix Symbol Lookup Error Ubuntu in Windows

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: