<div dir="ltr"><div class="gmail_extra"><br>
<br><br><div class="gmail_quote">On Tue, May 20, 2014 at 3:17 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="">Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> writes:<br>
>> array = (PetscScalar**)malloc(sizeof(PetscScalar*) * dof);<br>
>> for (k = 0; k < dof; k++){<br>
>> array[k] = (PetscScalar*)malloc(sizeof(PetscScalar) * dof);<br>
>> }<br>
>><br>
>> When I pass it to MatSetValuesBlocked() there is a problem. Either Petsc<br>
>> complains because I am not passing it the right way or when it accepts it,<br>
>> wrong data is passed because the solution is not correct. Maybe Petsc<br>
>> expect dof*dof values and only dof are passed ?<br>
>><br>
><br>
> You can only pass contiguous memory to MatSetValues().<br>
<br>
</div>And, while perhaps atypical, VecGetArray2D will give you contiguous<br>
memory behind the scenes, so it would work in this case. (Make a Vec of<br>
the right size using COMM_SELF instead of malloc.)<br>
<br>
With C99, you can use VLA pointers to get the "2D indexing" without<br>
setting up explicit pointers.<br></blockquote><div><br></div><div><br></div><div>Would the following be ok ? <br></div><div><br></div><div>//Creation of vector X of size dof*dof:</div><div>VecCreateSeq(PETSC_COMM_SELF,dof*dof,&X);</div>
<div><br></div><div>// Using two-dimensional array style:</div><div>PetscScalar *x;</div><div>VecGetArray2d(X,dof,dof,0,0,&x);</div><div><br></div><div>x[i][j] = ...;</div><div><br></div><div>Is it ok ?</div><div>Then, what should be passed to MatSetValuesBlocked() ?<br>
</div></div><br></div></div>