On the installation of mpi.h for C in Ubuntu

c mpi
13,126

Solution 1

Can you try:

module add gcc mpich2
mpicc mpi_hello.c

?

Edit: Oh wow, I completely misread your post. You successfully compiled it by the looks of it with mpicc hello_world.c

Now you should be able to execute a.out with

mpirun -np 2 ./a.out

where 2 = the number of processors. Using your code and a fresh install:

beaty@korriban:~$ mpicc test.c
beaty@korriban:~$ mpirun ./a.out

Hello world from process 0 of 1
You have just one processor!

beaty@korriban:~$ mpirun -np 2 ./a.out

Hello world from process 0 of 2

Hello world from process 1 of 2

Solution 2

You'll need to make sure your include path is updated so the compiler can find mpi.h if it's not installed in a standard location.

Share:
13,126
Admin
Author by

Admin

Updated on June 14, 2022

Comments

  • Admin
    Admin almost 2 years

    I would like to start with MPI/C and I want to compile/execute the standard program mpi_hello. I succeeded regarding mpicc but I got an error message when I compile the file. Here is the program:

    #include <mpi.h>
    #include <stdio.h>
    
    int main (int argc, char* argv[])
    
    {
    
    int mynode, totalnodes;
    
      MPI_Init(&argc,&argv);
      MPI_Comm_size(MPI_COMM_WORLD, &totalnodes);
      MPI_Comm_rank(MPI_COMM_WORLD, &mynode);
    
      printf( "\nHello world from process %d of %d\n", mynode, totalnodes );
      if(totalnodes==1) printf("You have just one processor!\n");
      MPI_Finalize();
      return 0;
    
    }
    

    I got the following:

    turb@turb-LIFEBOOK-AH531:~/Desktop/Prog$ mpicc mpi_hello.c
    turb@turb-LIFEBOOK-AH531:~/Desktop/Prog$ cc -O3 mpi_hello.c
    mpi_hello.c:6:17: fatal error: mpi.h: No such file or directory
     #include <mpi.h>
                     ^
    compilation terminated.
    

    I would appreciate your help. Thank you! a