g77 makefle conversion to pgf90

Hi,

I did not find much in the docs on how to make a make file. I have a make file now that points to g77, and want to re-do it for pgf90. I tried replacing g77 and removing the -‘options’ with pgf90 through out, but that did not work.

Here is the current make file.

OBJECTS =dem.o force.o glueforce.o initial.o initialize.o\
         time_march.o output.o subinitial.o

block : $(OBJECTS) 
	g77 -O2  -o inclusion $(OBJECTS) -lm

dem.o: dem.f definitions.f
	g77 -O2 -c dem.f 
force.o: force.f definitions.f 
	g77 -O2 -c force.f
glueforce.o: glueforce.f definitions.f 
	g77 -O2 -c  glueforce.f
initial.o: initial.f definitions.f 
	g77 -O2 -c initial.f  
initialize.o: initialize.f definitions.f 
	g77 -O2 -c initialize.f 
time_march.o: time_march.f definitions.f 
	g77 -O2 -c time_march.f
output.o: output.f definitions.f 
	g77 -O2 -c output.f 
subinitial.o: subinitial.f definitions.f 
	g77 -O2 -c subinitial.f

What do I need to do to re-do this for PGI, and take advantage of MPI?

Where can you find general documentation about makefiles?

Thank
EBD

I would do something liek the following:

OBJECTS =dem.o force.o glueforce.o initial.o initialize.o
time_march.o output.o subinitial.o
F77=pgf77
FFLAGS=-O2
LDFLAGS=
LIBS=-lm

block : $(OBJECTS)
$(F77) $(FFLAGS) -o inclusion $(LDFLAGS) $(OBJECTS) $(LIBS)

dem.o: dem.f definitions.f
$(F77) $(FFLAGS) -c dem.f

and so forth.

Using a variable for the compiler name/flags makes it much easier when you want to change compilers or switch flags. To take advantage of MPI, your fortran programs will have to call MPI routines and link against the mpi libraries.

Hi EBD,

Everyone tends to have there own style of writing makefiles so your free to do what works best for you. Typically though, you want to use variables for portability and ease of use. For example:

SRC_DIR = ./
OBJ_DIR = ./
OBJX    = o
RM        = rm -f
MKDIR   = mkdir 
FC      = pgf90
LD      = $(FC)
OPT     = -O2
 
LIBS    = -lm
FFLAGS  = $(OPT) -c 
EXTRA_LDFLAGS = 
LDFLAGS = $(OPT) $(EXTRA_LDFLAGS)

EXE = inclusion

OBJECTS = $(OBJ_DIR)/dem.$(OBJX) $(OBJ_DIR)/force.$(OBJX) $(OBJ_DIR)/glueforce.$(OBJX) \
	  $(OBJ_DIR)/initial.$(OBJX) $(OBJ_DIR)/initialize.$(OBJX) \
	  $(OBJ_DIR)/time_march.$(OBJX) $(OBJ_DIR)/output.$(OBJX) \
	  $(OBJ_DIR)/subinitial.$(OBJX)

all : block

block : setup $(OBJECTS)
	$(LD) $(LDFLAGS) -o $(EXE) $(OBJECTS) $(LIBS)

setup:
        -$(MKDIR) $(OBJ_DIR)

$(OBJ_DIR)/dem.$(OBJX): $(SRC_DIR)/dem.f $(SRC_DIR)/definitions.f
	$(FC) $(FFLAGS) -o $(OBJ_DIR)/dem.$(OBJX) $(SRC_DIR)/dem.f

$(OBJ_DIR)/force.$(OBJX): $(SRC_DIR)/force.f $(SRC_DIR)/definitions.f
	$(FC) $(FFLAGS) -o $(OBJ_DIR)/force.$(OBJX)$(SRC_DIR)/force.f

$(OBJ_DIR)/glueforce.$(OBJX): $(SRC_DIR)/glueforce.f $(SRC_DIR)/definitions.f
	$(FC) $(FFLAGS) -o $(OBJ_DIR)/glueforce.$(OBJX) $(SRC_DIR)/glueforce.f

$(OBJ_DIR)/initial.$(OBJX): $(SRC_DIR)/initial.f $(SRC_DIR)/definitions.f
	$(FC) $(FFLAGS) -o $(OBJ_DIR)/initial.$(OBJX) $(SRC_DIR)/initial.f 

$(OBJ_DIR)/initialize.$(OBJX): $(SRC_DIR)/initialize.f $(SRC_DIR)/definitions.f
	$(FC) $(FFLAGS) -o $(OBJ_DIR)/initialize.$(OBJX) $(SRC_DIR)/initialize.f

$(OBJ_DIR)/time_march.$(OBJX): $(SRC_DIR)/time_march.f $(SRC_DIR)/definitions.f
	$(FC) $(FFLAGS) -o $(OBJ_DIR)/time_march.$(OBJX) $(SRC_DIR)/time_march.f

$(OBJ_DIR)/output.$(OBJX): $(SRC_DIR)/output.f $(SRC_DIR)/definitions.f
	$(FC) $(FFLAGS) -o $(OBJ_DIR)/output.$(OBJX) $(SRC_DIR)/output.f

$(OBJ_DIR)/subinitial.$(OBJX): $(SRC_DIR)/subinitial.f $(SRC_DIR)/definitions.f
	$(FC) $(FFLAGS) -o $(OBJ_DIR)/subinitial.$(OBJX) $(SRC_DIR)/subinitial.f 

clean:
         -$(RM) $(OBJ_DIR)/*.$(OBJX) $(EXE)

Granted, this may be more complex than you need, but I try and use variables for everything that might change. Things like the compiler, flags, libraries, directories, exe names, object file extensions (Linxu uses “.o”, Windows uses “.obj”), etc. This way you don’t need to edit the file in order to compile with g77 or pgf90. For example:

make FC=pgf90 OPT="-fastsse" OBJ_DIR="pgi_obj" EXE="inclusion_mpi" LIBS="-lm -lmpich" all
make FC=g77 OPT="-O2" OBJ_DIR="gnu_obj" EXE="inclusion_gnu" all

There are a lot of online tutorials on how to create Makefile, just type “Makefile tutorial” in your favorite search engine. Also, O’Reilly publishes a good book on using make.

Hope thsi helps,
Mat