C How do I create a Makefile for an MPI program?

I have 3 C files, they all form one C program. One of them is an MPI file called mpi.c, the others are read.c and write.c. I don’t know how to include mpi.c in my Makefile, here is if I got it so far (and it’s wrong):

   all: program

   program: mpi.o read.o write.o
        mpicc mpi.o read.o write.o -o program // I think this line is wrong

   mpi.o: mpi.c
        mpicc -o mpi.o mpi.c

   read.o: read.c
        gcc -c read.c -o read.o

   write.o: write.c
       gcc -c write.c -o write.o

   clean:
       rm -f write.o read.o mpi.o program core *~

      

+3


source to share


1 answer


I think this line:

mpicc -o mpi.o mpi.c

      

and what it should be

mpicc -c mpi.c -o mpi.o

      



or simply

mpicc -c mpi.c

      

As it stands, it tries to compile only mpi.c into the program mpi.o, when mpi.o should just be an object file.

+4


source







All Articles