<div dir="ltr">On Fri, Aug 16, 2013 at 6:37 PM, Frank <span dir="ltr"><<a href="mailto:fangxingjun0319@gmail.com" target="_blank">fangxingjun0319@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I am using PETSc to iterate a problem, that is to say I call KSPSolve repeatedly.<br>
Firstly, I write all the PETSc components in one subroutine, including "MatCreate", "VecCreateMPI", etc. Everything works fine.<br>
Then, I want to only initialize ksp once outside the loop, and the matrix and rhs is changed within the loop repeatedly. Here are my problem:<br>
<br>
1. I tried to use COMMON to transfer the following variables. I include "petsc.var" in the solver subroutine. It cannot be compiled.<br>
"petsc.var"<br>
Vec x,b<br>
Mat A<br>
KSP ksp<br>
PC pc<br>
COMMON /MYPETSC/x, b, A,ksp,pc<br>
<br>
2. I defined the following in the main program:<br>
PROGRAM MAIN<br>
#include <finclude/petscsys.h><br>
#include <finclude/petscvec.h><br>
#include <finclude/petscmat.h><br>
#include <finclude/petscpc.h><br>
#include <finclude/petscksp.h><br>
Vec x,b<br>
Mat A<br>
KSP ksp<br>
PC pc<br>
......<br>
CALL INIT_PETSC(ksp,pc,A,x,b)<br>
......<br>
CALL LOOP(ksp,pc,A,x,b)<br>
<br>
END PROGRAM<br>
!-----------------------------<u></u>----------------------<br>
SUBROUTINE LOOP(ksp,pc,A,x,b)<br>
Vec x,b<br>
Mat A<br>
KSP ksp<br>
PC pc<br>
......<br>
CALL SOLVE(ksp,pc,A,x,b)<br>
.......<br>
END SUBROUTINE<br>
!-----------------------------<u></u>----------------------<br>
SUBROUTINE SOLVE(ksp,pc,A,x,b)<br>
Vec x,b<br>
Mat A<br>
KSP ksp<br>
PC pc<br>
<br>
......<br>
CALL (ksp, b,x,ierr)<br>
END SUBROUTINE<br>
<br>
It can be compiled, but ksp does not iterate.<br>
<br>
Could you please explain to me the reason and solution for this problem.<br></blockquote><div><br></div><div>I do not understand "does not iterate". Is there an error message?</div><div><br></div><div> Thanks,</div>
<div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thank you very much.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener
</div></div>