<head><!-- BaNnErBlUrFlE-HeAdEr-start -->
<style>
  #pfptBanner646200c { all: revert !important; display: block !important; 
    visibility: visible !important; opacity: 1 !important; 
    background-color: #D0D8DC !important; 
    max-width: none !important; max-height: none !important }
  .pfptPrimaryButton646200c:hover, .pfptPrimaryButton646200c:focus {
    background-color: #b4c1c7 !important; }
  .pfptPrimaryButton646200c:active {
    background-color: #90a4ae !important; }
</style>

<!-- BaNnErBlUrFlE-HeAdEr-end -->
</head><!-- BaNnErBlUrFlE-BoDy-start -->
<!-- Preheader Text : BEGIN -->
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden;">
 On Thu, Jun 6, 2024, 14: 53 Klaij, Christiaan <C. Klaij@ marin. nl> wrote: I'm writing a matrix to file from my fortran code (that uses petsc-3. 19. 4) with -mat_view binary. Then, I'm trying to load this mat into python (that uses
</div>
<!-- Preheader Text : END -->

<!-- Email Banner : BEGIN -->
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden;">ZjQcmQRYFpfptBannerStart</div>

<!--[if ((ie)|(mso))]>
  <table border="0" cellspacing="0" cellpadding="0" width="100%" style="padding: 16px 0px 16px 0px; direction: ltr" ><tr><td>
    <table border="0" cellspacing="0" cellpadding="0" style="padding: 0px 10px 5px 6px; width: 100%; border-radius:4px; border-top:4px solid #90a4ae;background-color:#D0D8DC;"><tr><td valign="top">
      <table align="left" border="0" cellspacing="0" cellpadding="0" style="padding: 4px 8px 4px 8px">
        <tr><td style="color:#000000; font-family: 'Arial', sans-serif; font-weight:bold; font-size:14px; direction: ltr">
          This Message Is From an External Sender
        </td></tr>
        <tr><td style="color:#000000; font-weight:normal; font-family: 'Arial', sans-serif; font-size:12px; direction: ltr">
          This message came from outside your organization.
        </td></tr>

      </table>

    </td></tr></table>
  </td></tr></table>
<![endif]-->

<![if !((ie)|(mso))]>
  <div dir="ltr"  id="pfptBanner646200c" style="all: revert !important; display:block !important; text-align: left !important; margin:16px 0px 16px 0px !important; padding:8px 16px 8px 16px !important; border-radius: 4px !important; min-width: 200px !important; background-color: #D0D8DC !important; background-color: #D0D8DC; border-top: 4px solid #90a4ae !important; border-top: 4px solid #90a4ae;">
    <div id="pfptBanner646200c" style="all: unset !important; float:left !important; display:block !important; margin: 0px 0px 1px 0px !important; max-width: 600px !important;">
      <div id="pfptBanner646200c" style="all: unset !important; display:block !important; visibility: visible !important; background-color: #D0D8DC !important; color:#000000 !important; color:#000000; font-family: 'Arial', sans-serif !important; font-family: 'Arial', sans-serif; font-weight:bold !important; font-weight:bold; font-size:14px !important; line-height:18px !important; line-height:18px">
        This Message Is From an External Sender
      </div>
      <div id="pfptBanner646200c" style="all: unset !important; display:block !important; visibility: visible !important; background-color: #D0D8DC !important; color:#000000 !important; color:#000000; font-weight:normal; font-family: 'Arial', sans-serif !important; font-family: 'Arial', sans-serif; font-size:12px !important; line-height:18px !important; line-height:18px; margin-top:2px !important;">
This message came from outside your organization.
      </div>

    </div>

    <div style="clear: both !important; display: block !important; visibility: hidden !important; line-height: 0 !important; font-size: 0.01px !important; height: 0px"> </div>
  </div>
<![endif]>

<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden;">ZjQcmQRYFpfptBannerEnd</div>
<!-- Email Banner : END -->

<!-- BaNnErBlUrFlE-BoDy-end -->
<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 6, 2024, 14:53 Klaij, Christiaan <<a href="mailto:C.Klaij@marin.nl">C.Klaij@marin.nl</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div style="display:none!important;display:none;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden">
 I'm writing a matrix to file from my fortran code (that uses petsc-3. 19. 4) with -mat_view binary. Then, I'm trying to load this mat into python (that uses petsc-3. 21. 0). This works fine using single or multiple procs when the marix
</div>



<div style="display:none!important;display:none;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden">ZjQcmQRYFpfptBannerStart</div>



<u></u>
  <div dir="ltr" id="m_-8935688308108847895pfptBanner3qsbpc4" style="display:block!important;text-align:left!important;margin:16px 0px 16px 0px!important;padding:8px 16px 8px 16px!important;border-radius:4px!important;min-width:200px!important;background-color:#d0d8dc!important;background-color:#d0d8dc;border-top:4px solid #90a4ae!important;border-top:4px solid #90a4ae">
    <div id="m_-8935688308108847895pfptBanner3qsbpc4" style="float:left!important;display:block!important;margin:0px 0px 1px 0px!important;max-width:600px!important">
      <div id="m_-8935688308108847895pfptBanner3qsbpc4" style="display:block!important;background-color:#d0d8dc!important;color:#000000!important;color:#000000;font-family:'Arial',sans-serif!important;font-family:'Arial',sans-serif;font-weight:bold!important;font-weight:bold;font-size:14px!important;line-height:18px!important;line-height:18px">
        This Message Is From an External Sender
      </div>
      <div id="m_-8935688308108847895pfptBanner3qsbpc4" style="display:block!important;background-color:#d0d8dc!important;color:#000000!important;color:#000000;font-weight:normal;font-family:'Arial',sans-serif!important;font-family:'Arial',sans-serif;font-size:12px!important;line-height:18px!important;line-height:18px;margin-top:2px!important">
This message came from outside your organization.
      </div>

    </div>

    <div style="clear:both!important;display:block!important;line-height:0!important;font-size:0.01px!important;height:0px"> </div>
  </div>
<u></u>

<div style="display:none!important;display:none;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden">ZjQcmQRYFpfptBannerEnd</div>







<div><div>I'm writing a matrix to file from my fortran code (that uses petsc-3.19.4) with -mat_view binary. Then, I'm trying to load this mat into python (that uses petsc-3.21.0). This works fine using single or multiple procs when the marix was written using a single proc (attached file a_mat_np_1.dat). However, when the matrix was written using mulitple procs (attached file a_mat_n_2.dat) I get the error below. Is this supposed to work? If so, what I'm I doing wrong?<br></div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">This should work. And your script seems ok too . How did you save the matrix in parallel? I suspect that file is corrupt </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><br>$ cat test_matrixImport_binary.py<br>import sys<br>import petsc4py<br>from petsc4py import PETSc<br>from mpi4py import MPI<br><br># mat files<br>#filename = "./a_mat_np_1.dat"  # Works<br>filename = "./a_mat_np_2.dat"   # Doesn't work<br><br># Initialize PETSc<br>petsc4py.init(sys.argv)<br><br># Create a viewer for reading the binary file<br>viewer = PETSc.Viewer().createBinary(filename, mode='r', comm=PETSc.COMM_WORLD)<br><br># Create a matrix and load data from the binary file<br>A = PETSc.Mat().create(comm=PETSc.COMM_WORLD)<br>A.load(viewer)<br><br>$ python test_matrixImport_binary.py <br>Traceback (most recent call last):<br>  File "/projects/P35662.700/test_cklaij/test_matrixImport_binary.py", line 18, in <module><br>    A.load(viewer)<br>  File "petsc4py/PETSc/Mat.pyx", line 2025, in petsc4py.PETSc.Mat.load<br>petsc4py.PETSc.Error: error code 79<br>[0] MatLoad() at /home/cklaij/petsc-3.21.0/src/mat/interface/matrix.c:1344<br>[0] MatLoad_SeqAIJ() at /home/cklaij/petsc-3.21.0/src/mat/impls/aij/seq/aij.c:5091<br>[0] MatLoad_SeqAIJ_Binary() at /home/cklaij/petsc-3.21.0/src/mat/impls/aij/seq/aij.c:5142<br>[0] Unexpected data in file<br>[0] Inconsistent matrix data in file: nonzeros = 460, sum-row-lengths = 761<br><br>$ mpirun -n 2 python test_matrixImport_binary.py <br>Traceback (most recent call last):<br>  File "/projects/P35662.700/test_cklaij/test_matrixImport_binary.py", line 18, in <module><br>Traceback (most recent call last):<br>  File "/projects/P35662.700/test_cklaij/test_matrixImport_binary.py", line 18, in <module><br>    A.load(viewer)<br>  File "petsc4py/PETSc/Mat.pyx", line 2025, in petsc4py.PETSc.Mat.load<br>    A.load(viewer)<br>  File "petsc4py/PETSc/Mat.pyx", line 2025, in petsc4py.PETSc.Mat.load<br>petsc4py.PETSc.Error: error code 79<br>[0] MatLoad() at /home/cklaij/petsc-3.21.0/src/mat/interface/matrix.c:1344<br>[0] MatLoad_MPIAIJ() at /home/cklaij/petsc-3.21.0/src/mat/impls/aij/mpi/mpiaij.c:3035<br>[0] MatLoad_MPIAIJ_Binary() at /home/cklaij/petsc-3.21.0/src/mat/impls/aij/mpi/mpiaij.c:3087<br>[0] Unexpected data in file<br>[0] Inconsistent matrix data in file: nonzeros = 460, sum-row-lengths = 761<br>petsc4py.PETSc.Error: error code 79<br>[1] MatLoad() at /home/cklaij/petsc-3.21.0/src/mat/interface/matrix.c:1344<br>[1] MatLoad_MPIAIJ() at /home/cklaij/petsc-3.21.0/src/mat/impls/aij/mpi/mpiaij.c:3035<br>[1] MatLoad_MPIAIJ_Binary() at /home/cklaij/petsc-3.21.0/src/mat/impls/aij/mpi/mpiaij.c:3087<br>[1] Unexpected data in file<br>[1] Inconsistent matrix data in file: nonzeros = 460, sum-row-lengths = 761<br><br><br></div><div dir="ltr" style="font-size:1px;direction:ltr"><table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;font-size:1px"><tbody><tr style="font-size:0"><td align="left" style="vertical-align:top"><table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-size:0;line-height:normal"><tbody><tr style="font-size:0"><td align="left" style="padding:10px 0;vertical-align:top"><img src="cid:ii_18feda229ee74859a161" width="125" height="40" border="0" alt="" style="width:125px;min-width:125px;max-width:125px;height:40px;min-height:40px;max-height:40px;font-size:0"></td></tr></tbody></table></td></tr><tr style="font-size:0"><td align="left" style="vertical-align:top"><table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-size:0"><tbody><tr style="font-size:0"><td align="left" style="vertical-align:top"><table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-size:0;color:#000001;font-style:normal;font-weight:400;white-space:nowrap"><tbody><tr style="font-size:14.67px"><td align="left" style="vertical-align:top;font-family:Calibri,Arial,sans-serif">dr. ir.<span style="font-family:remialcxesans;font-size:1px;color:#ffffff;line-height:1px">​<span style="font-family:'template-A7LWMTpBEe2ifABQ8nUoZA'">​</span><span style="font-family:'zone-1'">​</span><span style="font-family:'zones-AQ'">​</span></span> </td><td align="left" style="vertical-align:top;font-family:Calibri,Arial,sans-serif">Christiaan</td><td align="left" style="vertical-align:top;font-family:Calibri,Arial,sans-serif"> Klaij</td></tr></tbody></table></td><td align="left" style="vertical-align:top"><table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-size:0;color:#000001;font-style:normal;font-weight:400;white-space:nowrap"><tbody><tr style="font-size:14.67px"><td align="left" style="vertical-align:top;font-family:Calibri,Arial,sans-serif"> | </td><td align="left" style="vertical-align:top;font-family:Calibri,Arial,sans-serif">Senior Researcher</td><td align="left" style="vertical-align:top;font-family:Calibri,Arial,sans-serif"> | </td><td align="left" style="vertical-align:top;font-family:Calibri,Arial,sans-serif">Research & Development</td><td align="left" style="vertical-align:top;font-size:0"></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr style="font-size:0"><td align="left" style="vertical-align:top"><table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-size:0"><tbody><tr style="font-size:0"><td align="left" style="vertical-align:top"><table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-size:0;color:#000001;font-style:normal;font-weight:400;white-space:nowrap"><tbody><tr style="font-size:14.67px"><td align="left" style="vertical-align:top;font-family:Calibri,Arial,sans-serif">T <a href="tel:+31%20317%2049%2033%2044" id="m_-8935688308108847895LPlnk689713" style="text-decoration:none;color:#000001" target="_blank" rel="noreferrer">+31 317 49 33 44</a></td><td align="left" style="vertical-align:top;font-family:Calibri,Arial,sans-serif"> | </td><td align="left" style="vertical-align:top;font-family:Calibri,Arial,sans-serif"> <a href="mailto:C.Klaij@marin.nl" id="m_-8935688308108847895LPlnk689713" style="text-decoration:none;color:#000001" target="_blank" rel="noreferrer">C.Klaij@marin.nl</a> </td><td align="left" style="vertical-align:top;font-family:Calibri,Arial,sans-serif">| <a href="https://urldefense.us/v3/__https://www.marin.nl/__;!!G_uCfscf7eWS!YrcVeQ6V8OD3jKxSzzxpyuTgFdncWh4YcL1SgDT8NHqystMpzO1pkd17oNGni-ll5I8qH9_ueOtj3WYWBYeP9zg$" id="m_-8935688308108847895LPlnk689713" style="text-decoration:none;color:#000001" target="_blank" rel="noreferrer">www.marin.nl</a></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr style="font-size:0"><td align="left" style="vertical-align:top"><table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-size:0"><tbody><tr style="font-size:0"><td align="left" style="padding:5px 0 0;vertical-align:top"><table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-size:0"><tbody><tr style="font-size:0"><td align="left" style="vertical-align:top"><table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-size:0;line-height:normal"><tbody><tr style="font-size:0"><td align="left" style="padding:0 3px 3px 0;vertical-align:top"><a href="https://urldefense.us/v3/__https://www.facebook.com/marin.wageningen__;!!G_uCfscf7eWS!YrcVeQ6V8OD3jKxSzzxpyuTgFdncWh4YcL1SgDT8NHqystMpzO1pkd17oNGni-ll5I8qH9_ueOtj3WYWzqK6wKw$" id="m_-8935688308108847895LPlnk689713" style="text-decoration:none" target="_blank" rel="noreferrer"><img src="cid:ii_18feda229eee7a5551c2" width="15" height="15" border="0" title="Facebook" alt="Facebook" style="width:15px;min-width:15px;max-width:15px;height:15px;min-height:15px;max-height:15px;font-size:12px"></a></td></tr></tbody></table></td><td align="left" style="vertical-align:top"><table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-size:0;line-height:normal"><tbody><tr style="font-size:0"><td align="left" style="padding:0 3px 3px 0;vertical-align:top"><a href="https://urldefense.us/v3/__https://www.linkedin.com/company/marin__;!!G_uCfscf7eWS!YrcVeQ6V8OD3jKxSzzxpyuTgFdncWh4YcL1SgDT8NHqystMpzO1pkd17oNGni-ll5I8qH9_ueOtj3WYWIUyfXbM$" id="m_-8935688308108847895LPlnk689713" style="text-decoration:none" target="_blank" rel="noreferrer"><img src="cid:ii_18feda229eed6c4ccb83" width="15" height="15" border="0" title="LinkedIn" alt="LinkedIn" style="width:15px;min-width:15px;max-width:15px;height:15px;min-height:15px;max-height:15px;font-size:12px"></a></td></tr></tbody></table></td><td align="left" style="vertical-align:top"><table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;font-size:0;line-height:normal"><tbody><tr style="font-size:0"><td align="left" style="padding:0 3px 3px 0;vertical-align:top"><a href="https://urldefense.us/v3/__https://www.youtube.com/marinmultimedia__;!!G_uCfscf7eWS!YrcVeQ6V8OD3jKxSzzxpyuTgFdncWh4YcL1SgDT8NHqystMpzO1pkd17oNGni-ll5I8qH9_ueOtj3WYWjtUkoeg$" id="m_-8935688308108847895LPlnk689713" style="text-decoration:none" target="_blank" rel="noreferrer"><img src="cid:ii_18feda229eefc68c0994" width="15" height="15" border="0" title="YouTube" alt="YouTube" style="width:15px;min-width:15px;max-width:15px;height:15px;min-height:15px;max-height:15px;font-size:12px"></a></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div></div></blockquote></div></div></div>