<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi,</p>
    <p>I will test what Barry suggested, but I have done 2 tests after
      Stefano's remarks (and also upgraded to petsc 3.14.1 -- which
      changed nothing):</p>
    <p>=================================<br>
    </p>
    <p>test #1- Extract the local matrix with MatISGetLocalMat, call
      MatXAIJSetPreallocation with the local non-zeros I sent you in my
      first email: it worked!</p>
    <p>=================================</p>
    <p>*but*:</p>
    <p>=================================</p>
    <p>test #2- Pass the "same" non-zeros vectors as if I had a "normal"
      mpi matrix:</p>
    <p>This gives me a very different error:</p>
    <p>[0]PETSC ERROR: --------------------- Error Message
      --------------------------------------------------------------<br>
      [0]PETSC ERROR: No support for this operation for this object type<br>
      [0]PETSC ERROR: Some of the column indices can not be mapped!
      Maybe you should not use MATIS<br>
      [0]PETSC ERROR: See
      <a class="moz-txt-link-freetext" href="https://www.mcs.anl.gov/petsc/documentation/faq.html">https://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble
      shooting.<br>
      [0]PETSC ERROR: Petsc Release Version 3.14.1, Nov 03, 2020 <br>
      [0]PETSC ERROR: Test.MEF++.dev on a  named rohan by ericc Wed Nov
      11 21:35:55 2020<br>
      [0]PETSC ERROR: Configure options
      --prefix=/opt/petsc-3.14.1_debug_openmpi-4.0.5
      --with-mpi-compilers=1 --with-mpi-dir=/opt/openmpi-4.0.5
      --with-cxx-dialect=C++11 --with-make-np=12
      --with-shared-libraries=1 --with-debugging=yes --with-memalign=64
      --with-visibility=0 --with-64-bit-indices=0 --download-ml=yes
      --download-mumps=yes --download-superlu=yes
      --download-superlu_dist=yes --download-parmetis=yes
      --download-ptscotch=yes --download-metis=yes
      --download-suitesparse=yes --download-hypre=yes
      --with-blaslapack-dir=/opt/intel/composer_xe_2015.2.164/mkl/lib/intel64
      --with-mkl_pardiso-dir=/opt/intel/composer_xe_2015.2.164/mkl
      --with-mkl_cpardiso-dir=/opt/intel/composer_xe_2015.2.164/mkl
      --with-scalapack=1
      --with-scalapack-include=/opt/intel/composer_xe_2015.2.164/mkl/include
--with-scalapack-lib="-L/opt/intel/composer_xe_2015.2.164/mkl/lib/intel64
      -lmkl_scalapack_lp64 -lmkl_blacs_openmpi_lp64"<br>
      [0]PETSC ERROR: #1 MatSetValuesBlocked_IS() line 2555 in
      /home/mefpp_ericc/ompi-opt/petsc-3.14.1-debug/src/mat/impls/is/matis.c<br>
      [0]PETSC ERROR: #2 MatSetValuesBlocked() line 1848 in
      /home/mefpp_ericc/ompi-opt/petsc-3.14.1-debug/src/mat/interface/matrix.c</p>
    <p>==================================<br>
    </p>
    <p>So I still mystified on how to call MatXAIJSetPreallocation for
      MATIS type.  Here are more precises questions/remarks:</p>
    <p>a) What is the correct length for the dnnz vector for a MATIS
      when calling MatXAIJSetPreallocation?  I put it to the size of Mat
      from MatISGetLocalMat.</p>
    <p>b) Since all non-zeros are supposed to be "local", what do you
      put in onnz for MatXAIJSetPreallocation?  In my case, I put
      nothing: all entries are 0 and as for dnnz, the length is the one
      from the local Mat...<br>
    </p>
    <p>Since my test #1 is now all working right, I can go on with my
      modifications, but for the convenience of other users, maybe some
      further tests should be done?</p>
    <p>I will tests Barry's suggestions asap,</p>
    <p>Thanks a lot!</p>
    <p>Eric<br>
    </p>
    <div class="moz-cite-prefix">On 2020-11-11 6:47 a.m., Stefano
      Zampini wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAGPUisinaZRtUqCdRDKwmkV2Ee6iHvw5_6xHSFztpG_Nf1BmjQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">Eric
        <div><br>
        </div>
        <div>just use the same arrays you provide for the other matrix
          types. The purpose of having support for MATIS in
          MatXAIJSetPreallocation is exactly to not preallocate the
          local matrices, but treat the matrix as if it was in
          "assembled" (AIJ) form. The MATIS code does the local
          preallocation for you (a little bit overestimated), see here <a
