<div dir="ltr"><div>If you need to access a user defined context from within your CreateMatrix function, you can attach it to the DM via PetscObjectCompose<br><br><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscObjectCompose.html">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscObjectCompose.html</a><br><br></div>If your context is not a petsc object, you can use PetscContainerCreate(), <br><br><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscContainerCreate.html#PetscContainerCreate">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscContainerCreate.html#PetscContainerCreate</a><br><br>You would then set your user context pointer inside the container and then use PetscObjectCompose() to attach the container to the DM<br><div><br></div><div>Thanks,<br></div><div> Dave<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 24 October 2015 at 06:04, Sang pham van <span dir="ltr"><<a href="mailto:pvsang002@gmail.com" target="_blank">pvsang002@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Barry,<div><br></div><div>The routine <span style="font-size:12.8px">DMCreateMatrix_DA_3d_MPIAIJ has 2 input arguments (DM da, Mat J), the function pointer in </span><span style="font-size:12.8px">DMDASetGetMatrix() only accept function with that two arguments</span><span style="font-size:12.8px">. </span></div><div><span style="font-size:12.8px">As you suggested, I am writing a routine (based on </span><span style="font-size:12.8px">DMCreateMatrix_DA_3d_MPIAIJ()) to preallocate the matrix in the way I wish, to do that I think It needs to have one more input argument: My_</span><span style="font-size:12.8px">DMCreateMatrix_DA_3d_MPIAIJ(DM da, Mat J, void* my_context)</span><span style="font-size:12.8px">. But </span><span style="font-size:12.8px">DMDASetGetMatrix() will not accept pointer of this function. Please give a suggestion to overcome this.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Thank you.</span></div><span class="HOEnZb"><font color="#888888"><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Pham</span></div><div><span style="font-size:12.8px"><br></span></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 4, 2015 at 1:24 AM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Look at DMCreateMatrix_DA_2d_MPIAIJ (or the 3d version if working in 3d) You need to copy this routine and add whatever additional preallocation information you need. Then call DMDASetGetMatrix() so that the DM will use your routine to create the matrix for you.<br>
<span><font color="#888888"><br>
Barry<br>
</font></span><div><div><br>
<br>
<br>
<br>
> On Sep 3, 2015, at 11:28 AM, Sang pham van <<a href="mailto:pvsang002@gmail.com" target="_blank">pvsang002@gmail.com</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> I am using DMCreateMatrix to create matrix from a existed DM object and defined stencil.<br>
> In my code, boundary nodes need to involve many inner nodes, thus matrix rows corresponding to boundary nodes are almost dense. How can I tell petsc that those rows need to be preallocated with more entries? I don't want to use MatMPIAIJSetPreallocation() since advantages of DM might be lost.<br>
><br>
> Many thanks.<br>
><br>
> Sam.<br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>