[petsc-users] No warning or error message of segmentation violation

Barry Smith bsmith at mcs.anl.gov
Fri Nov 5 16:28:06 CDT 2010


  C has no way of detecting out of array access. If you are lucky the code crashes but if you are unlucky it is just accessing some other memory location (and thus doing garbage computation).

  Valgrind is very good at detecting bad memory access and should be used often even if the code "seems" to run correctly. We test all our codes with valgrind regularly.  http://www.mcs.anl.gov/petsc/petsc-as/documentation/faq.html#valgrind

   Barry

On Nov 5, 2010, at 4:22 PM, Li, Zhisong (lizs) wrote:

>  Hi, Petsc Team,
> 
> I use DA object to create structured data array based on global vectors. Recently, I checked my code and found an array with index out of range. But the code can run without any warning or segmentation violation message. At first I thought this might be a cache problem. But later I ran a simpler test code on another machine and it gave no error either. I did not use any periodic boundary setting.
> 
> This never took place in the past from my experience, as Petsc could always detect any segmentation violation. So what's wrong with it this time? The following is the main part of my sequential test code:
> 
>   DACreate3d(PETSC_COMM_WORLD,DA_NONPERIODIC,DA_STENCIL_BOX,m,n,q,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,1,1,PETSC_NULL,PETSC_NULL,PETSC_NULL,&da);  
>   DACreateGlobalVector(da, &elev); 
>   VecSet(elev, 3.14159265);  
>   DAVecGetArray(da, elev, &ele);
>   PetscPrintf(PETSC_COMM_WORLD, "ele[3][3][%D] is %4.3e\n", m+120, ele[3][3][m+120]); 
>   DAVecRestoreArray(da, elev, &ele);
>   VecDestroy(elev);     
>   DADestroy(daw);
> 
> 
> Thank you very much.
> 
> 
> Zhisong Li



More information about the petsc-users mailing list