href="https://gitlab.com/petsc/petsc/-/blob/master/src/mat/impls/is/matis.c#L1686"
            moz-do-not-send="true">https://gitlab.com/petsc/petsc/-/blob/master/src/mat/impls/is/matis.c#L1686</a></div>
        <div>You need to provide the local2global map object before
          calling the preallocation routine</div>
        <div><br>
        </div>
        <div>Let me know if something is still unclear</div>
        <div><br>
        </div>
        <div>Stefano</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">Il giorno mer 11 nov 2020 alle
          ore 12:06 Barry Smith <<a href="mailto:bsmith@petsc.dev"
            moz-do-not-send="true">bsmith@petsc.dev</a>> ha scritto:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
          <br>
          > On Nov 10, 2020, at 11:10 PM, Eric Chamberland <<a
            href="mailto:Eric.Chamberland@giref.ulaval.ca"
            target="_blank" moz-do-not-send="true">Eric.Chamberland@giref.ulaval.ca</a>>
          wrote:<br>
          > <br>
          > Hi,<br>
          > <br>
          > I am trying to add support for MATIS in our code to be
          able to use PCBDDC and others.<br>
          > <br>
          > So far, I have modify our matrix creation to add a call
          to MatSetLocalToGlobalMapping and also modified our non-zeros
          count to be able to give "local" non-zeros to
          MatXAIJSetPreallocation.<br>
          > <br>
          > When I run with, don't laugh, 1 process, everything is
          fine! So far so good. ;)<br>
          > <br>
          > When I run with 2 processes, fine also...<br>
          > <br>
          > When I run with 3 processes, I have process rank 1 and 2
          giving errors:<br>
          > <br>
          > [1]PETSC ERROR: New nonzero at (7,5) caused a malloc<br>
          > <br>
          > and<br>
          > <br>
          > [2]PETSC ERROR: New nonzero at (10,2) caused a malloc<br>
          > <br>
          > I understand that these new nonzero indices are *local*
          indices. The global indices I am trying to do assembly on are:<br>
          > <br>
          > proc 1:<br>
          > <br>
          > global Line 3 (local 7)<br>
          > global Columns: 3 7 10 15 *16* 17 (local 7 9 10 4 *5* 6) 
          // *x* is faulty column, meaning only 4 nnz have been
          allocated!?<br>
          <br>
            Because the local column indices may not be set "in order"
          it doesn't mean for sure that it thinks there are only 4
          column slots available, it could<br>
          be it filled up column slots with local columns larger than 5
          and hence used up all the available space.<br>
          <br>
            Unfortunately we don't have any code in place to display
          what is happening when the error occurs. So I suggest the
          following. <br>
          <br>
            Stop putting in values just before the first problematic
          value. <br>
          <br>
            At that point in your code call MatAssemblyBegin/End() <br>
          <br>
            Then call MatView() <br>
          <br>
            This will show you what columns have been filled up in each
          local matrix and can help you determine if either <br>
          <br>
            1) some other column entries are getting in there that you
          didn't expect.  or<br>
          <br>
            2) somehow the preallocation is not properly being
          determined and is smaller than you expect. <br>
          <br>
          Good luck,<br>
          <br>
            Barry<br>
          <br>
          <br>
          > <br>
          > proc2 :<br>
          > <br>
          > (global Line 16 (local 10)<br>
          > (global Columns: 3 8 16 17 *20* 22 23 24 (local 8 11 10
          12 *2* 4 5 6) // *x* is faulty column, , meaning only 4 nnz
          have been allocated!?<br>
          > <br>
          > The error is returned at the moment we do the first
          assembly.<br>
          > <br>
          > After verifying my number of nnz, I just can't find why
          PETSc complains about a malloc, since as I can verify, I
          counted them well...<br>
          > <br>
          > Global matrix "size": 25 x 25 (given to MatSetSizes)<br>
          > <br>
          > Here are the non-zeros given to MatXAIJSetPreallocation
          followed by mapping used when creating ISLocalToGlobalMapping:<br>
          > <br>
          > =============<br>
          > <br>
          > Process 0:<br>
          > <br>
          > nnz_d[Local:0]=4<br>
          > nnz_d[Local:1]=6<br>
          > nnz_d[Local:2]=4<br>
          > nnz_d[Local:3]=4<br>
          > nnz_d[Local:4]=6<br>
          > nnz_d[Local:5]=4<br>
          > nnz_d[Local:6]=6<br>
          > nnz_d[Local:7]=8<br>
          > nnz_d[Local:8]=6<br>
          > nnz_d[Local:9]=9<br>
          > nnz_d[Local:10]=4<br>
          > <br>
          > Local,Global:<br>
          > <br>
          > 0,0<br>
          > 1,1<br>
          > 2,2<br>
          > 3,3<br>
          > 4,4<br>
          > 5,5<br>
          > 6,6<br>
          > 7,7<br>
          > 8,8<br>
          > 9,9<br>
          > 10,10<br>
          > <br>
          > =============<br>
          > <br>
          > Process 1:<br>
          > <br>
          > <br>
          > nnz_d[Local:0]=4<br>
          > nnz_d[Local:1]=6<br>
          > nnz_d[Local:2]=6<br>
          > nnz_d[Local:3]=4<br>
          > nnz_d[Local:4]=9<br>
          > nnz_d[Local:5]=4<br>
          > nnz_d[Local:6]=6<br>
          > nnz_d[Local:7]=6<br>
          > nnz_d[Local:8]=4<br>
          > nnz_d[Local:9]=4<br>
          > nnz_d[Local:10]=8<br>
          > <br>
          > Local,Global:<br>
          > <br>
          > 0,11<br>
          > 1,12<br>
          > 2,13<br>
          > 3,14<br>
          > 4,15<br>
          > 5,16<br>
          > 6,17<br>
          > 7,3<br>
          > 8,5<br>
          > 9,7<br>
          > 10,10<br>
          > <br>
          > =============<br>
          > <br>
          > Process 2:<br>
          > <br>
          > nnz_d[Local:0]=4<br>
          > nnz_d[Local:1]=4<br>
          > nnz_d[Local:2]=6<br>
          > nnz_d[Local:3]=6<br>
          > nnz_d[Local:4]=6<br>
          > nnz_d[Local:5]=6<br>
          > nnz_d[Local:6]=9<br>
          > nnz_d[Local:7]=4<br>
          > nnz_d[Local:8]=4<br>
          > nnz_d[Local:9]=4<br>
          > nnz_d[Local:10]=8<br>
          > nnz_d[Local:11]=6<br>
          > nnz_d[Local:12]=6<br>
          > <br>
          >  Local,Global:<br>
          > 0,18<br>
          > 1,19<br>
          > 2,20<br>
          > 3,21<br>
          > 4,22<br>
          > 5,23<br>
          > 6,24<br>
          > 7,2<br>
          > 8,3<br>
          > 9,14<br>
          > 10,16<br>
          > 11,8<br>
          > 12,17<br>
          > <br>
          > =============<br>
          > <br>
          > I have ran with valgrind, everything is ok.<br>
          > <br>
          > So, why don't I have enough values reserved on local line
          7 of rank 1? and 10 of rank 2?<br>
          > <br>
          > Thanks for your insights,<br>
          > <br>
          > Eric<br>
          > <br>
          > ps: Here is the backtrace:<br>
          > <br>
          > [1]PETSC ERROR: --------------------- Error Message
          --------------------------------------------------------------<br>
          > [1]PETSC ERROR: Argument out of range<br>
          > [1]PETSC ERROR: New nonzero at (7,5) caused a malloc<br>
          > Use MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR,
          PETSC_FALSE) to turn off this check<br>
          > [1]PETSC ERROR: See <a
            href="http://www.mcs.anl.gov/petsc/documentation/faq.html"
            rel="noreferrer" target="_blank" moz-do-not-send="true">http://www.mcs.anl.gov/petsc/documentation/faq.html</a>
          for trouble shooting.<br>
          > [1]PETSC ERROR: Petsc Release Version 3.11.2, May, 18,
          2019<br>
          > [1]PETSC ERROR: Test.MEF++.dev on a  named rohan by ericc
          Tue Nov 10 23:39:47 2020<br>
          > [1]PETSC ERROR: Configure options
          --prefix=/opt/petsc-3.11.2_debug_openmpi-4.0.1
          --with-mpi-compilers=1 --with-mpi-dir=/opt/openmpi-4.0.1
          --with-cxx-dialect=C++11 --with-make-np=12
          --with-shared-libraries=1 --with-debugging=yes
          --with-memalign=64 --with-visibility=0 --with-64-bit-indices=0
          --download-ml=yes --download-mumps=yes --download-superlu=yes
          --download-superlu_dist=yes --download-parmetis=yes
          --download-ptscotch=yes --download-metis=yes
          --download-suitesparse=yes --download-hypre=yes
          --with-blaslapack-dir=/opt/intel/composer_xe_2015.2.164/mkl/lib/intel64
          --with-mkl_pardiso-dir=/opt/intel/composer_xe_2015.2.164/mkl
          --with-mkl_cpardiso-dir=/opt/intel/composer_xe_2015.2.164/mkl
          --with-scalapack=1
          --with-scalapack-include=/opt/intel/composer_xe_2015.2.164/mkl/include
--with-scalapack-lib="-L/opt/intel/composer_xe_2015.2.164/mkl/lib/intel64
          -lmkl_scalapack_lp64 -lmkl_blacs_openmpi_lp64"<br>
          > [1]PETSC ERROR: #1 MatSetValues_SeqAIJ() line 481 in
/home/mefpp_ericc/depots_prepush/cpetssc/ompi-opt/petsc-3.11.2-debug/src/mat/impls/aij/seq/aij.c<br>
          > [1]PETSC ERROR: #2 MatSetValues() line 1407 in
/home/mefpp_ericc/depots_prepush/cpetssc/ompi-opt/petsc-3.11.2-debug/src/mat/interface/matrix.c<br>
          > [1]PETSC ERROR: #3 MatSetValuesBlocked() line 1919 in
/home/mefpp_ericc/depots_prepush/cpetssc/ompi-opt/petsc-3.11.2-debug/src/mat/interface/matrix.c<br>
          > [1]PETSC ERROR: #4 MatSetValuesBlocked_IS() line 2609 in
/home/mefpp_ericc/depots_prepush/cpetssc/ompi-opt/petsc-3.11.2-debug/src/mat/impls/is/matis.c<br>
          > [1]PETSC ERROR: #5 MatSetValuesBlocked() line 1898 in
/home/mefpp_ericc/depots_prepush/cpetssc/ompi-opt/petsc-3.11.2-debug/src/mat/interface/matrix.c<br>
          > _GIREF_ASSERTION(false)<br>
          > voir fichier
/home/mefpp_ericc/depots_prepush/GIREF/src/commun/Petsc/MatricePETSc.cc:858<br>
          >    ---->  ERREUR FATALE: Erreur PETSc<br>
          > <br>
          > <br>
          > -- <br>
          > Eric Chamberland, ing., M. Ing<br>
          > Professionnel de recherche<br>
          > GIREF/Université Laval<br>
          > (418) 656-2131 poste 41 22 42<br>
          > <br>
          <br>
        </blockquote>
      </div>
      <br clear="all">
      <div><br>
      </div>
      -- <br>
      <div dir="ltr" class="gmail_signature">Stefano</div>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Eric Chamberland, ing., M. Ing
Professionnel de recherche
GIREF/Université Laval
(418) 656-2131 poste 41 22 42</pre>
  </body>
</html>