[petsc-dev] DMDA_BOUNDARY_GHOSTED

Barry Smith bsmith at mcs.anl.gov
Thu Sep 26 13:44:23 CDT 2013


  Multidimensional arrays are simply more flexible and powerful in C than in Fortran

On Sep 26, 2013, at 1:42 PM, "Mark F. Adams" <mfadams at lbl.gov> wrote:

>> 
>>  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