PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

g77 makefle conversion to pgf90

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
EBD



Joined: 12 Dec 2005
Posts: 7

PostPosted: Wed Mar 15, 2006 12:01 pm    Post subject: g77 makefle conversion to pgf90 Reply with quote

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.

Code:
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
Back to top
View user's profile
Christopher Hulbert



Joined: 01 Dec 2005
Posts: 76

PostPosted: Wed Mar 15, 2006 12:20 pm    Post subject: Reply with quote

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.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6206
Location: The Portland Group Inc.

PostPosted: Wed Mar 15, 2006 1:45 pm    Post subject: Reply with quote

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:
Code:

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:
Code:
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
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group