I'm beginning with MPI. I wanted to try a classical "Hello, world" program, which will print number of every process too and a few other informations too. My program works, but I'm little confused about how mpiexec really works. The problem is, when I specify the number of processes, sometimes they just don't get launched. For example, I use this command:
mpiexec -np 4 ./hello
but only 2 or 3 processes get launched, not 4. This number of launched processes changes, so I'm really confused. Is the problem in my pc (I have only dualcore) or is this normal?
hello.c:
#include <stdio.h>
#include <mpi.h>
int main(){
MPI_Init(NULL, NULL);
// Number of processes
int world_size;
MPI_Comm_size( MPI_COMM_WORLD, &world_size );
// Number of current process
int process_id;
MPI_Comm_rank( MPI_COMM_WORLD, &process_id );
// Processor name
char processor_name[ MPI_MAX_PROCESSOR_NAME ];
int name_len;
MPI_Get_processor_name( processor_name, &name_len );
printf("Hello! - sent from process %d running on processor %s.\n\
Number of processes is %d.\n\
Length of proc name is %d.\n\
***********************\n",
process_id, processor_name, world_size, name_len);
return 0;
}
My mistake was pretty silly. I was just missing MPI_Finalize() function before return.
#include <stdio.h>
#include <mpi.h>
int main(){
MPI_Init(NULL, NULL);
// Number of processes
int world_size;
MPI_Comm_size( MPI_COMM_WORLD, &world_size );
// Number of current process
int process_id;
MPI_Comm_rank( MPI_COMM_WORLD, &process_id );
// Processor name
char processor_name[ MPI_MAX_PROCESSOR_NAME ];
int name_len;
MPI_Get_processor_name( processor_name, &name_len );
printf("Hello! - sent from process %d running on processor %s.\n\
Number of processes is %d.\n\
Length of proc name is %d.\n\
***********************\n",
process_id, processor_name, world_size, name_len);
MPI_Finalize();
return 0;
}