[petsc-users] PetscOptionsGetRealArray command line format
Satish Balay
balay at mcs.anl.gov
Fri Feb 14 16:46:14 CST 2014
http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscOptionsGetRealArray.html
Input Parameters
nmax - maximum number of values to retrieve
Output Parameters
nmax - actual number of values retreived
So you need to do:
double myarray[10];
int nmax = 10;
I'm not sure if there is a way to detect this incorrect usage [without valgrind] ...
Satish
On Fri, 14 Feb 2014, Xiangdong wrote:
> I have a simple script (see below) by just
> calling PetscOptionsGetRealArray. I run the program like this: mpirun -np
> 1 runarraytest -myarray 1,2,3,4,5. However, the output is always "the
> length of input myarray is 0".
>
> Can you produce the correct result? Thank you.
>
>
> Below is the script I use:
>
>
> #include <petsc.h>
>
> int main(int argc, char **argv)
> {
> PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL);
>
> double myarray[10];
> int nmax;
> PetscBool flg;
>
> PetscOptionsGetRealArray(NULL,"-myarray",myarray,&nmax,&flg);
>
> printf("the length of input myarray is %d \n",nmax);
>
> int i;
> for(i=0;i<nmax;++i)
> {
> printf(" %g\n",myarray[i]);
> }
>
> PetscFinalize();
> return 0;
> }
>
>
>
> On Fri, Feb 14, 2014 at 3:47 PM, Jed Brown <jed at jedbrown.org> wrote:
>
> > Xiangdong <epscodes at gmail.com> writes:
> > > Now I see some random behavior. After compiling the code, for the same
> > > command line input, the output sometimes are correct (print values
> > > 1,2,3,4,5 with nmax=5), but sometime output all zeros (nmax is zero). I
> > did
> > > not change anything, but just running same input many times.
> > >
> > > Any hints for this random behavior? Thank you.
> >
> > Run with valgrind. It is probably some other memory corruption
> > interfering.
> >
>
More information about the petsc-users
mailing list