Skip to content

Petsc 3.25 upgrade#2781

Draft
Manangka wants to merge 23 commits into
MODFLOW-ORG:developfrom
Manangka:petsc_upgrade
Draft

Petsc 3.25 upgrade#2781
Manangka wants to merge 23 commits into
MODFLOW-ORG:developfrom
Manangka:petsc_upgrade

Conversation

@Manangka
Copy link
Copy Markdown
Contributor

@Manangka Manangka commented Apr 20, 2026

This PR contains the changes needed to get MODFLOW working with the latest petsc version.

How to build
To build petsc i used the following build.py

#!/usr/bin/python3
if __name__ == '__main__':
  import sys
  import os
  sys.path.insert(0, os.path.abspath('config'))
  import configure
  configure_options = [
    '--with-blaslapack-lib=-L/cygdrive/c/PROGRA~2/Intel/oneAPI/mkl/latest/lib mkl_intel_lp64_dll.lib mkl_sequential_dll.lib mkl_core_dll.lib',
    '--with-cc=icx',
    '--with-cxx=icx',
    '--with-fc=ifx',
    '--with-shared-libraries=1',
    'FPPFLAGS=-I/cygdrive/c/PROGRA~2/Intel/oneAPI/mpi/latest/include/mpi',
    '--debugging=0',
    '--with-mpi-include=/cygdrive/c/PROGRA~2/Intel/oneAPI/mpi/latest/include',
    '--with-mpi-lib=/cygdrive/c/PROGRA~2/Intel/oneAPI/mpi/latest/lib/impi.lib',
    '--with-mpiexec=/cygdrive/c/PROGRA~2/Intel/oneAPI/mpi/latest/bin/mpiexec -localonly',
    '--with-fortran-bindings=1',
    '--with-fortran-bindings-inplace=0',
    '--prefix=/cygdrive/c/dev/externals/petsc/install/arch-mswin-icx',
    'PETSC_ARCH=arch-mswin-icx'
  ]
  configure.petsc_configure(configure_options)

The commands to build are:

python build.py
make PETSC_DIR=/cygdrive/c/dev/externals/petsc PETSC_ARCH=arch-mswin-icx all
make PETSC_DIR=/cygdrive/c/dev/externals/petsc PETSC_ARCH=arch-mswin-icx install

This will create an out of build install at c/dev/externals/petsc/install/arch-mswin-icx

Get it working with PKG CONFIG
After running the make install command the files are placed at what you have defined at prefix.
The pkg config configuration file is located at ${prefix}\lib\pkgconfig\PETSc.pc.
For the windows build this needs to be updated. The reason for this is that the windows build uses cygwin to build petsc.

  • In the PETSc.pc file replace all occurrences of /cygdrive/c/ by C:/

At the PETSc.pc location to the PKG_CONFIG_PATH environment variable
For pkg config to be able to find petsc the location of the PETSc.pc file needs to be added to PKG_CONFIG_PATH environment variable. On windows this can be done at System Properties ->Advanced->Environment Variables
Then create or update the PKG_CONFIG_PATH with the location

An overview of the changes are:
pixi.toml

  • Updated the hardcoded PKG_CONFIG_PATH to also include the system PKG_CONFIG_PATH

meson

  • Removed compiling the mod files ourselves. Petsc now automatically generates them so their is no need anymore
  • Find the petsc library using pkg config. This will automatically set all correct linker and include arguments

Fortran

  • The ifx compiler produced errors when passing context classes to petsc. The error stated that type-bound-procedures couldn't be passed along. To fix this i moved the create and destroy methods out of the class, making the classes pure data classes
  • The new version of petsc now adds enums. However for some reason not all methods are exported/available in the library. This most likely is a petsc bug due the way the exports are defined. The workaround applied is to compare the integer values behind the enums directly e.g. flag%v == KSP_CONVERGED_ITERATING%v
    -Some of the methods have been renamed e.g. VecGetArrayReadF90 -> VecGetArrayRead
  • Due to a missing export one of the PCShellGetContext arguments is not available. The solution is to use the petsc macro directly and call it's c counterpart
  • In the new version of petsc a new type for a boolean is introduced: PetscBool
  • To Fix a runtime error I recreate the context%x_old and context%delta_x when they are first accesed

Things that still need to be figures out:

  • The runtime error where i recreate the x_old and delta_x vectors shouldn't be nececarry. For some reason they are intialized with an incorrect size. We need to figure out why this is happening
  • The pipeline needs to be updated. To work with the new meson pkg_config approach this also means that the PETSc.px need to be updated and added to the PKG_CONFIG_PATH variable
  • This PR has only be tested on a windows system with the IFX compiler. More work may be needed on other systems/compilers

Checklist of items for pull request

  • Replaced section above with description of pull request
  • Closed issue #xxxx
  • Referenced issue or pull request #xxxx
  • Added new test or modified an existing test
  • Ran ruff on new and modified python scripts in .doc, autotests, doc, distribution, pymake, and utils subdirectories.
  • Formatted new and modified Fortran source files with fprettify
  • Added doxygen comments to new and modified procedures
  • Updated meson files, makefiles, and Visual Studio project files for new source files
  • Updated definition files
  • Updated develop.toml with a plain-language description of the bug fix, change, feature; required for changes that may affect users
  • Updated input and output guide
  • Removed checklist items not relevant to this pull request

For additional information see instructions for contributing and instructions for developing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant