<div dir="ltr">How big are these matrices?<div><br></div><div>The memory PETSc allocates is (8+4)*num_nnz + 4*num_rows bytes (in double precision) <a href="https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/mat/impls/aij/seq/aij.h*L47__;Iw!!G_uCfscf7eWS!eQLvMSRayHm9_oWVvaVFu0KZKnXMgFnQ06zPI0ciy6V4RLioHdXqliTOEFJQs8W8qb-y8v2-wVe3mKbGwBDucIVgolkrDHg$">https://gitlab.com/petsc/petsc/-/blob/main/src/mat/impls/aij/seq/aij.h#L47</a></div><div>Assuming num_nnz >> num_rows, 2.8 billion nonzeros fit 32GB of RAM.</div><div><br></div><div>Anyway, if you say you use the same job for matrix write + load + averaging, then you are better off allocating a single matrix and perform averaging in the C++ code directly</div><div><br></div><div>allocate_and_zero_a single matrix</div><div>for i in range(number_of_matrices)</div><div>   add_values_to_the_matrix</div><div>scale_matrix_for_average</div><div><br></div><div><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">Il giorno gio 22 mag 2025 alle ore 18:55 <a href="mailto:superdduck88@gmail.com">superdduck88@gmail.com</a> <<a href="mailto:superdduck88@gmail.com">superdduck88@gmail.com</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"><div dir="auto"><div dir="ltr"></div><div dir="ltr">Hi</div><div dir="ltr"><br></div><div dir="ltr">The averaging takes place on the same hardware and as part of the same job as the writing the matrix to file in the c++ code. The number of nodes is determined on the problem size and therefor for a single matrix. Allocating extra nodes for the averaging is not economical, unfortunately.</div><div dir="ltr"><br><blockquote type="cite">On 22 May 2025, at 16:52, Junchao Zhang <<a href="mailto:junchao.zhang@gmail.com" target="_blank">junchao.zhang@gmail.com</a>> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Did you run in MPI parallel?   If not, using MPI and running with multiple compute nodes could solve the problem.</div><div><br></div><div>Are all these matrices already on disk?  Then you have to pay the I/O cost for reading the matrices. </div><div><br></div><div>--Junchao Zhang</div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 22, 2025 at 8:21 AM Donald Duck <<a href="mailto:superdduck88@gmail.com" target="_blank">superdduck88@gmail.com</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"><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>
</blockquote></div></div>
</div></blockquote></div></blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Stefano</div>