<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div> There are two sets of tools for helping compute the preallocation in a "pre-compute" step that "count" what you will need later efficiently so that you don't need to "figure out" the preallocation information yourself. They are both slightly clumsy, unfortunately, but should work fine.<div class=""><br class=""></div><div class=""> <a href="https://petsc.org/main/docs/manualpages/Mat/MATPREALLOCATOR/?highlight=matpreallocator" class="">https://petsc.org/main/docs/manualpages/Mat/MATPREALLOCATOR/?highlight=matpreallocator</a></div><div class=""><br class=""></div><div class=""><a href="https://petsc.org/main/docs/manualpages/Mat/MatPreallocateBegin/?highlight=matpreallocatebegin" class="">https://petsc.org/main/docs/manualpages/Mat/MatPreallocateBegin/?highlight=matpreallocatebegin</a> <br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 15, 2022, at 12:12 AM, Patrick Alken <<a href="mailto:patrick.alken@geomag.info" class="">patrick.alken@geomag.info</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">I am trying to assemble a matrix in parallel in Petsc, and it is working for 1 processor, but when I try running it with 2 processors I get errors like the following:<br class=""><br class="">----<br class=""><br class="">[1]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br class="">[1]PETSC ERROR: Argument out of range<br class="">[1]PETSC ERROR: New nonzero at (0,207) caused a malloc<br class="">Use MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE) to turn off this check<br class="">[1]PETSC ERROR: See <a href="https://petsc.org/release/faq/" class="">https://petsc.org/release/faq/</a> for trouble shooting.<br class="">[1]PETSC ERROR: Petsc Release Version 3.17.4, unknown<br class="">[1]PETSC ERROR: #1 MatSetValues_MPIAIJ() at /data/palken/petsc/src/mat/impls/aij/mpi/mpiaij.c:506<br class=""><br class="">----<br class=""><br class="">and then many MatSetValues errors follow.<br class=""><br class="">I have attached a minimal working example and a Makefile. My code does depend on the GSL library also. I think there must be a problem in how I set up the d_nnz and o_nnz arrays for the MatMPIAIJSetPreallocation() function (lines 211-235 of mwe.c).<br class=""><br class="">I am building a matrix using radial basis functions with compact support, so the matrix entries are zero when ||Xi - Xj|| >= c, where c is the RBF shape parameter. This is accounted for on line 224 and 254 of the code. As far as I can tell I am consistent in the way I define the nnz arrays and the way I call MatSetValues, so I don't know why Petsc would need to malloc additional memory during the assembly process.<br class=""><br class="">Any pointers would be greatly appreciated.<br class=""><br class="">Patrick<br class=""><span id="cid:EBE17D70-4E19-4430-A836-3F3D2458FC05"><mwe.c></span><span id="cid:4FC3B0AA-0DBD-4D14-AAF4-A53DBA999DD1"><Makefile.txt></span></div></div></blockquote></div><br class=""></div></body></html>