CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Adding PETSc to my userdefined Makefile

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 24, 2014, 16:09
Default Adding PETSc to my userdefined Makefile
  #1
New Member
 
Mahnaz
Join Date: Jan 2014
Posts: 5
Rep Power: 12
Mahnaz is on a distinguished road
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.
Mahnaz is offline   Reply With Quote

Old   January 24, 2014, 18:54
Default
  #2
Member
 
Join Date: May 2012
Posts: 68
Rep Power: 14
som87 is on a distinguished road
Hi there, yes it's possible.
I successfully linked PetSC's TS module (the time stepper) to my solver.Let me try to explain the procedure:-
In my time step module i have set a binary switch which allows the solver to pick between eulerian or time-integration m/d of petsc.Depending on the switch the solver calls (compiled)petsc modules while running.

Regarding your makefile configuration, I use the configuration file (similar to Overture pack by Henshaw) to set the the options. But you can very well write two separate makefiles and use them for compilation. Just set the "Make.in" file as switch for your make.

I am not sure if it helps.But feel free to mail me if you dont find difficulties.

PS:- the linking part is done by setting the library like this:-
lib= -L/your-pet-sc-location \
-L/(other library locations..eg fftw)
__________________
Best wishes,

Somdeb Bandopadhyay
som87 is offline   Reply With Quote

Old   January 25, 2014, 14:34
Default
  #3
New Member
 
Mahnaz
Join Date: Jan 2014
Posts: 5
Rep Power: 12
Mahnaz is on a distinguished road
som87: Thank you very much for explanation. Can you explain more in detail how can I call PETSc makefile in another makefile?

I added the following commands in my own makefile to make it ready in a way that it would compile PETSc as well, but it did not work.

#PETSC_DIR = /opt//petsc-3.4.2
#PETSC_ARCH = arch-linux2-cxx-debug arch-linux2-cxx-debug/include arch-linux2-cxx-debug/bin/mpicxx arch-linux2-cxx-debug/lib
#CPPFLAGS =
#MANSEC = KSP
#All : tport_SolveLS.cpp \
#CLEANFILES : tport_SolveLS.cpp \



## PETSc Includes: ################################################## ##################################

#include ${PETSC_DIR}/conf/petscvariables
#include ${PETSC_DIR}/conf/variables
#include ${PETSC_DIR}/conf/rules
#include ${PETSC_DIR}/conf/test

## PETSc Linking: ################################################## ###################################

#tport_SolveLS: tport_SolveLS.o chkopts
# -${CLINKER} -o tport_SolveLS tport_SolveLS.o ${PETSC_LIB} $(DIR_XNL)/lib/XNL.a
# ${RM} tport_SolveLS.o

## PETSc Running: ################################################## ###################################

#runtport_SolveLS:
# -@${MPIEXEC} -n 1 ./tport_SolveLS -ksp_monitor_short -ksp_gmres_cgs_refinement_type refine_always
Mahnaz is offline   Reply With Quote

Old   January 25, 2014, 15:21
Default
  #4
Senior Member
 
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20
cfdnewbie is on a distinguished road
Quote:
Originally Posted by Mahnaz View Post
#PETSC_DIR = /opt//petsc-3.4.2
this line looks wrong, there shouldnt be two //
cfdnewbie is offline   Reply With Quote

Old   January 25, 2014, 15:21
Default
  #5
Member
 
Join Date: May 2012
Posts: 68
Rep Power: 14
som87 is on a distinguished road
from what i understand, your code is using the "some part of" petsc module right? why dont you compile petsc first, then just build the dependency..?
After [make -C] you can use { [input-your-petsc-dir] [the-required-librry-in-petsc]}

Edit:- If he is using Bourne shell, double slash wont cause an prob...worth a check though
__________________
Best wishes,

Somdeb Bandopadhyay
som87 is offline   Reply With Quote

Old   January 25, 2014, 16:37
Default
  #6
New Member
 
Mahnaz
Join Date: Jan 2014
Posts: 5
Rep Power: 12
Mahnaz is on a distinguished road
So if understood right, I dont have to change my basic makefile.
Do I just have to compile PETSc first with using {make -C /opt/petsc-3.4.2/src/ksp} and then make my own c++ code (which I used {make clean ; make all} to compile) without adding anything special to the basic makefile? I did this process and it didnt work. I would be grateful if tell me how to create the dependency. I really need to link PETSc to my code.
Mahnaz is offline   Reply With Quote

Old   January 25, 2014, 16:46
Default
  #7
New Member
 
Mahnaz
Join Date: Jan 2014
Posts: 5
Rep Power: 12
Mahnaz is on a distinguished road
I just added { #include "tport_SolveLS.hpp" } in one of my codes. Then I compiled PETSc by using {make -C /opt/petsc-3.4.2/src/ksp} and then I compiled my own code by using {make clean ; make all} but the error showed that my code did not understand PETSc library and it shows : error: petscksp.h: No such file or directory
Mahnaz is offline   Reply With Quote

Old   January 25, 2014, 16:46
Default
  #8
Senior Member
 
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20
cfdnewbie is on a distinguished road
Just compile PetSC and find out where it puts the libraries. Then link during your compile process against these libs. You should maybe also google about how to link external libs to your code, that should be well explained in many places.
cfdnewbie is offline   Reply With Quote

Old   January 25, 2014, 17:10
Default
  #9
New Member
 
Mahnaz
Join Date: Jan 2014
Posts: 5
Rep Power: 12
Mahnaz is on a distinguished road
Thank you very much for your suggestion. I googled about it very much. My problem is exactly how to link my code to PETSc library during compiling.
Mahnaz is offline   Reply With Quote

Old   January 26, 2014, 14:51
Default
  #10
Senior Member
 
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20
cfdnewbie is on a distinguished road
http://www.mcs.anl.gov/petsc/documen...5/tutorial.pdf

Did you find this? Have a look at around slide 140!
cfdnewbie is offline   Reply With Quote

Reply

Tags
c++, linux server, petsc


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with Min/max rho tH3f0rC3 OpenFOAM 8 July 31, 2019 10:48
chtMultiRegionSimpleFoam samiam1000 OpenFOAM Running, Solving & CFD 39 March 31, 2016 09:43
chtMultiRegionSimpleFoam: strange error samiam1000 OpenFOAM Running, Solving & CFD 26 December 29, 2015 23:14
using petsc for large coupled linear systems sd_vakip Main CFD Forum 0 January 31, 2011 13:22
Help with chtMultiRegionFoam jbvw96 OpenFOAM Running, Solving & CFD 2 December 26, 2010 18:16


All times are GMT -4. The time now is 14:04.