0

I have absolutely no experience in using makefile for MPI program with OpenMP. I usually run on the command prompt as

mpicc main.c -fopenmp -o Out
mpirun -np 4 Out

So now I need to utilise the makefile and my understanding is that we use makefile to run the commands in a more convenient way so logically we should type the same commands in the makefile right? So my makefile now looks like this

all: 
    mpicc main.c -fopenmp -o Out
    mpirun -np 4 Out

Is there a step by step guide on how to create a makefile for absolute beginner?

1 Answer 1

1

Makefiles are commonly used for build/compile, test, install and uninstall programs and pieces of code. It's not very common to use it to actually run the programs, but yes, you can do it. You can create a specific rule to it, like run

CC=mpicc
CFLAGS=-fopenmp
EXE=./Out
SRCS=main.c

all:
    $(CC) $(CFLAGS) $(SRCS) -o $(EXE)

run:
    mpirun -np 4 $(EXE)

So you can compile it with just make and then invoke it with make run

NOTE: the space preceding the commands inside a rule must be a tab

Is there a step by step guide on how to create a makefile for absolute beginner?

You can give a look on this page from University of Oxford

Sign up to request clarification or add additional context in comments.

Comments

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.