<div dir="ltr">Ah, OK, never say never.<div><br></div><div>MatCreateSubMatrices seems to support creating a new matrix with the communicator of the IS.</div><div>It just needs to read from the input matrix and does not use it for communication, so it can do that.</div><div><br></div><div>As far as rectangular matrices, there is no reason not to support that (the row IS and column IS can be distinct).</div><div>Can you send the whole error message?</div><div>There may not be a test that does this, but src/mat/tests/ex23.c looks like it may be a rectangular matrix output.</div><div><br></div><div>And, it should not matter if the input matrix has a 100% full sparse matrix. It is still MatAIJ.</div><div>The semantics and API is the same for sparse or dense matrices.</div><div><br></div><div>Thanks,</div><div>Mark</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, Aug 25, 2025 at 7:31 AM Alexis SALZMAN <<a href="mailto:alexis.salzman@ec-nantes.fr">alexis.salzman@ec-nantes.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>

  
    
  
  <div>
    Hi,<br>
    <br>
    Thanks for your answer, Mark. Perhaps MatCreateSubMatricesMPI is the
    only PETSc function that acts on a sub-communicator — I'm not sure —
    but it's clear that there's no ambiguity on that point. The first
    line of the documentation for that function states that it 'may live
    on subcomms'. This is confirmed by the 'src/mat/tests/ex183.c' test
    case. I used this test case to understand the function, which helped
    me with my code and the example I provided in my initial post.
    Unfortunately, in this example, the matrix from which the
    sub-matrices are extracted is dense, even though it uses a sparse
    structure. This does not clarify how to define sub-matrices when
    extracting from a sparse distributed matrix. Since my initial post,
    I have discovered that having more columns than rows can also result
    in the same error message.
    <p>So, my questions boil down to:</p>
    <p>Can MatCreateSubMatricesMPI extract rectangular matrices from a
      square distributed sparse matrix?</p>
    <p>If not, the fact that only square matrices can be extracted in
      this context should perhaps be mentioned in the documentation.<br>
    </p>
    <p>If so, I would be very grateful for any assistance in defining an
      IS pair in this context.<br>
    </p>
    <p>Regards</p>
    <p>A.S.<br>
    </p>
    <div>Le 27/07/2025 à 00:15, Mark Adams a
      écrit :<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">First, you can not mix communicators in PETSc calls
        in general (ever?), but this error looks like you might
        be asking for a row from the matrix that does not exist.
        <div>You should start with a PETSc example code. Test it and
          modify it to suit your needs.</div>
        <div><br>
        </div>
        <div>Good luck,</div>
        <div>Mark</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Fri, Jul 25, 2025 at
          9:31 AM Alexis SALZMAN <<a href="mailto:alexis.salzman@ec-nantes.fr" target="_blank">alexis.salzman@ec-nantes.fr</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
          <br>
          As I am relatively new to Petsc, I may have misunderstood how
          to use the <br>
          MatCreateSubMatricesMPI function. The attached code is tuned
          for three <br>
          processes and extracts one matrix for each colour of a
          subcommunicator <br>
          that has been created using the MPI_Comm_split function from
          an  MPIAij <br>
          matrix. The following error message appears when the code is
          set to its <br>
          default configuration (i.e. when a rectangular matrix is
          extracted with <br>
          more rows than columns for colour 0):<br>
          <br>
          [0]PETSC ERROR: --------------------- Error Message <br>
          --------------------------------------------------------------<br>
          [0]PETSC ERROR: Argument out of range<br>
          [0]PETSC ERROR: Column too large: col 4 max 3<br>
          [0]PETSC ERROR: See <a href="https://urldefense.us/v3/__https://petsc.org/release/faq/__;!!G_uCfscf7eWS!ZqH097BZ0G0O3WI7RWrwIKFNpyk0czSWEqfusAeTlgEygAffwpgBUzsLw1TIoGkjZ3mYG-NRQxxFoxU4y8EyY0ofiz9I43Qwe0w$" rel="noreferrer" target="_blank">https://urldefense.us/v3/__https://petsc.org/release/faq/__;!!G_uCfscf7eWS!ZqH097BZ0G0O3WI7RWrwIKFNpyk0czSWEqfusAeTlgEygAffwpgBUzsLw1TIoGkjZ3mYG-NRQxxFoxU4y8EyY0ofiz9I43Qwe0w$</a> 
          for trouble shooting.<br>
          [0]PETSC ERROR: Petsc Release Version 3.22.2, unknown<br>
          <br>
          ... petsc git hash 2a89477b25f compiled on a dell i9 computer
          with Gcc <br>
          14.3, mkl 2025.2, .....<br>
          [0]PETSC ERROR: #1 MatSetValues_SeqAIJ() at <br>
          ...petsc/src/mat/impls/aij/seq/aij.c:426<br>
          [0]PETSC ERROR: #2 MatSetValues() at <br>
          ...petsc/src/mat/interface/matrix.c:1543<br>
          [0]PETSC ERROR: #3 MatSetSeqMats_MPIAIJ() at <br>
          .../petsc/src/mat/impls/aij/mpi/mpiov.c:2965<br>
          [0]PETSC ERROR: #4 MatCreateSubMatricesMPI_MPIXAIJ() at <br>
          .../petsc/src/mat/impls/aij/mpi/mpiov.c:3163<br>
          [0]PETSC ERROR: #5 MatCreateSubMatricesMPI_MPIAIJ() at <br>
          .../petsc/src/mat/impls/aij/mpi/mpiov.c:3196<br>
          [0]PETSC ERROR: #6 MatCreateSubMatricesMPI() at <br>
          .../petsc/src/mat/interface/matrix.c:7293<br>
          [0]PETSC ERROR: #7 main() at sub.c:169<br>
          <br>
          When the '-ok' option is selected, the code extracts a square
          matrix for <br>
          colour 0, which runs smoothly in this case. Selecting the
          '-trans' <br>
          option swaps the row and column selection indices, providing a
          <br>
          transposed submatrix smoothly. For colour 1, which uses only
          one process <br>
          and is therefore sequential, rectangular extraction is OK
          regardless of <br>
          the shape.<br>
          <br>
          Is this dependency on the shape expected? Have I missed an
          important <br>
          tuning step somewhere?<br>
          <br>
          Thank you in advance for any clarification.<br>
          <br>
          Regards<br>
          <br>
          A.S.<br>
          <br>
          P.S.: I'm sorry, but as I'm leaving my office for the
          following weeks <br>
          this evening, I won't be very responsive during this period.<br>
          <br>
          <br>
        </blockquote>
      </div>
    </blockquote>
  </div>

</blockquote></div>