[petsc-dev] DMDA_BOUNDARY_GHOSTED

Mark F. Adams mfadams at lbl.gov
Thu Sep 26 13:42:53 CDT 2013


> 
>   Here is the magic
> PetscErrorCode  VecGetArray2d(Vec x,PetscInt m,PetscInt n,PetscInt mstart,PetscInt nstart,PetscScalar **a[])
> 
>  ierr = VecGetLocalSize(x,&N);CHKERRQ(ierr);
>  if (m*n != N) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Local array size %D does not match 2d array dimensions %D by %D",N,m,n);
>  ierr = VecGetArray(x,&aa);CHKERRQ(ierr);
> 
>  ierr = PetscMalloc(m*sizeof(PetscScalar*),a);CHKERRQ(ierr);
>  for (i=0; i<m; i++) (*a)[i] = aa + i*n - nstart;
>  *a -= mstart;
>  PetscFunctionReturn(0);

Ah, so you make a bunch of silly_1 pointers so you can index into them in a silly_2 way and silly_2 = silly_1^-1.  That's easy :)


More information about the petsc-dev mailing list