2

I am a beginner trying to learn MPI. I have tried to run the following program downloaded from internet:

    #include <stdio.h>
    #include <mpi.h>

    int main (argc, argv)
         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;
    }

The code has been compiled with mpicc and executed with mpirun.

mpicc HelloWorld.c
mpirun -np 4 a.out

The output is as follows:

Hello world from process 0 of 1
Hello world from process 0 of 1
Hello world from process 0 of 1
Hello world from process 0 of 1

My question is, why the output has generated only one process and not 4 processes as requested?

Rohit Maitri
  • 21
  • 1
  • 2
  • How many cores do you have? I managed to run it on my machine i7, 8 cores and got expected output. – Mon Calamari Dec 02 '14 at 16:25
  • Even I tried this on other pc and managed to get desired result. But in my pc, the issue persists. The `nproc` value from pc is 12. – Rohit Maitri Dec 02 '14 at 16:32
  • I guess generating processes is core (hardware) independent. – Rohit Maitri Dec 02 '14 at 16:32
  • 3
    possible duplicate of [MPI\_Rank return same process number for all process](http://stackoverflow.com/questions/20287564/mpi-rank-return-same-process-number-for-all-process) – Hristo Iliev Dec 02 '14 at 16:45
  • Thanks for the reply. I tried to follow the link of a discussion but `which mpicc` and `which mpirun` are returning the location on computer. Hence, I could not really make conclusion if they are from the same version or not. Is there any other way I could do it? – Rohit Maitri Dec 05 '14 at 09:21
  • I have met the same problem. And finally I found that I installed openmpi and mpich simultaneously on my ubuntu. I uninstalled both of them completely and then only installed libmpich-dev. Then the problem was solved for me. – Eric Yang Aug 30 '18 at 12:01

2 Answers2

-1

This problem occurs when mpicc and mpirun are not from the same MPI Implementation.
You can do uninstall openmpi and mpich and install only mpich lib.

Run these commands in your terminal.
sudo apt-get remove --auto-remove openmpi-bin
sudo apt-get remove --auto-remove mpich
sudo apt-get install mpich

manask322
  • 123
  • 1
  • 8
-1

The following solved my problem:

sudo apt-get remove --auto-remove openmpi-bin
sudo apt-get remove --auto-remove mpich
sudo apt-get install mpich
sudo apt install lam-runtime     
sudo apt install mpich           
sudo apt install openmpi-bin     
sudo apt install slurm-wlm-torque
dbc
  • 104,963
  • 20
  • 228
  • 340