Using PETSc on makefile within my user-defined makefile

Nazi

I am new in PETSc. I have a big c++ code and I want to add PETSc to some of the files that I already have, so I have to change my makefile in a way that it can compile PETSc as well.

Is it possible to have two different makefiles and then call PETSc makefile within my own makefile? if so, how can I do this?

Does anyone have any experience in linking PETSc to their own code?

By the way, I am using Linux as my operating system.

Toon

edit: Though this is an old post, I am sure there are still people struggling with this.

Furthermore, things apparently changed slightly for petsc 3.6.x (and slepc 3.6.x).

I currently use the following lines in my ubuntu 14.04 LTS makefile for F90 files (using both petsc 3.6.1 and slepc 3.6.0):

# PETSC and SLEPC directories
PETSC_DIR = /opt/petsc-3.6.1
SLEPC_DIR = /opt/slepc-3.6.0
include  $(PETSC_DIR)/lib/petsc/conf/variables
include  $(SLEPC_DIR)/lib/slepc/conf/slepc_variables

Using this I can construct the

# Compiler command
COMPILE = $(COMP_DIR) $(COMP_FLAGS) $(PETSC_FC_INCLUDES) $(SLEPC_INCLUDE)

where COMP_DIR has to be set manually (e.g. COMP_DIR = /usr/bin/mpif90 or COMP_DIR = /usr/bin/gfortran) and COMP_FLAGS are additional flags (e.g. '-g O0'), as well as the

# Link command
LINK = $(LINK_DIR) &(LINK_FLAGS)

where again LINK_DIR has to be set manually (e.g. /usr/bin/g++) and LINK_FLAGS contains additional flags (e.g. -fPIC).

These can then be used to create rules to compile the F90 files (I am sure C is pretty similar):

%.o : %.f90
$(COMPILE) -c $<

and the main program:

main:   $(ObjectFiles) main.o
$(LINK) -o $@ $(ObjectFiles) main.o $(LINK_LIB) $(PETSC_LIB) $(SLEPC_LIB)

where ObjectFiles contains a list of all the files in the project and LINK_LIB corresponds to other links (e.g. -lgfortran).

This works fine for me, yet suggestions for improvements are always welcome.

original post: Instead of the hack described by Divakar, you can easily find out the link flags and the include directories for compilation by running

make getlinklibs
make getincludedirs

in the main petsc directory, as described here...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Generic Makefile for PETSc

From Dev

Using "$**" to direct file input within a Makefile

From Dev

Is there a way to print all variables defined/visible within a makefile?

From Dev

Hard linking within makefile

From Dev

Hard linking within makefile

From Dev

Makefile: how to detect changes within the makefile itself?

From Dev

How to prompt user for [y/n] in my makefile (with pure make syntaxis)?

From Dev

How to make my Makefile compatible with Cygwin? (install: invalid user ‘root’)

From Dev

Makefile with user input validation

From Dev

What is wrong with my makefile?

From Dev

Beginner in writing makefile; checking my Makefile

From Java

Using a user-defined function within a CTE

From Dev

Test if a list of variables are defined in a Makefile

From Dev

Test if a list of variables are defined in a Makefile

From Dev

Git commit from within a Makefile

From Dev

with glfw -3.2.1 inside my work directory ,how to compile with it using makefile

From Dev

Using bash variables in Makefile

From Dev

Makefile path directory using ~/

From Dev

library is not created using makefile

From Dev

Running a binary using makefile

From Dev

Simple compiling using a Makefile?

From Dev

Makefile error using flex

From Dev

Using install -D in Makefile

From Dev

Makefile using $() instead of `` backticks

From Dev

Using a Makefile for Debain packages

From Dev

Reading User Input in a Makefile Script

From Dev

newb: what is wrong with my makefile?

From Dev

What is wrong with my makefile for C?

From Dev

Why is my makefile not working as expected?