[petsc-users] Parallel assembly of a matrix problem

Patrick Alken patrick.alken at geomag.info
Sun Aug 14 23:12:20 CDT 2022

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:


[1]PETSC ERROR: --------------------- Error Message 
[1]PETSC ERROR: Argument out of range
[1]PETSC ERROR: New nonzero at (0,207) caused a malloc
off this check
[1]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
[1]PETSC ERROR: Petsc Release Version 3.17.4, unknown
[1]PETSC ERROR: #1 MatSetValues_MPIAIJ() at 


and then many MatSetValues errors follow.

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).

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.

Any pointers would be greatly appreciated.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: mwe.c
Type: text/x-csrc
Size: 6728 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220814/d929d5ef/attachment.bin>
-------------- next part --------------
default: mwe

include ${SLEPC_DIR}/lib/slepc/conf/slepc_common


lib_dir = /home/palken/usr/lib
common_libs = -L${lib_dir} ${lib_dir}/libgsl.a -lm -lgslcblas ${lib_dir}/liblapacke.a ${lib_dir}/liblapack.a -lcsparse

OBJECTS = mwe.o

mwe: ${OBJECTS}
	${CLINKER} -o mwe ${OBJECTS} ${SLEPC_EPS_LIB} ${common_libs}

More information about the petsc-users mailing list