<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 20, 2014 at 4:25 PM, Jed Brown <span dir="ltr"><<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">Christophe Ortiz <<a href="mailto:christophe.ortiz@ciemat.es">christophe.ortiz@ciemat.es</a>> writes:<br>
> Would the following be ok ?<br>
><br>
> //Creation of vector X of size dof*dof:<br>
> VecCreateSeq(PETSC_COMM_SELF,dof*dof,&X);<br>
><br>
> // Using two-dimensional array style:<br>
> PetscScalar *x;<br>
<br>
</div>This needs to be<br>
<br>
PetscScalar **x;<br>
<br>
as you would have noticed if you tried to compile.<br>
<div class=""><br>
> VecGetArray2d(X,dof,dof,0,0,&x);<br>
><br>
> x[i][j] = ...;<br>
<br>
</div>Yes.<br>
<div class=""><br>
> Is it ok ?<br>
> Then, what should be passed to MatSetValuesBlocked() ?<br>
<br>
</div>Since the array starts are (0,0), you can just pass &x[0][0].<br>
<br>
Remember to call VecRestoreArray2d() and eventually VecDestroy().<br></blockquote><div><br></div><div>I tried and it works. The advantage is that it avoids setting up and using pointers.</div><div>However, I found out that it is significantly slower than using explicit pointers of pointers **.</div>
<div> </div></div><br></div></div>