7

Following is my code in MPI, which I run it over a core i7 CPU (quad core), but the problem is it shows me that it's running under 1 processor CPU, which has to be 4.

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

    MPI_Init(&argc, &argv);

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    printf("Hello world! I am %d of %d\n", rank, size);

    MPI_Finalize();

    return 0;
}

I was wondering if the problem is with MPI library or sth else?

Here is the result that it shows me:

Hello world! I am 0 of 1

Additional info: Windows 7 - Professional x64

Foo Bah
  • 25,660
  • 5
  • 55
  • 79
Gabriel
  • 578
  • 3
  • 8
  • 22
  • how are you running the program? – Foo Bah Sep 15 '11 at 21:00
  • 2
    You might want to add how you're running the code - typically MPI executables have to be run using a command like `mpirun -np 4 mympiexecutable` to get them to run on 4 processors, for example, but I don't really know Windows MPI versions. – Aesin Sep 15 '11 at 21:00
  • Note: it is important to put the "-n 4" before the name of the executable. On my machine, if it is after, then it is ignored. – Paul Wintz May 08 '19 at 08:47

1 Answers1

13

Prima facie it looks like you are running the program directly. Did you try using mpiexec -n 2 or -n 4?

Foo Bah
  • 25,660
  • 5
  • 55
  • 79
  • yes, I did that and it works fine, but I copied that example from a book which said if for example you have a dual core CPU, you'd get 2 for the result. So here i have a quad core CPU so I should get 4 in result. – Gabriel Sep 15 '11 at 23:45
  • If you run it without explicitly using an mpi wrapper, it will run assuming a single core. – Foo Bah Sep 15 '11 at 23:46
  • 4
    @Gabriel Lets say you made `test.exe`. Then, if you just run `test` it will use 1 core. If you use mpiexec -n 4 test.exe then it will know to use 4 instances. – Foo Bah Sep 16 '11 at 02:38