[petsc-users] Set the options NOT from argc and argv

Longxiang Chen suifengls at gmail.com
Tue May 21 15:33:13 CDT 2013


Here is an example:

I only have a function written in C(and it is called in fortran, I cannot
change fortran code):
PetscInitialize() is called in C function.

void P_solve(A, b, x, size)
{
   // definition and declaration

  PetscInitialize();

  // petsc KSP functions

}

I use PetscOptionsSetValue() to set the options. But need to compile it
every time I change options, I would fix it in the end.
Could I get the command line options in this situation? Like petscrc in
fortran for this C function?

Thanks,

Best regards,
Longxiang Chen

Do something every day that gets you closer to being done.
--------------------------------------------------------------
465 Winston Chung Hall
Computer Science Engineering
University of California, Riverside



On Tue, May 21, 2013 at 7:48 AM, Satish Balay <balay at mcs.anl.gov> wrote:

> If PetscInitialize() is called from fortran - command line should work.
>
> An easy alternative is to have a file 'petscrc' in the executable run
> dir - with the command line options listed [one option per line]
>
> Satish
>
> On Tue, 21 May 2013, Matthew Knepley wrote:
>
> > On Mon, May 20, 2013 at 11:01 PM, Longxiang Chen <suifengls at gmail.com
> >wrote:
> >
> > > The fortran program is too long (several files with more than 10,000
> > > lines).
> > > And I just want to insert the P_solve inside one of the subroutine to
> > > solve Ax=b.
> > > Or it can only use argc and argv?
> > >
> >
> > Barry is correct that you can use PetscOptionsSetValue(), however I think
> > you are
> > still missing the point.
> >
> > Command line options are processed in PetscInitialize(). You do not have
> to
> > do anything
> > else. You do not have to change your huge Fortran code. You just use the
> > command line.
> > It is much better than hard coding a solver type since you can use ALL
> > solver types. There
> > is no reason not to use it.
> >
> >   Thanks,
> >
> >      Matt
> >
> >
> > > Thanks.
> > > Longxiang
> > >
> > > Best regards,
> > > Longxiang Chen
> > >
> > > Do something every day that gets you closer to being done.
> > > --------------------------------------------------------------
> > > 465 Winston Chung Hall
> > > Computer Science Engineering
> > > University of California, Riverside
> > >
> > >
> > >
> > > On Mon, May 20, 2013 at 8:52 PM, Barry Smith <bsmith at mcs.anl.gov>
> wrote:
> > >
> > >>
> > >> On May 20, 2013, at 10:38 PM, Longxiang Chen <suifengls at gmail.com>
> wrote:
> > >>
> > >> > To whom it may concern,
> > >> >
> > >> > I am using KSP to solve Ax=b.
> > >> > The main() is in Fortran, and it calls a function I write in C.The
> > >> parameter is array A, x, b.
> > >> >
> > >> > void P_solve(double x[ ], double b[ ], double A[ ], int size);
> > >> >
> > >> > In the function, I should call PetscInitialize() before I create the
> > >> matrix and vectors for A, x, b, and also call MatSetFromOptions() and
> > >> VecSetFromOptions().
> > >> >
> > >> > But I don't have the argc and argv from main function.
> > >>
> > >>     If Fortran is the main program the options database still has
> access
> > >> to the command line arguments. You should still be able to use
> command line
> > >> arguments and not need to set them in the program.
> > >>
> > >>      Does this not work? Can you send a sample program where it does
> not
> > >> work?
> > >>
> > >>    Barry
> > >>
> > >> >
> > >> > I just want to fix the KSP type to bcgs and the PC type.
> > >> > Is there another way that I can set the options not through argc and
> > >> argv, just set them in the program.
> > >> >
> > >> > e.g. options[] = {"-ksp_type", "bcgs"}.
> > >> >
> > >> > Thanks,
> > >> > Longxiang
> > >>
> > >>
> > >
> >
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130521/e21a2607/attachment.html>


More information about the petsc-users mailing list