# Generic Makefile for compiling a program that uses MPI # # Do NOT copy and paste this file, but rather save it, as make(1) depends on # tabs -- copy and paste would turn those into normal whitespace. # # Example code is in the file "integral.c". # Replace "trapezoid" with the name of the executable to create TARGET= trapezoid # Number of Processors to run this program on NP= 30 # List the object-files needed; usually, these are the names of the # source-files with the ending substituted with ".o" OFILES= integral.o # Libraries to link with. # In addition to the MPI library, this examples needs libm.so for the use of # the sin(3) function. LDFLAGS= -lmpich -lm # Common prefixes on our machines. PREFIX= /usr/pkg X11PREFIX= /usr/X11R6 # Common flags passed to the compiler while compiling CFLAGS= -Wall # Where to find the header files. INCLUDES= -I${PREFIX}/include -I${X11PREFIX}/include # Where to find the libraries LIBDIRS= -L${PREFIX}/lib -L${X11PREFIX}/include # the famous 'all' target, invoked if you type 'make' or 'make all' all: ${TARGET} # TARGET depends on the object files, created through the # .c.o: rule. It then calls the compiler to link the object-files into the # executable. Note that library parameters are position sensitive. ${TARGET}: ${OFILES} ${CC} ${LIBDIRS} ${OFILES} -o ${TARGET} ${LDFLAGS} # automatically compile each .c-file or .cpp-file into a .o-object file .cpp.o .c.o: ${CC} ${INCLUDES} ${CFLAGS} -c $< -o $@ # run the executable on the specified number of machines using mpirun(1) # Note: if you just invoke the executable, it will only run on the local # machine! You need to use mpirun(1). run: ${PREFIX}/bin/mpirun -np ${NP} ./${TARGET} # rm object files and executable before compiling everything from scratch clean: rm -f ${TARGET} ${OFILES}