|
[Sponsors] |
January 24, 2014, 15:09 |
Adding PETSc to my userdefined Makefile
|
#1 |
New Member
Mahnaz
Join Date: Jan 2014
Posts: 5
Rep Power: 12 |
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. |
|
January 24, 2014, 17:54 |
|
#2 |
Member
Join Date: May 2012
Posts: 68
Rep Power: 14 |
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 |
|
January 25, 2014, 13:34 |
|
#3 |
New Member
Mahnaz
Join Date: Jan 2014
Posts: 5
Rep Power: 12 |
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 |
|
January 25, 2014, 14:21 |
|
#4 |
Senior Member
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20 |
||
January 25, 2014, 14:21 |
|
#5 |
Member
Join Date: May 2012
Posts: 68
Rep Power: 14 |
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 |
|
January 25, 2014, 15:37 |
|
#6 |
New Member
Mahnaz
Join Date: Jan 2014
Posts: 5
Rep Power: 12 |
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. |
|
January 25, 2014, 15:46 |
|
#7 |
New Member
Mahnaz
Join Date: Jan 2014
Posts: 5
Rep Power: 12 |
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
|
|
January 25, 2014, 15:46 |
|
#8 |
Senior Member
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20 |
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.
|
|
January 25, 2014, 16:10 |
|
#9 |
New Member
Mahnaz
Join Date: Jan 2014
Posts: 5
Rep Power: 12 |
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.
|
|
January 26, 2014, 13:51 |
|
#10 |
Senior Member
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20 |
http://www.mcs.anl.gov/petsc/documen...5/tutorial.pdf
Did you find this? Have a look at around slide 140! |
|
Tags |
c++, linux server, petsc |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
problem with Min/max rho | tH3f0rC3 | OpenFOAM | 8 | July 31, 2019 09:48 |
chtMultiRegionSimpleFoam | samiam1000 | OpenFOAM Running, Solving & CFD | 39 | March 31, 2016 08:43 |
chtMultiRegionSimpleFoam: strange error | samiam1000 | OpenFOAM Running, Solving & CFD | 26 | December 29, 2015 22:14 |
using petsc for large coupled linear systems | sd_vakip | Main CFD Forum | 0 | January 31, 2011 12:22 |
Help with chtMultiRegionFoam | jbvw96 | OpenFOAM Running, Solving & CFD | 2 | December 26, 2010 17:16 |