0

I have a C MPI program that runs well but my challenge is to compile it with a Makefile. The C file is named frequencyMPI.c and I have drafted the Make file named makefile.frequencyMPI. The makefile successfully compiled on Linux terminal but I don't know how to run it. My problem is how to run it and whether it is correct. The content of the Makefile is given below:

all: program

program: frequencyMPI.o
    mpicc frequencyMPI.o -o program

frequencyMPI.o: frequencyMPI.c
    mpicc -c frequencyMPI.c -o frequencyMPI.o

clean:
    rm -f frequencyMPI.o program core *~
7
  • 1
    1. What do you mean by "The makefile successfully compiled"? You can't compile Makefiles... did you run make or gmake, specifying your Makefile with -f makefile.frequencyMPI? 2. Have you considered using CMake instead, and letting it generate the Makefile for you? Here is an explanation on how to do that. It also takes care of locating relevant libraries if they are not in the include path already. 3. Are you sure you want to run the mpicc wrapper rather than compiling directly? Commented Oct 2, 2021 at 19:09
  • what I meant by compiling successfully was that when I entered make -f makefile.frequencyMPI it did not give any errors Commented Oct 2, 2021 at 19:12
  • Please use block code formatting when including examples (e.g., indent all lines by 4+ spaces). As mentioned above you don't "compile makefiles"; you run make, which uses the instructions in the makefile to build your software. The above makefile builds a program named program. Did you try to run that program? If the problem is that it didn't work then we need to know, what did you type? What errors did you get? Commented Oct 2, 2021 at 19:44
  • 1
    After running the makefile with make -f makefile.frequencyMPI it generated frequencyMPI.o in the directory. I tried running it with ./frequencyMPI.o it says permission denied then i tried sudo ./frequencyMPI.o then it says command not found. Normally when I compile with mpicc on terminal I run with mpirun -np 3 ./frequencyMPI.o but for a make file executable, I don't know how to execute it to know if it correct. Secondly, my program is not named program, it is named frequencyMPI.c Commented Oct 2, 2021 at 19:59
  • 1
    Just for terminology's sake, your program is not frequencyMPI.c. That's the source code for your program. Also frequencyMPI.o is not a program either and cannot be run from the command line, it's an object file which represents the compiled version of your source code. Then you have to link that object file into a program, or executable file, that you have named program here. Then you can run the executable file. Commented Oct 2, 2021 at 21:12

1 Answer 1

-1

Using open MPI: mpicc to compile and mpirun to run the code

So you would do:

  • make, to compile program
  • mpirun program, to run your parallel code
Sign up to request clarification or add additional context in comments.

1 Comment

That does not answer the question. The issue was the mpirun command line and was diagnosed in the comments section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.