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.
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):
Using this I can construct the
where
COMP_DIR
has to be set manually (e.g.COMP_DIR = /usr/bin/mpif90
orCOMP_DIR = /usr/bin/gfortran
) andCOMP_FLAGS
are additional flags (e.g. '-g O0'), as well as thewhere again
LINK_DIR
has to be set manually (e.g./usr/bin/g++
) andLINK_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):
and the main program:
where
ObjectFiles
contains a list of all the files in the project andLINK_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
in the main petsc directory, as described here...