On Tue, May 20, 2014 at 4:25 PM, Jed Brown <[email protected]> wrote:
> Christophe Ortiz <[email protected]> writes: > > Would the following be ok ? > > > > //Creation of vector X of size dof*dof: > > VecCreateSeq(PETSC_COMM_SELF,dof*dof,&X); > > > > // Using two-dimensional array style: > > PetscScalar *x; > > This needs to be > > PetscScalar **x; > > as you would have noticed if you tried to compile. > > > VecGetArray2d(X,dof,dof,0,0,&x); > > > > x[i][j] = ...; > > Yes. > > > Is it ok ? > > Then, what should be passed to MatSetValuesBlocked() ? > > Since the array starts are (0,0), you can just pass &x[0][0]. > > Remember to call VecRestoreArray2d() and eventually VecDestroy(). > I tried and it works. The advantage is that it avoids setting up and using pointers. However, I found out that it is significantly slower than using explicit pointers of pointers **.
