2

I'm new to MPI and generally parallel programming so this might be too obvious for some of you.

I want to run a simple hello world program, using all of my cores.

I currently installed and configured MPICH3 as shown here (I know the tutorial is about MPICH2 but that's the closest I've found).

I copied this code:

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

int main(int argc, char** argv) {
    // Initialize the MPI environment
    MPI_Init(NULL, NULL);

    // Get the number of processes
    int world_size;
    MPI_Comm_size(MPI_COMM_WORLD, &world_size);

    // Get the rank of the process
    int world_rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

    // Get the name of the processor
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    int name_len;
    MPI_Get_processor_name(processor_name, &name_len);

    // Print off a hello world message
    printf("Hello world from processor %s, rank %d out of %d processors\n",
           processor_name, world_rank, world_size);

    // Finalize the MPI environment.
    MPI_Finalize();
}

And I tried to compile it like this mpicc mpi_implementation.c. So far, everything is good. The problem is, that when I run it using mpiexec -np 4 ./a.out I get the following output:

Hello world from processor grodeBase, rank 0 out of 1 processors
Hello world from processor grodeBase, rank 0 out of 1 processors
Hello world from processor grodeBase, rank 0 out of 1 processors
Hello world from processor grodeBase, rank 0 out of 1 processors

Practically that's right, since I only have one processor, but my point is to run the program on many cores and I have no idea how to do that. Does it happen automatically and I just don't see it? Is there any way to make sure that all of my cores are used? And also, how can I refer to one of them specifically?

P.S. If you need any further information, let me know.

  • 1
    That typically occurs when you use `mpiexec` from one MPI library (e.g. MPICH) and your app is using `libmpi.so` from an other one (e.g. Open MPI). you can `which mpiexec` and `ldd ./a.out` to double a single MPI implementation is used (and then use the `mpiexec` corresponding to the `libmpi.so` used by your app. – Gilles Gouaillardet Oct 28 '19 at 23:46

0 Answers0