[petsc-users] PetscOptionsGetRealArray command line format
Jed Brown
jed at jedbrown.org
Fri Feb 14 17:01:45 CST 2014
Xiangdong <epscodes at gmail.com> writes:
> 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.
$ valgrind ./a -myarray 1,2,3
==8778== Memcheck, a memory error detector
==8778== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==8778== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==8778== Command: ./a -myarray 1,2,3
==8778==
==8778== Conditional jump or move depends on uninitialised value(s)
==8778== at 0x4EBBB6F: PetscOptionsGetRealArray (options.c:1863)
==8778== by 0x400861: main (a.c:11)
==8778==
the length of input myarray is 0
[...]
Hmm,
options.c:1863 while (n < *nmax) {
Yup, you definitely have to initialize nmax before calling the function.
> 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;
>
Add nmax = 10;
> 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;
> }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140214/fb291bf3/attachment.pgp>
More information about the petsc-users
mailing list