2

Sorry, I'm sure making a silly mistake, but did not work out.

I'm compiling a simple mpi hello world:

#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;
}

And:

> mpicc -o hello_world_c hello_world.c
> mpirun -np 4 hello_world_c

But returns:

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

But my computer is a core i7 with 4 cores. And everything seems to be ok, ie. cat /proc/cpuinfo shows the 4 processors

what's happening??? Thanks in advance!!!!

John Fadria
  • 1,863
  • 2
  • 25
  • 31
  • 1
    Doesn't look like it's a problem with your MPI code. Which MPI library did you install? How did you install it? – Shawn Chin Apr 03 '12 at 10:02
  • 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) – Jonathan Dursi Jun 16 '14 at 15:19

4 Answers4

5

There is nothing wrong with your code. The only problem that can be is with your mpi installation.

Notice:

There is a differences between processor to core. its not the same thing.

lolo
  • 17,392
  • 9
  • 25
  • 49
  • How did you install it? what computer do you use? do you use win7? – lolo Apr 03 '12 at 10:21
  • no no, I use Ubuntu and a regular installation. Package mpich2 – John Fadria Apr 03 '12 at 10:51
  • 6
    Let me just add to this: the particular problem with the installation you're seeing here is probably that you're running your program with an mpirun which belongs to a different mpi installation than you compiled linked with. Make sure the same mpirun, mpicc, and your mpi libraries are first in your various paths. – Jonathan Dursi Apr 03 '12 at 12:53
  • Thanks everybody. The problem was two mpi installation. mpich2 and openmpi. I uninstall openmpi and everything works fine. Thanks!!! – John Fadria Apr 04 '12 at 06:09
1

In this case, you need mpiexec from the 'mpich2' package.

Firstly, remove all mpi packages that installed on your computer. If your server is Ubuntu, you can use the command:

sudo apt-get purge mpi mpich2 openmpi-common

To make sure that you have removed all the packages, try this command

which mpiexec

If you got nothing in response, you already removed all the packages.

Then reinstall the package of mpich2

sudo apt-get install mpich2

Try to compile and run your code again! Hope this help!

Kwang
  • 11
  • 1
0

INSTALL

sudo apt-get install libopenmpi-dev openmpi-bin openmpi-doc

Now compile and execute code

enter image description here

negi
  • 408
  • 7
  • 13
0

I don't know how you can compile it:

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

will be changed to

 int main (int argc, char *argv[])

another point is that mpi is message passing interface that passes messages between processes not cores or processors if you have a 4 core system you can run your code with so many processes as your ram permits but only 4 processes are working at any time and other processes must wait so it is efficient that you use only 4 process.

peaceman
  • 1,499
  • 2
  • 17
  • 29