To simplify compiling your parallel code, we will be using a Makefile to compile our code. Even otherwise, it's always strongly recommended to use Makefiles to compile any code you write.
Note: If you copied the source tree of example programs from the HPC account in the initial part of this workshop, then you should already have the Makefiles in place, ready to be used. If you did not, then you could copy and paste the following makefile into the HelloWorld , RoundRobin , ParallelPi , and ParallelDiffusion directories. See Couple of important points following the Makefile on this page.
We won't bother with makefiles for the serial code. If your knowledge of makefiles is limited, don't worry, because you don't need to know anything about them to complete this tutorial. Want to learn more about Makefiles?
#!/sh/bin
## Makefile for HPC @ IU tutorial Feb/March/May 2005
## Author: Arvind Gopu; Please send comments/suggestions to hpc in the indiana.edu domain
## Content based on Makefile, Gustav Meglicki wrote for I50 class: beige.ucs.indiana.edu/I590
## Where to install stuff
DESTDIR = /N/B/$(USER)/bin
MANDIR = /N/B/$(USER)/man/man1
## For C++ code, use mpiCC
## For Fortran77/90 code, use mpif77/mpif90 respectively
## You might need to change compiler/linker flags
## Currently should use /N/soft/linux-rhel3-ia32/lam-gm-7.1.1-intel/bin/mpicc
CC = mpicc
## We need to include VT.h for Intel Trace* profiling instrumentation.
## Use -g in CFLAGS for TotalView; Need to link to the IntelTrace* library
## Included in CPATH and LPATH respectively; No need to include 'em here
# CFLAGS = -g -I/N/soft/linux-rhel3_AS-ia32/intel-traceAC/itc/lam/include
# LIBS = -L/N/soft/linux-rhel3_AS-ia32/intel-traceAC/itc/lam/lib
CFLAGS = -g
## Link with ITA/C library (libVT) and its dependencies
LDFLAGS = -lVT -ldwarf -lelf -lm
## Change this to the program you are trying to compile
TARGET=helloWorld
$(TARGET): $(TARGET).o
$(CC) -o $@ $(TARGET).o $(LIBS) $(LDFLAGS)
$(TARGET).o: $(TARGET).c
$(CC) $(CFLAGS) -c $(TARGET).c
.PHONY: install
install: all $(TARGET).1
[ -d $(DESTDIR) ] || mkdirhier $(DESTDIR)
install $(TARGET) $(DESTDIR)
[ -d $(MANDIR) ] || mkdirhier $(MANDIR)
install $(TARGET).1 $(MANDIR)
.PHONY: clean
clean:
rm -f *.o $(TARGET) $(TARGET)*.stf* $(TARGET)*.prot
.PHONY: clobber
clobber: clean
rcsclean
Make needs a tab, not spaces! If indeed you decided to build your own set of example programs and Makefiles, then after you copy and paste the above Makefile, you must change the spaces into tabs in the twelve or so indented lines. In your text editor backspace each of those lines to the left margin, then hit the tab key once. The make command requires that these command lines begin with exactly one tab; see the above listed tutorial or other documentation for more information.
Which compiler to use? If you are going to use the example C source codes from this tutorial, then you do not need to modify this makefile. If you code in C++ or Fortran 77 or Fortran 90, then you must change the CC variable in the following makefile to mpiCC, mpif77 or mpif90 respectively.
What is LDFLAGS defined for? In the latter half of this tutorial, you'll be using Intel Trace Analyzer to profile your parallel code. The libraries listed in LDFLAGS (-lVT and its dependencies) in the above Makefile cause profiling files to generated when you run your parallel code.
| Previous: My First MPI Program | Up: Table of Contents | Next: Basic Concepts in Parallel Programming |
|---|