<div dir="ltr"><div><div><div><div>I insert the lines below into my code, but it does not work:<br>  PetscErrorCode         ierr;<br>  PetscInt               xs,ys,nx,ny,i,j,slot,gxs,gys,gnx,gny;<br>  PetscInt               m,n,dim,s,*cols = NULL,k,nc,*rows = NULL,col,cnt,l,p,*dnz = NULL,*onz = NULL;<br>  PetscInt               istart,iend,jstart,jend,kstart,kend,zs,nz,gzs,gnz,ii,jj,kk;<br>  MPI_Comm               comm;<br>  PetscScalar            *values;<br>  DMDABoundaryType       bx,by,bz;<br>  ISLocalToGlobalMapping ltog,ltogb;<br>  DMDAStencilType        st;<br><br>  PetscFunctionBegin;<br>    ierr = DMDAGetInfo(da,&dim,&m,&n,&p,0,0,0,&nc,&s,&bx,&by,&bz,&st);CHKERRQ(ierr);<br>  col  = 2*s + 1;<br><br>  ierr = DMDAGetCorners(da,&xs,&ys,&zs,&nx,&ny,&nz);CHKERRQ(ierr);<br>  ierr = DMDAGetGhostCorners(da,&gxs,&gys,&gzs,&gnx,&gny,&gnz);CHKERRQ(ierr);<br>  ierr = PetscObjectGetComm((PetscObject)da,&comm);CHKERRQ(ierr);<br><br>  ierr = PetscMalloc2(nc,PetscInt,&rows,col*col*col*nc*nc,PetscInt,&cols);CHKERRQ(ierr);<br>  ierr = DMGetLocalToGlobalMapping(da,&ltog);CHKERRQ(ierr);<br><br>  ierr = MatSetBlockSize(pMat,nc);CHKERRQ(ierr); /// error happens !<br>  /* determine the matrix preallocation information */<br>  ierr = MatPreallocateInitialize(comm,nc*nx*ny*nz,nc*nx*ny*nz,dnz,onz);CHKERRQ(ierr);<br>  for (i=xs; i<xs+nx; i++) {<br>    istart = (bx == DMDA_BOUNDARY_PERIODIC) ? -s : (PetscMax(-s,-i));<br>    iend   = (bx == DMDA_BOUNDARY_PERIODIC) ?  s : (PetscMin(s,m-i-1));<br>    for (j=ys; j<ys+ny; j++) {<br>      jstart = (by == DMDA_BOUNDARY_PERIODIC) ? -s : (PetscMax(-s,-j));<br>      jend   = (by == DMDA_BOUNDARY_PERIODIC) ?  s : (PetscMin(s,n-j-1));<br>      for (k=zs; k<zs+nz; k++) {<br>        kstart = (bz == DMDA_BOUNDARY_PERIODIC) ? -s : (PetscMax(-s,-k));<br>        kend   = (bz == DMDA_BOUNDARY_PERIODIC) ?  s : (PetscMin(s,p-k-1));<br><br>        slot = i - gxs + gnx*(j - gys) + gnx*gny*(k - gzs);<br><br>        cnt = 0;<br>        for (l=0; l<nc; l++) {<br>          for (ii=istart; ii<iend+1; ii++) {<br>            for (jj=jstart; jj<jend+1; jj++) {<br>              for (kk=kstart; kk<kend+1; kk++) {<br>                if ((st == DMDA_STENCIL_BOX) || ((!ii && !jj) || (!jj && !kk) || (!ii && !kk))) {/* entries on star*/<br>                  cols[cnt++] = l + nc*(slot + ii + gnx*jj + gnx*gny*kk);<br>                }<br>              }<br>            }<br>          }<br>          rows[l] = l + nc*(slot);<br>        }<br>        ierr = MatPreallocateSetLocal(ltog,nc,rows,ltog,cnt,cols,dnz,onz);CHKERRQ(ierr);<br>      }<br>    }<br>  }<br>  ierr = MatSetBlockSize(pMat,nc);CHKERRQ(ierr);<br>  ierr = MatSeqAIJSetPreallocation(pMat,0,dnz);CHKERRQ(ierr);<br>  ierr = MatMPIAIJSetPreallocation(pMat,0,dnz,0,onz);CHKERRQ(ierr);<br>  ierr = MatPreallocateFinalize(dnz,onz);CHKERRQ(ierr);<br>  ierr = MatSetLocalToGlobalMapping(pMat,ltog,ltog);CHKERRQ(ierr);<br>  ierr = PetscFree2(rows,cols);CHKERRQ(ierr);<br><br></div>An error reported when it runs into   ierr = MatSetBlockSize(pMat,nc);CHKERRQ(ierr); <br><br>"unknowndirectory/"src/mat_vec/sasMatVecPetsc.cpp:154: __FUNCT__="DMCreateMatrix_DA_3d_MPIAIJ_pvs" does not agree with __PRETTY_FUNCTION__="PetscErrorCode sasMatVecPetsc::DMCreateMatrix_DA_3d_MPIAIJ_pvs(DM, sasSmesh*, sasVector<int>&, sasVector<int>&, sasVector<int>&, sasVector<int>&)"<br>[0]PETSC ERROR: --------------------- Error Message ------------------------------------<br>[0]PETSC ERROR: Null argument, when expecting valid pointer!<br>[0]PETSC ERROR: Null Object: Parameter # 1!<br>[0]PETSC ERROR: ------------------------------------------------------------------------<br>[0]PETSC ERROR: Petsc Release Version 3.4.5, Jun, 29, 2014 <br>[0]PETSC ERROR: See docs/changes/index.html for recent updates.<br>[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>[0]PETSC ERROR: See docs/index.html for manual pages.<br>[0]PETSC ERROR: ------------------------------------------------------------------------<br>[0]PETSC ERROR: ./sasMAIN on a arch-cxx-linux-deb named sang by sang Thu Feb 11 14:54:12 2016<br>[0]PETSC ERROR: Libraries linked from /home/sang/petsc/petsc-3.4.5/arch-cxx-linux-deb/lib<br>[0]PETSC ERROR: Configure run at Thu Feb 11 11:44:35 2016<br>[0]PETSC ERROR: Configure options --download-mpich=1 --with-scalar-type=real --with-clanguage=cxx --download-mumps=1 --download-blacs=1 --download-parmetis=1 --download-scalapack=1 --with-debugging=1 --download-hypre=1 --with-fc=gfortran --download-metis=1 -download-cmake=1 --download-f-blas-lapack=1<br>[0]PETSC ERROR: ------------------------------------------------------------------------<br>[0]PETSC ERROR: MatSetBlockSize() line 6686 in /home/sang/petsc/petsc-3.4.5/src/mat/interface/matrix.c<br>[0]PETSC ERROR: PetscErrorCode sasMatVecPetsc::DMCreateMatrix_DA_3d_MPIAIJ_pvs(DM, sasSmesh*, sasVector<int>&, sasVector<int>&, sasVector<int>&, sasVector<int>&)() line 165 in "unknowndirectory/"src/mat_vec/sasMatVecPetsc.cpp<br><br></div>where is the mistake?<br><br></div>Many thanks.<br><br></div>Pham<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 11, 2016 at 1:18 PM, Dave May <span dir="ltr"><<a href="mailto:dave.mayhem23@gmail.com" target="_blank">dave.mayhem23@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"><div><div>I think he wants the source location so that he can copy and implementation and "tweak" it slightly<br><br></div>The location is here<br></div>${PETSC_DIR}/src/dm/impls/da/fdda.c<div><div><br>/Users/dmay/software/petsc-3.6.0/src<br>dmay@nikkan:~/software/petsc-3.6.0/src $ grep -r DMCreateMatrix_DA_3d_MPIAIJ *<br>dm/impls/da/fdda.c:extern PetscErrorCode DMCreateMatrix_DA_3d_MPIAIJ(DM,Mat);<br>dm/impls/da/fdda.c:extern PetscErrorCode DMCreateMatrix_DA_3d_MPIAIJ_Fill(DM,Mat);<br>dm/impls/da/fdda.c:        ierr = DMCreateMatrix_DA_3d_MPIAIJ_Fill(da,A);CHKERRQ(ierr);<br>dm/impls/da/fdda.c:        ierr = DMCreateMatrix_DA_3d_MPIAIJ(da,A);CHKERRQ(ierr);<br><b>dm/impls/da/fdda.c:#define __FUNCT__ "DMCreateMatrix_DA_3d_MPIAIJ"<br>dm/impls/da/fdda.c:PetscErrorCode DMCreateMatrix_DA_3d_MPIAIJ(DM da,Mat J)<br></b>dm/impls/da/fdda.c:#define __FUNCT__ "DMCreateMatrix_DA_3d_MPIAIJ_Fill"<br>dm/impls/da/fdda.c:PetscErrorCode DMCreateMatrix_DA_3d_MPIAIJ_Fill(DM da,Mat J)<br><br></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 11 February 2016 at 04:08, Matthew Knepley <span dir="ltr"><<a href="mailto:knepley@gmail.com" target="_blank">knepley@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"><div class="gmail_extra"><div class="gmail_quote"><span>On Wed, Feb 10, 2016 at 8:59 PM, 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"><p dir="ltr">The irregular rows is quite many. The matrix really needs to be preallocated. <br>
Could you show me how to use DMCreateMatrix_DA_3d_MPIAIJ() directly?</p>
<p dir="ltr"></p></blockquote></span><div>Just put the declaration right into your source.</div><div><br></div><div>   Matt <br></div><div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Pham</p>
<div class="gmail_quote">On Feb 11, 2016 9:52 AM, "Matthew Knepley" <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 10, 2016 at 8:44 PM, 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><p dir="ltr">That is because my matrix has some rows which need more entries than usual.<br></p></blockquote><div><br></div><div>If its only a few, you could just turn off the allocation error.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><p dir="ltr">
Where can i find source code of DMCreateMatrix()?</p>
<p dir="ltr"></p></blockquote><div><br></div><div><a href="https://bitbucket.org/petsc/petsc/src/827b69d6bb12709ff9b9a0dede31640477fc2b74/src/dm/impls/da/fdda.c?at=master&fileviewer=file-view-default#fdda.c-1024" target="_blank">https://bitbucket.org/petsc/petsc/src/827b69d6bb12709ff9b9a0dede31640477fc2b74/src/dm/impls/da/fdda.c?at=master&fileviewer=file-view-default#fdda.c-1024</a></div><div><br></div><div>  Matt <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><p dir="ltr">Pham.<br>
</p>
<div class="gmail_quote">On Feb 11, 2016 8:35 AM, "Matthew Knepley" <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 10, 2016 at 6:14 PM, 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><span style="font-size:12.8px">Hi,</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I am trying to create a DM matrix with <span style="font-size:12.8px">DMCreateMatrix_DA_3d_MPIAIJ() instead of using DMCreateMatrix().</span></div></div></blockquote><div><br></div><div>Why, that should be called automatically by DMCreateMatrix()?</div><div><br></div><div>  Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-size:12.8px"><span style="font-size:12.8px">Which header file should I include to use that routine? also, what is the source file containing the DMCreateMatrix() routine?</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">Many thanks in advance.</span></div><div style="font-size:12.8px"><div><img src="https://ssl.gstatic.com/ui/v1/icons/mail/images/cleardot.gif"></div><span><font color="#888888"><div>Pham</div></font></span></div></div>
</blockquote></div><br><br clear="all"><span><font color="#888888"><span><font color="#888888"><div><br></div>-- <br><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</font></span></font></span></div></div><span><font color="#888888">
</font></span></blockquote></div><span><font color="#888888">
</font></span></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</font></span></div></div>
</blockquote></div>
</blockquote></div></div></div><div><div><br><br clear="all"><div><br></div>-- <br><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</div></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>