[petsc-users] help about my first petsc program

Jed Brown jed at 59A2.org
Mon Jun 21 17:00:42 CDT 2010


On Mon, 21 Jun 2010 17:30:10 -0400, "XUAN YU" <xxy113 at psu.edu> wrote:
> I want to learn petsc by solving a small time-dependent problem:
>    The problem is from chemical kinetics, and consists of the following three
> rate equations:         
>    dy1/dt = -.04*y1 + 1.e4*y2*y3
>    dy2/dt = .04*y1 - 1.e4*y2*y3 - 3.e7*(y2)^2
>    dy3/dt = 3.e7*(y2)^2
>   on the interval from t = 0.0 to t = 4.e10, with initial
>   conditions: y1 = 1.0, y2 = y3 = 0.
> 
> I passed the compiling, and generated an executable file. But I got a lot of -
> Error Message - when I run the file. I appreciate your help and suggestions!

First, always send the error message.  Second, if you get a seg-fault
(what's certainly happening here), you should run in a debugger ('./ex1
-start_in_debugger' or 'gdb --args ./ex1') or valgrind, either of which
will immediately show your error.

> int main(int argc,char **argv)
> {
>     TS ts;
>     Vec u,r;
>     PetscScalar    *u_localptr;
                     ^^^^^^^^^^^

This is just a pointer, it's value is undefined.

>     Mat J;
>     AppCtx user;
>     PetscInt its,m;
>     PetscReal dt,ftime;
>     PetscErrorCode ierr;
>     PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
>     m=3;
>     dt=0.1;
>   ierr = PetscOptionsGetInt(PETSC_NULL,"-m",&m,PETSC_NULL);CHKERRQ(ierr);
>   user.m=m;
>   u_localptr[0]=1.0;

It is still undefined here, so you try to write to an invalid memory
location.

Jed


More information about the petsc-users mailing list