0

I have a test code like this:

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

int main(int argc, char** argv) {
  MPI_Init(NULL, NULL);

  int world_size;
  MPI_Comm_size(MPI_COMM_WORLD, &world_size);

  int world_rank;
  MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

  char processor_name[MPI_MAX_PROCESSOR_NAME];
  int name_len;
  MPI_Get_processor_name(processor_name, &name_len);

  printf("Hello world from processor %s, rank %d out of %d processors\n",
         processor_name, world_rank, world_size);

  MPI_Finalize();
}

and make file like this:

EXECS=mpi_hello_world
MPICC?=mpicc

all: ${EXECS}

mpi_hello_world: mpi_hello_world.c
    ${MPICC} -o mpi_hello_world mpi_hello_world.c

clean:
    rm -f ${EXECS}

When running:

mpirun ./mpi_hello_world

got these:

Hello world from processor x-space, rank 2 out of 6 processors
Hello world from processor x-space, rank 3 out of 6 processors
Hello world from processor x-space, rank 4 out of 6 processors
Hello world from processor x-space, rank 1 out of 6 processors
Hello world from processor x-space, rank 5 out of 6 processors
Hello world from processor x-space, rank 0 out of 6 processors

All cores got used

And when running:

 mpiexec.hydra ./mpi_hello_world

Got these

Hello world from processor x-space, rank 0 out of 1 processors

Only one core got used

When running:

mpiexec.hydra -n 6 ./mpi_hello_world

Got these:

Hello world from processor x-space, rank 0 out of 1 processors
Hello world from processor x-space, rank 0 out of 1 processors
Hello world from processor x-space, rank 0 out of 1 processors
Hello world from processor x-space, rank 0 out of 1 processors
Hello world from processor x-space, rank 0 out of 1 processors
Hello world from processor x-space, rank 0 out of 1 processors

Still,only one core got used

Question is:

When using mpiexec.hydra to run,how to use all cores?
Alex Luya
  • 9,412
  • 15
  • 59
  • 91

0 Answers0