<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><br></div>   Take a look at MatLoad_SeqAIJ_Binary(). You will see how it is easy to simplify that code to get what you need.  You can call PetscViewerBinaryGetDescriptor() and then use <span style="font-family: Menlo; font-size: 16px;">lseek() to skip over all the integer part of the matrix storage (the row lengths and column indices) and not even read that into memory at all.</span><div><font face="Menlo" size="3"><br></font></div><div><font face="Menlo" size="3">  Since the file stores all the numerical values after the integer part you won't need to read a row at a time, just loop over "big chunks" and read a big chunk at a time of the numerical part and add that big chunk to the appropriate place in the in-memory AIJ matrix.  You are free to pick any big chunk size, it should be at least 1000s of doubles for good performance.</font></div><div><font face="Menlo" size="3"><br></font></div><div><font face="Menlo" size="3">   Barry</font></div><div><font face="Menlo" size="3"><br></font><div><br><blockquote type="cite"><div>On May 22, 2025, at 2:23 AM, Donald Duck <superdduck88@gmail.com> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr">Hello everyone<div><br></div><div>A piece of c++ code writes PETSc AIJ matrices to binary files. My task is to compute an average matrix of these AIJ matrices. Therefore I read the first matrix with petsc4py and then start to add the other matrices to it. All matrixes always have the same size, shape, nnz etc.</div><div><br></div><div>However in some cases these matrices are large and only one of it fits into memory and the reading/writing takes a significant amout of time. Is there a way to read it row by row to prevent memory overflow?</div><div><br></div><div>I'm also open for other suggestions, thanks in advance!</div><div><br></div><div>Raphael</div></div>
</div></blockquote></div><br></div></body></html>