<div dir="ltr"><div>Sorry about the delay on this. I can reproduce.<br></div><div><br></div><div>This regression appears to be a result of this optimization: <a href="https://gitlab.com/petsc/petsc/-/merge_requests/4273">https://gitlab.com/petsc/petsc/-/merge_requests/4273</a></div><div><br></div><div>The changes there including having MatPreallocator destroy its internal hash structure within MatPreallocatorPreallocate(), which allows for a lower overall memory footprint but prevents usage of the same MatPreallocate object for two Mats. The error you see is because this hash structure was destroyed during the first preallocation. We didn't catch this because our test suite doesn't test that usage.</div><div><br></div><div>cc'ing PETSc dev because I'm not sure how to best resolve this - enforce that a MatPreallocator is only "good once", remove the <span id="gmail-LC182" class="gmail-line" lang="c"><span class="gmail-n">PetscHSetIJDestroy</span>() calls and accept the bigger memory footprint, or something else more clever?</span></div><div><span id="gmail-LC182" class="gmail-line" lang="c"><br></span></div><div><span id="gmail-LC182" class="gmail-line" lang="c">My test to reproduce with C, which can be included in our fix in src/mat/tests , attached.<br></span></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Mo., 24. Jan. 2022 um 10:33 Uhr schrieb Marius Buerkle <<a href="mailto:mbuerkle@web.de">mbuerkle@web.de</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Hi,<br>
 <br>
