问题
I was reading and practicing MPI programs from a tutorial. There I saw an example of finding a rank of a process. But the same example is giving different output on my machine(Ubuntu 10.04).. Here is the program
#include <stdio.h>
#include <mpi.h>
main(int argc, char **argv)
{
int ierr, num_procs, my_id;
ierr = MPI_Init(&argc, &argv);
/* find out MY process ID, and how many processes were started. */
ierr = MPI_Comm_rank(MPI_COMM_WORLD, &my_id);
ierr = MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
printf("Hello world! I'm process %i out of %i processes\n",
my_id, num_procs);
ierr = MPI_Finalize();
}
The expected output according to the tutorial is
Expected Output :
Hello world! I'm process 0 out of 4 processes.
Hello world! I'm process 2 out of 4 processes.
Hello world! I'm process 1 out of 4 processes.
Hello world! I'm process 3 out of 4 processes.
Output which I am getting
Hello world! I'm process 0 out of 1 processes
Hello world! I'm process 0 out of 1 processes
Hello world! I'm process 0 out of 1 processes
Hello world! I'm process 0 out of 1 processes
My machine uses intel i3,Dell Inspiron and is having Ubuntu 10.04 OS.Help me resolving the problem.
回答1:
I have just compiled and run your program on my Ubuntu:
tom@tom-ThinkPad-T500:~/MPI_projects/Start/net2/net2/bin/Debug$ mpirun -n 6 ./output
Hello world! I'm process 3 out of 6 processes
Hello world! I'm process 4 out of 6 processes
Hello world! I'm process 0 out of 6 processes
Hello world! I'm process 2 out of 6 processes
Hello world! I'm process 1 out of 6 processes
Hello world! I'm process 5 out of 6 processes
Enter the folder with your executable file and run:
mpirun -np 2 ./output
or
mpirun -np 6 ./output
the flag -np modifies the number of called processes (http://linux.die.net/man/1/mpirun).
You can also run mpirun
without any flags to display lots of useful info.
Another interesting command is mpirun -info
, which will show print MPI build information.
This is the first part of my output:
tom@tom-ThinkPad-T500:~/MPI_projects/Start/net2/net2/bin/Debug$ mpirun -info
HYDRA build details:
Version: 1.4.1
Release Date: Wed Aug 24 14:40:04 CDT 2011
The last resort is to re-install or update your MPI using, for example, the following command : sudo apt-get install libcr-dev mpich2 mpich2-doc
来源:https://stackoverflow.com/questions/15095121/mpi-unexpected-output