<div dir="ltr"><div><div><div>Here is an example:<br><br></div>I only have a function written in C(and it is called in fortran, I cannot change fortran code):<br></div><div>PetscInitialize() is called in C function.<br></div>
<div><br></div>void P_solve(A, b, x, size)<br>{<br></div> // definition and declaration<br><div> <br></div><div> PetscInitialize();<br></div><div> <br></div><div> // petsc KSP functions<br></div><div><br>}<br><br></div>
<div>I use PetscOptionsSetValue() to set the options. But need to compile it every time I change options, I would fix it in the end.<br></div><div>Could I get the command line options in this situation? Like petscrc in fortran for this C function?<br>
</div><div><br></div><div>Thanks,<br></div><div class="gmail_extra"><br clear="all"><div><div dir="ltr">Best regards,<div>Longxiang Chen</div><div><br></div><div>Do something every day that gets you closer to being done.</div>
<div>--------------------------------------------------------------</div><div>465 Winston Chung Hall</div><div>Computer Science Engineering</div><div>University of California, Riverside</div><div><br></div></div></div>
<br><br><div class="gmail_quote">On Tue, May 21, 2013 at 7:48 AM, Satish Balay <span dir="ltr"><<a href="mailto:balay@mcs.anl.gov" target="_blank">balay@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">
If PetscInitialize() is called from fortran - command line should work.<br>
<br>
An easy alternative is to have a file 'petscrc' in the executable run<br>
dir - with the command line options listed [one option per line]<br>
<span class="HOEnZb"><font color="#888888"><br>
Satish<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Tue, 21 May 2013, Matthew Knepley wrote:<br>
<br>
> On Mon, May 20, 2013 at 11:01 PM, Longxiang Chen <<a href="mailto:suifengls@gmail.com">suifengls@gmail.com</a>>wrote:<br>
><br>
> > The fortran program is too long (several files with more than 10,000<br>
> > lines).<br>
> > And I just want to insert the P_solve inside one of the subroutine to<br>
> > solve Ax=b.<br>
> > Or it can only use argc and argv?<br>
> ><br>
><br>
> Barry is correct that you can use PetscOptionsSetValue(), however I think<br>
> you are<br>
> still missing the point.<br>
><br>
> Command line options are processed in PetscInitialize(). You do not have to<br>
> do anything<br>
> else. You do not have to change your huge Fortran code. You just use the<br>
> command line.<br>
> It is much better than hard coding a solver type since you can use ALL<br>
> solver types. There<br>
> is no reason not to use it.<br>
><br>
> Thanks,<br>
><br>
> Matt<br>
><br>
><br>
> > Thanks.<br>
> > Longxiang<br>
> ><br>
> > Best regards,<br>
> > Longxiang Chen<br>
> ><br>
> > Do something every day that gets you closer to being done.<br>
> > --------------------------------------------------------------<br>
> > 465 Winston Chung Hall<br>
> > Computer Science Engineering<br>
> > University of California, Riverside<br>
> ><br>
> ><br>
> ><br>
> > On Mon, May 20, 2013 at 8:52 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
> ><br>
> >><br>
> >> On May 20, 2013, at 10:38 PM, Longxiang Chen <<a href="mailto:suifengls@gmail.com">suifengls@gmail.com</a>> wrote:<br>
> >><br>
> >> > To whom it may concern,<br>
> >> ><br>
> >> > I am using KSP to solve Ax=b.<br>
> >> > The main() is in Fortran, and it calls a function I write in C.The<br>
> >> parameter is array A, x, b.<br>
> >> ><br>
> >> > void P_solve(double x[ ], double b[ ], double A[ ], int size);<br>
> >> ><br>
> >> > In the function, I should call PetscInitialize() before I create the<br>
> >> matrix and vectors for A, x, b, and also call MatSetFromOptions() and<br>
> >> VecSetFromOptions().<br>
> >> ><br>
> >> > But I don't have the argc and argv from main function.<br>
> >><br>
> >> If Fortran is the main program the options database still has access<br>
> >> to the command line arguments. You should still be able to use command line<br>
> >> arguments and not need to set them in the program.<br>
> >><br>
> >> Does this not work? Can you send a sample program where it does not<br>
> >> work?<br>
> >><br>
> >> Barry<br>
> >><br>
> >> ><br>
> >> > I just want to fix the KSP type to bcgs and the PC type.<br>
> >> > Is there another way that I can set the options not through argc and<br>
> >> argv, just set them in the program.<br>
> >> ><br>
> >> > e.g. options[] = {"-ksp_type", "bcgs"}.<br>
> >> ><br>
> >> > Thanks,<br>
> >> > Longxiang<br>
> >><br>
> >><br>
> ><br>
><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>