FreeFEM compilation

Hello Everyone,

I am trying to compile the most recent version of FreeFEM from the develop branch. The compilation seems successful, but when I try to run the codes, I get random error messages, probably related to PETSc. E.g.,

[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
[0]PETSC ERROR: Argument out of range
[0]PETSC ERROR: Inserting a new nonzero at global row/column (6479, 8962) into matrix
[0]PETSC ERROR: WARNING! There are unused option(s) set! Could be the program crashed before usage or a spelling mistake, etc!
[0]PETSC ERROR:   Option left: name:-nw value: navier-stokes-2d-PETSc.edp source: command line
[0]PETSC ERROR:   Option left: name:-v value: 0 source: command line
[0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
[0]PETSC ERROR: PETSc Release Version 3.24.2, unknown
[0]PETSC ERROR: /home/andrasz/freefem/FreeFem-sources/src/mpi/FreeFem++-mpi with 4 MPI process(es) and PETSC_ARCH arch-FreeFem on cnre-ws-11 by andrasz Wed Dec 10 18:38:14 2025
[0]PETSC ERROR: Configure options: --download-cmake --download-mumps --download-parmetis --download-metis --download-hypre --download-superlu --download-slepc --download-hpddm --download-ptscotch --download-suitesparse --download-scalapack --with-fortran-bindings=no --with-scalar-type=real --with-debugging=no
[0]PETSC ERROR: #1 MatSetValues_MPIAIJ() at /home/andrasz/freefem/petsc/src/mat/impls/aij/mpi/mpiaij.c:612
[0]PETSC ERROR: #2 MatSetValues() at /home/andrasz/freefem/petsc/src/mat/interface/matrix.c:1601

I use the following commands to compile FreeFEM:

apt-get update && apt-get upgrade
sudo apt-get install cpp freeglut3-dev g++ gcc gfortran  m4 make patch pkg-config wget unzip liblapack-dev libhdf5-dev libgsl-dev autoconf automake autotools-dev bison flex gdb git cmake
sudo apt-get install -y mpich
#================================ core installation 
export FF_DIR=${PWD}/FreeFem-sources
export PETSC_DIR=${PWD}/petsc 
export PETSC_ARCH=arch-FreeFem
export PETSC_VAR=${PETSC_DIR}/${PETSC_ARCH} 
git clone https://github.com/FreeFem/FreeFem-sources.git
git clone https://gitlab.com/petsc/petsc
cd ${PETSC_DIR} 
git checkout v3.24.2
./configure --download-cmake --download-mumps --download-parmetis --download-metis --download-hypre --download-superlu --download-slepc --download-hpddm --download-ptscotch --download-suitesparse --download-scalapack --with-fortran-bindings=no --with-scalar-type=real --with-debugging=no 
make -j10
export PETSC_ARCH=arch-FreeFem-complex 
./configure --with-cmake-dir=arch-FreeFem --with-mumps-dir=arch-FreeFem --with-parmetis-dir=arch-FreeFem --with-metis-dir=arch-FreeFem --with-superlu-dir=arch-FreeFem --download-slepc --download-hpddm --with-ptscotch-dir=arch-FreeFem --with-suitesparse-dir=arch-FreeFem --with-scalapack-dir=arch-FreeFem --with-fortran-bindings=no --with-scalar-type=complex --with-debugging=no 
make -j10 
cd ${FF_DIR} 
git checkout develop
autoreconf -i
./configure --without-hdf5 --enable-download_metis --enable-download_parmetis --enable-download_nlopt --enable-optim --with-petsc=${PETSC_VAR}/lib --with-petsc_complex=${PETSC_VAR}-complex/lib 
make -j10  

I attach the config.log of FreeFEM of PETSc. Any help would be much appreciated!

config_PETSc-complex.log (1.3 MB)

config_PETSc.zip (502.5 KB)

config_FreeFEM.log (163.5 KB)

What if you let PETSc compile MPICH? Are you sure there is no other instances of PETSc.so (the FreeFEM plugin) somewhere else on the machine? Where does the error happen (inside FreeFEM sources or on a directory somewhere else)?

Thanks for the prompt reply. Compiling MPICH with PETSc seems to have resolved the issue.