Hi, After reading the source code of aij.c, I think the MatSetValues function can be more flexible when preallocation is not correct. Why not use a dynamic array such as c++ vector of triple(a, i, j) to buffer the operation? And flush the buffer to real a,i,j array when MatAssemblyEnd is called? Gong Ding