<div dir="ltr"><div class="gmail_default" style="font-family:'trebuchet ms',sans-serif;color:rgb(68,68,68)">Yes. I move MPI_Init() outsidet the LOOP.</div><div class="gmail_default" style="font-family:'trebuchet ms',sans-serif;color:rgb(68,68,68)">
Now it works.</div><div class="gmail_default" style="font-family:'trebuchet ms',sans-serif;color:rgb(68,68,68)">Thanks you.</div><div class="gmail_extra"><br clear="all"><div><div dir="ltr">Best regards,<div>
Longxiang Chen</div><div><br></div><div><br></div></div></div>
<br><br><div class="gmail_quote">On Tue, Jun 25, 2013 at 4:58 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><br>
On Jun 25, 2013, at 6:50 PM, "Zou (Non-US), Ling" <<a href="mailto:ling.zou@inl.gov" target="_blank">ling.zou@inl.gov</a>> wrote:<br>
<br>
> Hmmm... I guess you cannot do PetscInitialize multiple times.<br>
<br>
</div> You must call PetscFinalize() each time before calling PetscInitialize() again. In addition you must call MPI_Init() your self ONCE at the beginning of the application code.<br>
<span><font color="#888888"><br>
Barry<br>
</font></span><div><div><br>
><br>
> Ling<br>
><br>
><br>
> On Tue, Jun 25, 2013 at 5:47 PM, Zou (Non-US), Ling <<a href="mailto:ling.zou@inl.gov" target="_blank">ling.zou@inl.gov</a>> wrote:<br>
> I have petsc 3.3p5 on my Mac.<br>
><br>
> PetscInitialize(NULL, NULL, NULL, NULL);<br>
><br>
> It seems working fine here.<br>
><br>
> Ling<br>
><br>
><br>
> On Tue, Jun 25, 2013 at 4:54 PM, Longxiang Chen <<a href="mailto:suifengls@gmail.com" target="_blank">suifengls@gmail.com</a>> wrote:<br>
> Dear all,<br>
><br>
> I try to use ksp to solve Ax=b.<br>
><br>
> ALL programs are in fortran, except petscsolve() in c.<br>
><br>
> Because petscsolve() is a sub-function that I don't have argc and argv.<br>
> So I use following statement to set the options.<br>
><br>
> PetscInitialize(NULL, NULL, NULL, help);<br>
> PetscOptionsSetValue("-ksp_type", "bcgs");<br>
> PetscOptionsSetValue("-pc_type", "jacobi");<br>
> PetscOptionsSetValue("-ksp_max_it", "100");<br>
> PetscOptionsInsert(NULL, NULL, NULL);<br>
><br>
> The program works like this:<br>
><br>
> main()<br>
> Init()<br>
> LOOP:<br>
> call MULTI (calculate Jacob A)<br>
> -> call petscsolve( solve Ax=b)<br>
> -> check solution<br>
> Goto LOOP<br>
><br>
> The first iteration works well that I can calculate the solution x from petscsolve().<br>
> But when it enters the second iteration of LOOP, it has Segmentation fault:<br>
><br>
> Program received signal SIGSEGV, Segmentation fault.<br>
> 0x000000000d8e11f0 in ?? ()<br>
> (gdb) bt<br>
> #0 0x000000000d8e11f0 in ?? ()<br>
> #1 0x0000000001a32625 in PMPI_Barrier ()<br>
> #2 0x0000000000bdd2b7 in PetscLogBegin_Private () at /home/lchen/ft-petsc/src/sys/logging/plog.c:234<br>
> #3 0x0000000000bdd876 in PetscLogBegin () at /home/lchen/ft-petsc/src/sys/logging/plog.c:278<br>
> #4 0x00000000004c1f6c in PetscOptionsCheckInitial_Private ()<br>
> at /home/lchen/ft-petsc/src/sys/objects/init.c:494<br>
> #5 0x00000000004cbe6d in PetscInitialize (argc=0x0, args=0x0, file=0x0,<br>
> help=0x20a9f00 "Replace with PETSC_solve") at /home/lchen/ft-petsc/src/sys/objects/pinit.c:779<br>
> #6 0x00000000004991e3 in petscsolve_ (N=0x20c7d28, RHS=0x9813500, WKAREA=0x4902c80, NZ=0xc0629e0,<br>
> IA=0xb8b9ac0, JA=0x754e520, CO=0x9871ac0, TOL=0x22c0528, ITMAX=0x71ef048, ITER=0x7fffffffd3a8,<br>
> ERR=0x7fffffffd3b0, IERR=0x7fffffffd3b8, IUNIT=0x1bcb310, RWORK=0x57d2000, LENW=0x49f4cc0,<br>
> IWORK=0x3e32860, LENIW=0x49f4cc8) at petscsolve.c:184<br>
> #7 0x000000000044ed15 in lineq () at t2cg22.f:1698<br>
> #8 0x000000000046a24c in cycit () at t2f.f:2055<br>
> #9 0x00000000004483d3 in tough2 () at t2cg22.f:625<br>
> #10 0x000000000040bfcc in main ()<br>
><br>
> Are there any problems with PetscInitialize(NULL, NULL, NULL, help)?<br>
> Thank you.<br>
><br>
> Best regards,<br>
> Longxiang Chen<br>
><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>