I try to use MatPreallocatorPreallocate to allocate a MATMPIAIJ matrix A . I define the MATPREALLOCATOR preM with MatSetValues and then call MatPreallocatorPreallocate to get A. This works on the first call to MatPreallocatorPreallocate, but if I call MatPreallocatorPreallocate  again with the same preM to get another matrix B then I get a segfault, although the program continues to run (see below). It worked with PETSC 3.15 but with 3.16 I stopped working. <br>
When I check mat_info_nz_allocated and mat_info_nz_used for the allocated matrix it looks correct for the first call, but on the second call mat_info_nz_used is 0. I also attached a minimal example. <br>
<br>
<br>
[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>
[0]PETSC ERROR: Null argument, when expecting valid pointer<br>
[1]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>
[0]PETSC ERROR: Null Pointer: Parameter # 1<br>
[0]PETSC ERROR: See <a href="https://petsc.org/release/faq/" rel="noreferrer" target="_blank">https://petsc.org/release/faq/</a> for trouble shooting.<br>
[0]PETSC ERROR: [1]PETSC ERROR: Null argument, when expecting valid pointer<br>
[1]PETSC ERROR: Petsc Development GIT revision: v3.16.3-686-g5e81a90  GIT Date: 2022-01-23 05:13:26 +0000<br>
[0]PETSC ERROR: ./prem_test on a  named cd001 by cdfmat_marius Mon Jan 24 18:21:17 2022<br>
[0]PETSC ERROR: Null Pointer: Parameter # 1<br>
[1]PETSC ERROR: See <a href="https://petsc.org/release/faq/" rel="noreferrer" target="_blank">https://petsc.org/release/faq/</a> for trouble shooting.<br>
[1]PETSC ERROR: Configure options --prefix=/home/cdfmat_marius/prog/petsc/petsc_main_dbg --with-scalar-type=complex --with-fortran-kernels=1 --with-64-bit-indices=0 --CC=mpiicc --COPTFLAGS="-g -traceback" --CXX=mpiicpc --CXXOPTFLAGS="-g -traceback" --FC=mpiifort --FOPTFLAGS="-g -traceback" --with-mpi=1 --with-x=0 --with-cuda=0 --download-parmetis=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.parmetis.tar.gz --download-parmetis-commit=HEAD --download-metis=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.metis.tar.gz --download-metis-commit=HEAD --download-slepc=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.slepc_main.tar.gz --download-slepc-commit=HEAD --download-superlu_dist=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.superlu_dist.tar.gz --download-superlu_dist-commit=HEAD --download-mumps=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.mumps.tar.gz --download-mumps-commit=HEAD --download-hypre=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.hypre.tar.gz --download-hypre-commit=HEAD --download-hwloc=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/hwloc-2.5.0.tar.gz --download-sowing=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.sowing.tar.gz --download-elemental=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.elemental.tar.gz --download-elemental-commit=HEAD --download-make=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/make-4.2.1-6.fc28.tar.gz --download-ptscotch=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.ptscotch.tar.gz --download-ptscotch-commit=HEAD --with-openmp=0 --with-pthread=0 --with-cxx-dialect=c++11 --with-debugging=1 --with-cuda=0 --with-cudac=0 --with-valgrind=0 --with-blaslapack-lib="-mkl=sequential -lmkl_scalapack_lp64 -lmkl_blacs_intelmpi_lp64 -lpthread -lm -ldl" --with-scalapack-lib="-mkl=sequential -lmkl_scalapack_lp64 -lmkl_blacs_intelmpi_lp64 -lpthread -lm -ldl" --with-mkl_pardiso-dir=/home/appli/intel/compilers_and_libraries_2020.4.304/linux/mkl --with-mkl_cpardiso-dir=/home/appli/intel/compilers_and_libraries_2020.4.304/linux/mkl --with-mkl_sparse-dir=/home/appli/intel/compilers_and_libraries_2020.4.304/linux/mkl --with-mkl_sparse_optimize-dir=/home/appli/intel/compilers_and_libraries_2020.4.304/linux/mkl<br>
[0]PETSC ERROR: Petsc Development GIT revision: v3.16.3-686-g5e81a90  GIT Date: 2022-01-23 05:13:26 +0000<br>
[1]PETSC ERROR: ./prem_test on a  named cd001 by cdfmat_marius Mon Jan 24 18:21:17 2022<br>
[1]PETSC ERROR: #1 PetscHSetIJGetSize() at /home/cdfmat_marius/prog/petsc/git/petsc_main/include/petsc/private/hashsetij.h:13<br>
[0]PETSC ERROR: #2 MatPreallocatorPreallocate_Preallocator() at /home/cdfmat_marius/prog/petsc/git/petsc_main/src/mat/impls/preallocator/matpreallocator.c:165<br>
[0]PETSC ERROR: #3 MatPreallocatorPreallocate() at /home/cdfmat_marius/prog/petsc/git/petsc_main/src/mat/impls/preallocator/matpreallocator.c:234<br>
Configure options --prefix=/home/cdfmat_marius/prog/petsc/petsc_main_dbg --with-scalar-type=complex --with-fortran-kernels=1 --with-64-bit-indices=0 --CC=mpiicc --COPTFLAGS="-g -traceback" --CXX=mpiicpc --CXXOPTFLAGS="-g -traceback" --FC=mpiifort --FOPTFLAGS="-g -traceback" --with-mpi=1 --with-x=0 --with-cuda=0 --download-parmetis=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.parmetis.tar.gz --download-parmetis-commit=HEAD --download-metis=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.metis.tar.gz --download-metis-commit=HEAD --download-slepc=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.slepc_main.tar.gz --download-slepc-commit=HEAD --download-superlu_dist=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.superlu_dist.tar.gz --download-superlu_dist-commit=HEAD --download-mumps=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.mumps.tar.gz --download-mumps-commit=HEAD --download-hypre=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.hypre.tar.gz --download-hypre-commit=HEAD --download-hwloc=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/hwloc-2.5.0.tar.gz --download-sowing=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.sowing.tar.gz --download-elemental=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.elemental.tar.gz --download-elemental-commit=HEAD --download-make=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/make-4.2.1-6.fc28.tar.gz --download-ptscotch=/home/cdfmat_marius/prog/petsc/git/petsc_main/externalpackages/git.ptscotch.tar.gz --download-ptscotch-commit=HEAD --with-openmp=0 --with-pthread=0 --with-cxx-dialect=c++11 --with-debugging=1 --with-cuda=0 --with-cudac=0 --with-valgrind=0 --with-blaslapack-lib="-mkl=sequential -lmkl_scalapack_lp64 -lmkl_blacs_intelmpi_lp64 -lpthread -lm -ldl" --with-scalapack-lib="-mkl=sequential -lmkl_scalapack_lp64 -lmkl_blacs_intelmpi_lp64 -lpthread -lm -ldl" --with-mkl_pardiso-dir=/home/appli/intel/compilers_and_libraries_2020.4.304/linux/mkl --with-mkl_cpardiso-dir=/home/appli/intel/compilers_and_libraries_2020.4.304/linux/mkl --with-mkl_sparse-dir=/home/appli/intel/compilers_and_libraries_2020.4.304/linux/mkl --with-mkl_sparse_optimize-dir=/home/appli/intel/compilers_and_libraries_2020.4.304/linux/mkl<br>
[1]PETSC ERROR: #1 PetscHSetIJGetSize() at /home/cdfmat_marius/prog/petsc/git/petsc_main/include/petsc/private/hashsetij.h:13<br>
[1]PETSC ERROR: #2 MatPreallocatorPreallocate_Preallocator() at /home/cdfmat_marius/prog/petsc/git/petsc_main/src/mat/impls/preallocator/matpreallocator.c:165<br>
[1]PETSC ERROR: #3 MatPreallocatorPreallocate() at /home/cdfmat_marius/prog/petsc/git/petsc_main/src/mat/impls/preallocator/matpreallocator.c:234<br>
<br>
Best and Thanks,<br>
Marius<br>
<br>
<br>
</blockquote></div>