From fdd12d75a093dc7c84df176acb66ee1e88f528b4 Mon Sep 17 00:00:00 2001 From: Boris Kaus <61824822+boriskaus@users.noreply.github.com> Date: Thu, 3 Oct 2024 08:05:22 +0200 Subject: [PATCH] [PETSc] v3.21.5 (#9335) * buildscript for 3.21.5 * drop support for HDF5 * typos * deactivate mumps for a few systems * deactivate mpich/openmpi and freebsd * missing patches * more mistakes in mpi-constants.patch * update patch file * bugfix * add hypre * no need for hypre on windows * compile superlu_dist on 32bit systems as well * fix MPItrampoline version and activate all other builds * address comments by @eschnett * incorporate requestes changes by @giordano * add 32bit example to test correct implementation --------- Co-authored-by: Viral B. Shah <744411+ViralBShah@users.noreply.github.com> --- P/PETSc/build_tarballs.jl | 131 ++++++-- P/PETSc/bundled/patches/mpi-constants.patch | 353 ++++++++++++-------- 2 files changed, 329 insertions(+), 155 deletions(-) diff --git a/P/PETSc/build_tarballs.jl b/P/PETSc/build_tarballs.jl index 2b3fcabeeaa..942fa310590 100644 --- a/P/PETSc/build_tarballs.jl +++ b/P/PETSc/build_tarballs.jl @@ -1,20 +1,21 @@ +# PETSc 3.21.5 with OpenBLAS and static compilations of SuperLU_Dist, SuiteSparse, MUMPS, Hypre, triangle and TetGen on machines that support it using BinaryBuilder, Pkg using Base.BinaryPlatforms const YGGDRASIL_DIR = "../.." include(joinpath(YGGDRASIL_DIR, "platforms", "mpi.jl")) name = "PETSc" -version = v"3.20.5" -petsc_version = v"3.20.5" +version = v"3.21.5" +petsc_version = v"3.21.5" -MPItrampoline_compat_version="5.2.1" +MPItrampoline_compat_version="5.5.0" MicrosoftMPI_compat_version="~10.1.4" MPICH_compat_version="~4.1.2" # Collection of sources required to build PETSc. sources = [ ArchiveSource("https://web.cels.anl.gov/projects/petsc/download/release-snapshots/petsc-$(petsc_version).tar.gz", - "fb4e637758737af910b05f30a785245633916cd0a929b7b6447ad1028da4ea5a"), + "4eb1ec04c1a8988bd524f71f8d7d980dc1853d5be8791c0f19f3c09eef71fdd2"), DirectorySource("./bundled"), ] @@ -27,6 +28,11 @@ apk del cmake cd $WORKSPACE/srcdir/petsc* atomic_patch -p1 $WORKSPACE/srcdir/patches/petsc_name_mangle.patch +# TODO: MPITrampoline embeds the wrong CC. https://github.com/JuliaPackaging/Yggdrasil/issues/7420 +export MPITRAMPOLINE_CC="$(which $CC)" +export MPITRAMPOLINE_CXX="$(which $CXX)" +export MPITRAMPOLINE_FC="$(which $FC)" + if [[ "${target}" == *-mingw* ]]; then # On windows, it compiles fine but we obtain a following runtime error: # @@ -81,7 +87,7 @@ fi atomic_patch -p1 $WORKSPACE/srcdir/patches/mingw-version.patch atomic_patch -p1 $WORKSPACE/srcdir/patches/mpi-constants.patch -atomic_patch -p1 $WORKSPACE/srcdir/patches/sosuffix.patch +atomic_patch -p1 $WORKSPACE/srcdir/patches/sosuffix.patch mkdir $libdir/petsc build_petsc() @@ -105,19 +111,34 @@ build_petsc() # A SuperLU_DIST build is (now) available on most systems, but only works for double precision USE_SUPERLU_DIST=0 - if [ "${1}" == "double" ] && [ "${3}" == "Int64" ]; then + if [ "${1}" == "double" ]; then USE_SUPERLU_DIST=1 fi + if [[ "${target}" == *-mingw* ]]; then + USE_SUPERLU_DIST=0 + fi + + # install suitesparse if available - note that this shipped with julia and therefore linked to specific julia versions + USE_SUITESPARSE=0 + if [ "${1}" == "double" ]; then + USE_SUITESPARSE=1 + fi + if [[ "${target}" == *-mingw* ]]; then + USE_SUITESPARSE=0 + fi # See if we can install MUMPS - USE_STATIC_MUMPS=0 + USE_MUMPS=0 if [[ "${target}" == *-mingw* ]]; then # try static - USE_STATIC_MUMPS=0 + USE_MUMPS=0 elif [ "${1}" == "double" ] && [ "${2}" == "real" ]; then - USE_STATIC_MUMPS=1 + USE_MUMPS=1 else - USE_STATIC_MUMPS=0 + USE_MUMPS=0 + fi + if [[ "${target}" == powerpc64le-linux-* ]] || [[ "${target}" == aarch64-linux-* ]] || [[ "${target}" == arm-linux-* ]]; then + USE_MUMPS=0 fi LIBFLAGS="-L${libdir}" @@ -125,6 +146,23 @@ build_petsc() LIBFLAGS="-L${libdir} -lssp -lmsmpi" fi + # use LBT - to be activated @ a later stage + #if [[ "${target}" == aarch64-apple-* ]]; then + # LIBFLAGS="-L${libdir}" + # # Linking requires the function `__divdc3`, which is implemented in + # # `libclang_rt.osx.a` from LLVM compiler-rt. + # BLAS_LAPACK_LIB="${libdir}/libblastrampoline.${dlext}" + # CLINK_FLAGS="-L${libdir}/darwin -lclang_rt.osx" + #elif [[ "${target}" == *-mingw* ]]; then + # # BLAS_LAPACK_LIB="${libdir}/libblastrampoline-5.${dlext}" + # BLAS_LAPACK_LIB="${libdir}/libopenblas.${dlext}" # LBT doesn't seem to work on windows + # CLINK_FLAGS="" + + #else + # BLAS_LAPACK_LIB="${libdir}/libblastrampoline.${dlext}" + # CLINK_FLAGS="" + #fi + BLAS_LAPACK_LIB="${libdir}/libopenblas.${dlext}" if [ ${DEBUG_FLAG} == 1 ]; then @@ -137,6 +175,12 @@ build_petsc() _FOPTFLAGS='-O3' fi + # hypre + USE_HYPRE=0 + if [ "${1}" == "double" ] && [ "${2}" == "real" ]; then + USE_HYPRE=1 + fi + MPI_CC=mpicc MPI_FC=mpif90 MPI_CXX=mpicxx @@ -150,7 +194,7 @@ build_petsc() MPI_FC=${FC} MPI_CXX=${CXX} USE_SUPERLU_DIST=0 - USE_STATIC_MUMPS=1 + USE_MUMPS=1 elif [[ "${target}" == *-mingw* ]]; then # since we don't use MPI on windows MPI_CC=${CC} @@ -158,14 +202,26 @@ build_petsc() MPI_CXX=${CXX} USE_SUPERLU_DIST=0 USE_SUITESPARSE=0 + USE_HYPRE=0 fi if [[ "${target}" == powerpc64le-linux-* ]] || [[ "${target}" == aarch64-linux-* ]] || [[ "${target}" == arm-linux-* ]]; then - USE_STATIC_MUMPS=0 + USE_MUMPS=0 + fi + + # triangle, tetgen + USE_TRIANGLE=0 + USE_TETGEN=0 + if [ "${1}" == "double" ] ; then + USE_TRIANGLE=1 + USE_TETGEN=1 fi echo "USE_SUPERLU_DIST="$USE_SUPERLU_DIST echo "USE_SUITESPARSE="$USE_SUITESPARSE - echo "USE_STATIC_MUMPS="$USE_STATIC_MUMPS + echo "USE_MUMPS="$USE_MUMPS + echo "USE_HYPRE="$USE_HYPRE + echo "USE_TETGEN="$USE_TETGEN + echo "USE_TRIANGLE="$USE_TRIANGLE echo "1="${1} echo "2="${2} echo "3="${3} @@ -183,7 +239,8 @@ build_petsc() echo "MPI_CXX="$MPI_CXX mkdir $libdir/petsc/${PETSC_CONFIG} - + + # Step 1: build static libraries of external packages (happens during configure) # Note that mpicc etc. should be indicated rather than ${CC} to compile external packages ./configure --prefix=${libdir}/petsc/${PETSC_CONFIG} \ @@ -210,12 +267,19 @@ build_petsc() --with-scalar-type=${2} \ --with-pthread=0 \ --PETSC_ARCH=${target}_${PETSC_CONFIG} \ + --with-scalapack-lib=${libdir}/libscalapack32.${dlext} \ + --with-scalapack-include=${includedir} \ + --download-suitesparse=${USE_SUITESPARSE} \ + --download-suitesparse-shared=0 \ --download-superlu_dist=${USE_SUPERLU_DIST} \ --download-superlu_dist-shared=0 \ - --download-mumps=${USE_STATIC_MUMPS} \ + --download-hypre=${USE_HYPRE} \ + --download-hypre-shared=0 \ + --download-hypre-configure-arguments='--host --build' \ + --download-mumps=${USE_MUMPS} \ --download-mumps-shared=0 \ - --with-scalapack-lib=${libdir}/libscalapack32.${dlext} \ - --with-scalapack-include=${includedir} \ + --download-tetgen=${USE_TETGEN} \ + --download-triangle=${USE_TRIANGLE} \ --SOSUFFIX=${PETSC_CONFIG} \ --with-shared-libraries=1 \ --with-clean=1 @@ -235,7 +299,6 @@ build_petsc() # Remove PETSc.pc because petsc.pc also exists, causing conflicts on case-insensitive file-systems. rm ${libdir}/petsc/${PETSC_CONFIG}/lib/pkgconfig/PETSc.pc - if [ "${1}" == "double" ] && [ "${2}" == "real" ] && [ "${3}" == "Int64" ] && [ "${4}" == "opt" ]; then # Compile examples (to allow testing the installation). @@ -294,6 +357,23 @@ build_petsc() fi + if [ "${1}" == "double" ] && [ "${2}" == "real" ] && [ "${3}" == "Int32" ] && [ "${4}" == "opt" ]; then + + # this is the example that PETSc uses to test the correct installation + # We compile it with debug flags (helpful to catch issues) + workdir=${libdir}/petsc/${PETSC_CONFIG}/share/petsc/examples/src/snes/tutorials/ + make --directory=$workdir PETSC_DIR=${libdir}/petsc/${PETSC_CONFIG} PETSC_ARCH=${target}_${PETSC_CONFIG} ex19 + file=${workdir}/ex19 + if [[ "${target}" == *-mingw* ]]; then + if [[ -f "$file" ]]; then + mv $file ${file}${exeext} + fi + fi + mv ${file}${exeext} ${file}_int32${exeext} + install -Dvm 755 ${workdir}/ex19_int32${exeext} "${bindir}/ex19_int32${exeext}" + + fi + # we don't particularly care about the other examples rm -r ${libdir}/petsc/${PETSC_CONFIG}/share/petsc/examples } @@ -323,9 +403,8 @@ platforms = expand_gfortran_versions(supported_platforms(exclude=[Platform("i686 Platform("armv6l","linux"; libc="musl"), Platform("armv7l","linux"; libc="musl"), Platform("armv7l","linux"; libc="gnu"), - Platform("aarch64","linux"; libc="musl"), - Platform("aarch64","linux"; libc="musl"), - ])) + Platform("aarch64","linux"; libc="musl")])) + # a few, but not all, platforms with libgfortran 3.0.0 are excluded platforms, platform_dependencies = MPI.augment_platforms(platforms; MPItrampoline_compat = MPItrampoline_compat_version, @@ -342,15 +421,21 @@ platforms = filter(p -> !(p["mpi"] == "openmpi" && arch(p) == "armv7l" && libc(p platforms = filter(p -> !(p["mpi"] == "openmpi" && arch(p) == "x86_64" && libc(p) == "musl"), platforms) platforms = filter(p -> !(p["mpi"] == "openmpi" && arch(p) == "i686"), platforms) +# this excludes only aarch64-unknown-freebsd; can be removed once OpenMPI has been built for this platforms. +platforms = filter(p -> !(p["mpi"] == "openmpi" && Sys.isfreebsd(p) && arch(p) == "aarch64"), platforms) + # MPItrampoline -platforms = filter(p -> !(p["mpi"] == "mpitrampoline" && libc(p) == "musl"), platforms) -platforms = filter(p -> !(p["mpi"] == "mpitrampoline" && Sys.isfreebsd(p)), platforms) +platforms = filter(p -> !(p["mpi"] == "mpitrampoline" && libc(p) == "musl" ), platforms) + +# MPICH +platforms = filter(p -> !(p["mpi"] == "mpich" && Sys.isfreebsd(p) && arch(p) == "aarch64"), platforms) # can be removed once MPICH has been built for aarch64-unknown-freebsd products = [ ExecutableProduct("ex4", :ex4) ExecutableProduct("ex42", :ex42) ExecutableProduct("ex19", :ex19) ExecutableProduct("ex19_int64_deb", :ex19_int64_deb) + ExecutableProduct("ex19_int32", :ex19_int32) # Current default build, equivalent to Float64_Real_Int32 LibraryProduct("libpetsc_double_real_Int64", :libpetsc, "\$libdir/petsc/double_real_Int64/lib") diff --git a/P/PETSc/bundled/patches/mpi-constants.patch b/P/PETSc/bundled/patches/mpi-constants.patch index 58f1a67708e..ef59dccabfc 100644 --- a/P/PETSc/bundled/patches/mpi-constants.patch +++ b/P/PETSc/bundled/patches/mpi-constants.patch @@ -1,161 +1,100 @@ diff --git a/src/mat/impls/aij/mpi/superlu_dist/superlu_dist.c b/src/mat/impls/aij/mpi/superlu_dist/superlu_dist.c -index 1361d41..415825e 100644 +index 7b5e24b..3f0e592 100644 --- a/src/mat/impls/aij/mpi/superlu_dist/superlu_dist.c +++ b/src/mat/impls/aij/mpi/superlu_dist/superlu_dist.c -@@ -144,8 +144,9 @@ typedef struct { +@@ -144,7 +144,8 @@ typedef struct { #endif } PetscSuperLU_DIST; -static PetscMPIInt Petsc_Superlu_dist_keyval = MPI_KEYVAL_INVALID; -- -+static PetscMPIInt Petsc_Superlu_dist_keyval; ++PetscMPIInt Petsc_Superlu_dist_keyval; +__attribute__((__constructor__)) static void init_Petsc_Superlu_dist_keyval() { Petsc_Superlu_dist_keyval = MPI_KEYVAL_INVALID; } -+ - PETSC_EXTERN PetscMPIInt MPIAPI Petsc_Superlu_dist_keyval_Delete_Fn(MPI_Comm comm, PetscMPIInt keyval, void *attr_val, void *extra_state) + + PETSC_EXTERN PetscMPIInt MPIAPI Petsc_Superlu_dist_keyval_DeleteFn(MPI_Comm comm, PetscMPIInt keyval, void *attr_val, void *extra_state) + { +diff --git a/src/mat/impls/elemental/matelem.cxx b/src/mat/impls/elemental/matelem.cxx +index f3527c1..0eddd06 100644 +--- a/src/mat/impls/elemental/matelem.cxx ++++ b/src/mat/impls/elemental/matelem.cxx +@@ -14,7 +14,8 @@ static PetscBool ElementalCite = PETSC_FALSE; + The variable Petsc_Elemental_keyval is used to indicate an MPI attribute that + is attached to a communicator, in this case the attribute is a Mat_Elemental_Grid + */ +-static PetscMPIInt Petsc_Elemental_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_Elemental_keyval; ++__attribute__((__constructor__)) static void init_Petsc_Elemental_keyval() { Petsc_Elemental_keyval = MPI_KEYVAL_INVALID; } + + static PetscErrorCode MatView_Elemental(Mat A, PetscViewer viewer) { - PetscSuperLU_DIST *context = (PetscSuperLU_DIST *)attr_val; +diff --git a/src/sys/classes/matlabengine/matlab.c b/src/sys/classes/matlabengine/matlab.c +index 343dd6e..08345df 100644 +--- a/src/sys/classes/matlabengine/matlab.c ++++ b/src/sys/classes/matlabengine/matlab.c +@@ -288,7 +288,9 @@ PetscErrorCode PetscMatlabEngineGet(PetscMatlabEngine mengine, PetscObject obj) + The variable Petsc_Matlab_Engine_keyval is used to indicate an MPI attribute that + is attached to a communicator, in this case the attribute is a PetscMatlabEngine + */ +-static PetscMPIInt Petsc_Matlab_Engine_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_Matlab_Engine_keyval; ++__attribute__((__constructor__)) static void init_Petsc_Matlab_Engine_keyval() { Petsc_Matlab_Engine_keyval = MPI_KEYVAL_INVALID; } ++ + + /*@C + PETSC_MATLAB_ENGINE_ - Creates a MATLAB engine on each process in a communicator. +diff --git a/src/sys/classes/viewer/impls/ams/ams.c b/src/sys/classes/viewer/impls/ams/ams.c +index 0c2bfb8..9e9bb36 100644 +--- a/src/sys/classes/viewer/impls/ams/ams.c ++++ b/src/sys/classes/viewer/impls/ams/ams.c +@@ -6,7 +6,8 @@ + The variable Petsc_Viewer_SAWs_keyval is used to indicate an MPI attribute that + is attached to a communicator, in this case the attribute is a PetscViewer. + */ +-static PetscMPIInt Petsc_Viewer_SAWs_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_Viewer_SAWs_keyval; ++__attribute__((__constructor__)) static void init_Petsc_Viewer_SAWs_keyval() { Petsc_Viewer_SAWs_keyval = MPI_KEYVAL_INVALID; } + + /*@C + PETSC_VIEWER_SAWS_ - Creates a SAWs `PetscViewer` shared by all MPI processes in a communicator. diff --git a/src/sys/classes/viewer/impls/ascii/vcreatea.c b/src/sys/classes/viewer/impls/ascii/vcreatea.c -index 2ce92a6..ebe7461 100644 +index cb3c3d5..58d343e 100644 --- a/src/sys/classes/viewer/impls/ascii/vcreatea.c +++ b/src/sys/classes/viewer/impls/ascii/vcreatea.c -@@ -4,8 +4,9 @@ +@@ -4,7 +4,8 @@ The variable Petsc_Viewer_Stdout_keyval is used to indicate an MPI attribute that is attached to a communicator, in this case the attribute is a PetscViewer. */ -PetscMPIInt Petsc_Viewer_Stdout_keyval = MPI_KEYVAL_INVALID; -- +PetscMPIInt Petsc_Viewer_Stdout_keyval; +__attribute__((__constructor__)) static void init_Petsc_Viewer_Stdout_keyval() { Petsc_Viewer_Stdout_keyval = MPI_KEYVAL_INVALID; } -+ - /*@ - PetscViewerASCIIGetStdout - Creates a `PETSCVIEWERASCII` `PetscViewer` shared by all processors - in a communicator. Error returning version of `PETSC_VIEWER_STDOUT_()` -@@ -89,8 +90,9 @@ PetscViewer PETSC_VIEWER_STDOUT_(MPI_Comm comm) + + /*@C + PETSC_VIEWER_STDOUT_ - Creates a `PETSCVIEWERASCII` `PetscViewer` shared by all MPI processes +@@ -45,7 +46,8 @@ PetscViewer PETSC_VIEWER_STDOUT_(MPI_Comm comm) The variable Petsc_Viewer_Stderr_keyval is used to indicate an MPI attribute that is attached to a communicator, in this case the attribute is a PetscViewer. */ -PetscMPIInt Petsc_Viewer_Stderr_keyval = MPI_KEYVAL_INVALID; -- +PetscMPIInt Petsc_Viewer_Stderr_keyval; +__attribute__((__constructor__)) static void init_Petsc_Viewer_Stderr_keyval() { Petsc_Viewer_Stderr_keyval = MPI_KEYVAL_INVALID; } -+ + /*@ PetscViewerASCIIGetStderr - Creates a `PETSCVIEWERASCII` `PetscViewer` shared by all MPI processes - in a communicator. Error returning version of `PETSC_VIEWER_STDERR_()` -@@ -172,7 +174,8 @@ PetscViewer PETSC_VIEWER_STDERR_(MPI_Comm comm) +@@ -128,7 +130,9 @@ PetscViewer PETSC_VIEWER_STDERR_(MPI_Comm comm) PetscFunctionReturn(viewer); } -PetscMPIInt Petsc_Viewer_keyval = MPI_KEYVAL_INVALID; +PetscMPIInt Petsc_Viewer_keyval; +__attribute__((__constructor__)) static void init_Petsc_Viewer_keyval() { Petsc_Viewer_keyval = MPI_KEYVAL_INVALID; } ++ /* Called with MPI_Comm_free() is called on a communicator that has a viewer as an attribute. The viewer is not actually destroyed because that is managed by PetscObjectDestroyRegisterAll(). PetscViewerASCIIGetStdout() registers the viewer with PetscObjectDestroyRegister() to be destroyed when PetscFinalize() is called. -diff --git a/src/sys/objects/pinit.c b/src/sys/objects/pinit.c -index 6bbeb4d..03037fa 100644 ---- a/src/sys/objects/pinit.c -+++ b/src/sys/objects/pinit.c -@@ -42,22 +42,36 @@ PETSC_INTERN PetscErrorCode PetscSequentialPhaseEnd_Private(MPI_Comm, int); - PETSC_INTERN PetscErrorCode PetscCloseHistoryFile(FILE **); - - /* user may set these BEFORE calling PetscInitialize() */ --MPI_Comm PETSC_COMM_WORLD = MPI_COMM_NULL; --#if PetscDefined(HAVE_MPI_INIT_THREAD) --PetscMPIInt PETSC_MPI_THREAD_REQUIRED = PETSC_DECIDE; --#else --PetscMPIInt PETSC_MPI_THREAD_REQUIRED = MPI_THREAD_SINGLE; --#endif -- --PetscMPIInt Petsc_Counter_keyval = MPI_KEYVAL_INVALID; --PetscMPIInt Petsc_InnerComm_keyval = MPI_KEYVAL_INVALID; --PetscMPIInt Petsc_OuterComm_keyval = MPI_KEYVAL_INVALID; --PetscMPIInt Petsc_ShmComm_keyval = MPI_KEYVAL_INVALID; --PetscMPIInt Petsc_CreationIdx_keyval = MPI_KEYVAL_INVALID; --PetscMPIInt Petsc_Garbage_HMap_keyval = MPI_KEYVAL_INVALID; -- --PetscMPIInt Petsc_SharedWD_keyval = MPI_KEYVAL_INVALID; --PetscMPIInt Petsc_SharedTmp_keyval = MPI_KEYVAL_INVALID; -+MPI_Comm PETSC_COMM_WORLD; -+PetscMPIInt PETSC_MPI_THREAD_REQUIRED; -+ -+PetscMPIInt Petsc_Counter_keyval; -+PetscMPIInt Petsc_InnerComm_keyval; -+PetscMPIInt Petsc_OuterComm_keyval; -+PetscMPIInt Petsc_ShmComm_keyval; -+PetscMPIInt Petsc_CreationIdx_keyval; -+PetscMPIInt Petsc_Garbage_HMap_keyval; -+PetscMPIInt Petsc_SharedWD_keyval; -+PetscMPIInt Petsc_SharedTmp_keyval; -+ -+__attribute__((__constructor__)) static void init_PETSC_COMM_WORLD() -+{ -+ PETSC_COMM_WORLD = MPI_COMM_NULL; -+ #if PetscDefined(HAVE_MPI_INIT_THREAD) -+ PETSC_MPI_THREAD_REQUIRED = MPI_THREAD_FUNNELED; -+ #else -+ PETSC_MPI_THREAD_REQUIRED = 0; -+ #endif -+ -+ Petsc_Counter_keyval = MPI_KEYVAL_INVALID; -+ Petsc_InnerComm_keyval = MPI_KEYVAL_INVALID; -+ Petsc_OuterComm_keyval = MPI_KEYVAL_INVALID; -+ Petsc_ShmComm_keyval = MPI_KEYVAL_INVALID; -+ Petsc_CreationIdx_keyval = MPI_KEYVAL_INVALID; -+ Petsc_Garbage_HMap_keyval = MPI_KEYVAL_INVALID; -+ Petsc_SharedWD_keyval = MPI_KEYVAL_INVALID; -+ Petsc_SharedTmp_keyval = MPI_KEYVAL_INVALID; -+} - - /* - Declare and set all the string names of the PETSc enums -@@ -424,8 +438,9 @@ PETSC_EXTERN PetscMPIInt PetscDataRep_read_conv_fn(void *, MPI_Datatype, PetscMP - PETSC_EXTERN PetscMPIInt PetscDataRep_write_conv_fn(void *, MPI_Datatype, PetscMPIInt, void *, MPI_Offset, void *); - #endif - --PetscMPIInt PETSC_MPI_ERROR_CLASS = MPI_ERR_LASTCODE, PETSC_MPI_ERROR_CODE; -- -+PetscMPIInt PETSC_MPI_ERROR_CLASS,PETSC_MPI_ERROR_CODE; -+__attribute__((__constructor__)) static void init_PETSC_MPI_ERROR_CLASS() { PETSC_MPI_ERROR_CLASS=MPI_ERR_LASTCODE; } -+ - PETSC_INTERN int PetscGlobalArgc; - PETSC_INTERN char **PetscGlobalArgs; - int PetscGlobalArgc = 0; -diff --git a/src/vec/vec/utils/comb.c b/src/vec/vec/utils/comb.c -index 745a0c0..7484a99 100644 ---- a/src/vec/vec/utils/comb.c -+++ b/src/vec/vec/utils/comb.c -@@ -271,8 +271,9 @@ static PetscErrorCode PetscSplitReductionDestroy(PetscSplitReduction *sr) - PetscFunctionReturn(PETSC_SUCCESS); - } - --PetscMPIInt Petsc_Reduction_keyval = MPI_KEYVAL_INVALID; -- -+PetscMPIInt Petsc_Reduction_keyval; -+__attribute__((__constructor__)) static void init_Petsc_Reduction_keyval() { Petsc_Reduction_keyval = MPI_KEYVAL_INVALID; } -+ - /* - Private routine to delete internal storage when a communicator is freed. - This is called by MPI, not by users. -diff --git a/src/sys/objects/optionsyaml.c b/src/sys/objects/optionsyaml.c -index 28ba6f0df9..617c20aeaf 100644 ---- a/src/sys/objects/optionsyaml.c -+++ b/src/sys/objects/optionsyaml.c -@@ -7,7 +7,8 @@ - #include <../src/sys/yaml/include/yaml.h> - #endif - --static MPI_Comm petsc_yaml_comm = MPI_COMM_NULL; /* only used for parallel error handling */ -+static MPI_Comm petsc_yaml_comm; /* only used for parallel error handling */ -+__attribute__((__constructor__)) static void init_petsc_yaml_comm() { petsc_yaml_comm = MPI_COMM_NULL; } - - PETSC_STATIC_INLINE MPI_Comm PetscYAMLGetComm(void) - { diff --git a/src/sys/classes/viewer/impls/binary/binv.c b/src/sys/classes/viewer/impls/binary/binv.c -index 842cc0750e..a4dee6a96d 100644 +index c50e077..89a1db8 100644 --- a/src/sys/classes/viewer/impls/binary/binv.c +++ b/src/sys/classes/viewer/impls/binary/binv.c -@@ -1625,7 +1625,8 @@ PETSC_EXTERN PetscErrorCode PetscViewerCreate_Binary(PetscViewer v) +@@ -1579,7 +1579,8 @@ PETSC_EXTERN PetscErrorCode PetscViewerCreate_Binary(PetscViewer v) The variable Petsc_Viewer_Binary_keyval is used to indicate an MPI attribute that is attached to a communicator, in this case the attribute is a PetscViewer. */ @@ -164,12 +103,12 @@ index 842cc0750e..a4dee6a96d 100644 +__attribute__((__constructor__)) static void init_Petsc_Viewer_Binary_keyval() { Petsc_Viewer_Binary_keyval = MPI_KEYVAL_INVALID; } /*@C - PETSC_VIEWER_BINARY_ - Creates a binary PetscViewer shared by all processors + PETSC_VIEWER_BINARY_ - Creates a `PETSCVIEWERBINARY` `PetscViewer` shared by all processors diff --git a/src/sys/classes/viewer/impls/draw/drawv.c b/src/sys/classes/viewer/impls/draw/drawv.c -index e98ade22ff..8d27934c3e 100644 +index 09f7f94..8c18913 100644 --- a/src/sys/classes/viewer/impls/draw/drawv.c +++ b/src/sys/classes/viewer/impls/draw/drawv.c -@@ -752,7 +752,8 @@ PetscErrorCode PetscViewerDrawGetHold(PetscViewer viewer,PetscBool *hold) +@@ -721,7 +721,8 @@ PetscErrorCode PetscViewerDrawGetHold(PetscViewer viewer, PetscBool *hold) The variable Petsc_Viewer_Draw_keyval is used to indicate an MPI attribute that is attached to a communicator, in this case the attribute is a PetscViewer. */ @@ -178,35 +117,185 @@ index e98ade22ff..8d27934c3e 100644 +__attribute__((__constructor__)) static void init_Petsc_Viewer_Draw_keyval() { Petsc_Viewer_Draw_keyval = MPI_KEYVAL_INVALID; } /*@C - PETSC_VIEWER_DRAW_ - Creates a window PetscViewer shared by all processors + PETSC_VIEWER_DRAW_ - Creates a window `PETSCVIEWERDRAW` `PetscViewer` shared by all processors +diff --git a/src/sys/classes/viewer/impls/hdf5/hdf5v.c b/src/sys/classes/viewer/impls/hdf5/hdf5v.c +index e5b5380..10035dd 100644 +--- a/src/sys/classes/viewer/impls/hdf5/hdf5v.c ++++ b/src/sys/classes/viewer/impls/hdf5/hdf5v.c +@@ -1580,7 +1580,8 @@ static PetscErrorCode PetscViewerHDF5HasAttribute_Internal(PetscViewer viewer, c + The variable Petsc_Viewer_HDF5_keyval is used to indicate an MPI attribute that + is attached to a communicator, in this case the attribute is a PetscViewer. + */ +-PetscMPIInt Petsc_Viewer_HDF5_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_Viewer_HDF5_keyval; ++__attribute__((__constructor__)) static void init_Petsc_Viewer_HDF5_keyval() { Petsc_Viewer_HDF5_keyval = MPI_KEYVAL_INVALID; } + + /*@C + PETSC_VIEWER_HDF5_ - Creates an `PETSCVIEWERHDF5` `PetscViewer` shared by all processors in a communicator. +diff --git a/src/sys/classes/viewer/impls/matlab/vmatlab.c b/src/sys/classes/viewer/impls/matlab/vmatlab.c +index 54e6b1d..6ecbd37 100644 +--- a/src/sys/classes/viewer/impls/matlab/vmatlab.c ++++ b/src/sys/classes/viewer/impls/matlab/vmatlab.c +@@ -238,7 +238,8 @@ PetscErrorCode PetscViewerMatlabOpen(MPI_Comm comm, const char name[], PetscFile + PetscFunctionReturn(PETSC_SUCCESS); + } + +-static PetscMPIInt Petsc_Viewer_Matlab_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_Viewer_Matlab_keyval; ++__attribute__((__constructor__)) static void init_Petsc_Viewer_Matlab_keyval() { Petsc_Viewer_Matlab_keyval = MPI_KEYVAL_INVALID; } + + /*@C + PETSC_VIEWER_MATLAB_ - Creates a `PETSCVIEWERMATLAB` `PetscViewer` shared by all processors diff --git a/src/sys/classes/viewer/impls/socket/send.c b/src/sys/classes/viewer/impls/socket/send.c -index 3f34bb5e10..5a752fdc24 100644 +index 9bcc6fd..710b649 100644 --- a/src/sys/classes/viewer/impls/socket/send.c +++ b/src/sys/classes/viewer/impls/socket/send.c -@@ -464,7 +464,8 @@ PetscErrorCode PetscViewerSocketSetConnection(PetscViewer v,const char machine[ +@@ -463,8 +463,9 @@ PetscErrorCode PetscViewerSocketSetConnection(PetscViewer v, const char machine[ The variable Petsc_Viewer_Socket_keyval is used to indicate an MPI attribute that is attached to a communicator, in this case the attribute is a PetscViewer. */ -PetscMPIInt Petsc_Viewer_Socket_keyval = MPI_KEYVAL_INVALID; +- +PetscMPIInt Petsc_Viewer_Socket_keyval; +__attribute__((__constructor__)) static void init_Petsc_Viewer_Socket_keyval() { Petsc_Viewer_Socket_keyval = MPI_KEYVAL_INVALID; } - ++ /*@C - PETSC_VIEWER_SOCKET_ - Creates a socket viewer shared by all processors in a communicator. + PETSC_VIEWER_SOCKET_ - Creates a socket viewer shared by all processors in a communicator. + +diff --git a/src/sys/objects/optionsyaml.c b/src/sys/objects/optionsyaml.c +index 7556dc1..6c16875 100644 +--- a/src/sys/objects/optionsyaml.c ++++ b/src/sys/objects/optionsyaml.c +@@ -10,7 +10,8 @@ + PETSC_INTERN PetscErrorCode PetscOptionsSetValue_Private(PetscOptions, const char[], const char[], int *, PetscOptionSource); + PETSC_INTERN PetscErrorCode PetscOptionsInsertStringYAML_Private(PetscOptions, const char[], PetscOptionSource); + +-static MPI_Comm petsc_yaml_comm = MPI_COMM_NULL; /* only used for parallel error handling */ ++static MPI_Comm petsc_yaml_comm; /* only used for parallel error handling */ ++__attribute__((__constructor__)) static void init_petsc_yaml_comm() { petsc_yaml_comm = MPI_COMM_NULL; } + + static inline MPI_Comm PetscYAMLGetComm(void) + { diff --git a/src/sys/utils/mpiu.c b/src/sys/utils/mpiu.c -index a28ea3dc51..15247372d9 100644 +index 93290f4..e63ecec 100644 --- a/src/sys/utils/mpiu.c +++ b/src/sys/utils/mpiu.c -@@ -52,7 +52,8 @@ PETSC_INTERN PetscErrorCode PetscSequentialPhaseEnd_Private(MPI_Comm comm,int ng +@@ -41,7 +41,9 @@ PETSC_INTERN PetscErrorCode PetscSequentialPhaseEnd_Private(MPI_Comm comm, int n The variable Petsc_Seq_keyval is used to indicate an MPI attribute that is attached to a communicator that manages the sequential phase code below. */ -PetscMPIInt Petsc_Seq_keyval = MPI_KEYVAL_INVALID; +PetscMPIInt Petsc_Seq_keyval; +__attribute__((__constructor__)) static void init_Petsc_Seq_keyval() { Petsc_Seq_keyval = MPI_KEYVAL_INVALID; } ++ /*@ - PetscSequentialPhaseBegin - Begins a sequential section of code. + PetscSequentialPhaseBegin - Begins a sequential section of code. +diff --git a/src/vec/vec/impls/shared/shvec.c b/src/vec/vec/impls/shared/shvec.c +index e25c5d8..a45bdbc 100644 +--- a/src/vec/vec/impls/shared/shvec.c ++++ b/src/vec/vec/impls/shared/shvec.c +@@ -69,7 +69,8 @@ PETSC_EXTERN PetscErrorCode VecCreate_Shared(Vec vv) + #include + #include + +-static PetscMPIInt Petsc_ShmComm_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_ShmComm_keyval; ++__attribute__((__constructor__)) static void init_Petsc_ShmComm_keyval() { Petsc_ShmComm_keyval = MPI_KEYVAL_INVALID; } + + /* + Private routine to delete internal storage when a communicator is freed. +diff --git a/src/vec/vec/utils/comb.c b/src/vec/vec/utils/comb.c +index 67335d4..ecc67d9 100644 +--- a/src/vec/vec/utils/comb.c ++++ b/src/vec/vec/utils/comb.c +@@ -272,7 +272,8 @@ static PetscErrorCode PetscSplitReductionDestroy(PetscSplitReduction *sr) + PetscFunctionReturn(PETSC_SUCCESS); + } + +-PetscMPIInt Petsc_Reduction_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_Reduction_keyval; ++__attribute__((__constructor__)) static void init_Petsc_Reduction_keyval() { Petsc_Reduction_keyval = MPI_KEYVAL_INVALID; } + + /* + Private routine to delete internal storage when a communicator is freed. +diff --git a/src/sys/objects/pinit.c b/src/sys/objects/pinit.c +index 6867c8a..feb5f7e 100644 +--- a/src/sys/objects/pinit.c ++++ b/src/sys/objects/pinit.c +@@ -42,22 +42,51 @@ PETSC_INTERN PetscErrorCode PetscSequentialPhaseEnd_Private(MPI_Comm, int); + PETSC_INTERN PetscErrorCode PetscCloseHistoryFile(FILE **); + + /* user may set these BEFORE calling PetscInitialize() */ +-MPI_Comm PETSC_COMM_WORLD = MPI_COMM_NULL; ++//MPI_Comm PETSC_COMM_WORLD = MPI_COMM_NULL; ++MPI_Comm PETSC_COMM_WORLD; ++__attribute__((__constructor__)) static void init_PETSC_COMM_WORLD() { PETSC_COMM_WORLD = MPI_COMM_NULL; } ++ ++PetscMPIInt PETSC_MPI_THREAD_REQUIRED; + #if PetscDefined(HAVE_MPI_INIT_THREAD) +-PetscMPIInt PETSC_MPI_THREAD_REQUIRED = PETSC_DECIDE; ++//PetscMPIInt PETSC_MPI_THREAD_REQUIRED = PETSC_DECIDE; ++__attribute__((__constructor__)) static void init_PETSC_MPI_THREAD_REQUIRED() { PETSC_MPI_THREAD_REQUIRED = PETSC_DECIDE; } + #else +-PetscMPIInt PETSC_MPI_THREAD_REQUIRED = MPI_THREAD_SINGLE; ++//PetscMPIInt PETSC_MPI_THREAD_REQUIRED = MPI_THREAD_SINGLE; ++__attribute__((__constructor__)) static void init_PETSC_MPI_THREAD_REQUIRED() { PETSC_MPI_THREAD_REQUIRED = MPI_THREAD_SINGLE; } + #endif + +-PetscMPIInt Petsc_Counter_keyval = MPI_KEYVAL_INVALID; +-PetscMPIInt Petsc_InnerComm_keyval = MPI_KEYVAL_INVALID; +-PetscMPIInt Petsc_OuterComm_keyval = MPI_KEYVAL_INVALID; +-PetscMPIInt Petsc_ShmComm_keyval = MPI_KEYVAL_INVALID; +-PetscMPIInt Petsc_CreationIdx_keyval = MPI_KEYVAL_INVALID; +-PetscMPIInt Petsc_Garbage_HMap_keyval = MPI_KEYVAL_INVALID; ++//PetscMPIInt Petsc_Counter_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_Counter_keyval; ++__attribute__((__constructor__)) static void init_Petsc_Counter_keyval() { Petsc_Counter_keyval = MPI_KEYVAL_INVALID; } ++ ++//PetscMPIInt Petsc_InnerComm_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_InnerComm_keyval; ++__attribute__((__constructor__)) static void init_Petsc_InnerComm_keyval() { Petsc_InnerComm_keyval = MPI_KEYVAL_INVALID; } ++ ++//PetscMPIInt Petsc_OuterComm_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_OuterComm_keyval; ++__attribute__((__constructor__)) static void init_Petsc_OuterComm_keyval() { Petsc_OuterComm_keyval = MPI_KEYVAL_INVALID; } ++ ++//PetscMPIInt Petsc_ShmComm_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_ShmComm_keyval; ++__attribute__((__constructor__)) static void init_Petsc_ShmComm_keyval() { Petsc_ShmComm_keyval = MPI_KEYVAL_INVALID; } ++ ++//PetscMPIInt Petsc_CreationIdx_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_CreationIdx_keyval; ++__attribute__((__constructor__)) static void init_Petsc_CreationIdx_keyval() { Petsc_CreationIdx_keyval = MPI_KEYVAL_INVALID; } ++ ++//PetscMPIInt Petsc_Garbage_HMap_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_Garbage_HMap_keyval; ++__attribute__((__constructor__)) static void init_Petsc_Garbage_HMap_keyval() { Petsc_Garbage_HMap_keyval = MPI_KEYVAL_INVALID; } ++ ++//PetscMPIInt Petsc_SharedWD_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_SharedWD_keyval; ++__attribute__((__constructor__)) static void init_Petsc_SharedWD_keyval() { Petsc_SharedWD_keyval = MPI_KEYVAL_INVALID; } ++ ++//PetscMPIInt Petsc_SharedTmp_keyval = MPI_KEYVAL_INVALID; ++PetscMPIInt Petsc_SharedTmp_keyval; ++__attribute__((__constructor__)) static void init_Petsc_SharedTmp_keyval() { Petsc_SharedTmp_keyval = MPI_KEYVAL_INVALID; } + +-PetscMPIInt Petsc_SharedWD_keyval = MPI_KEYVAL_INVALID; +-PetscMPIInt Petsc_SharedTmp_keyval = MPI_KEYVAL_INVALID; + + /* + Declare and set all the string names of the PETSc enums +@@ -426,7 +455,8 @@ PETSC_EXTERN PetscMPIInt PetscDataRep_read_conv_fn(void *, MPI_Datatype, PetscMP + PETSC_EXTERN PetscMPIInt PetscDataRep_write_conv_fn(void *, MPI_Datatype, PetscMPIInt, void *, MPI_Offset, void *); + #endif + +-PetscMPIInt PETSC_MPI_ERROR_CLASS = MPI_ERR_LASTCODE, PETSC_MPI_ERROR_CODE; ++PetscMPIInt PETSC_MPI_ERROR_CLASS,PETSC_MPI_ERROR_CODE; ++__attribute__((__constructor__)) static void init_PETSC_MPI_ERROR_CLASS() { PETSC_MPI_ERROR_CLASS=MPI_ERR_LASTCODE; } + + PETSC_INTERN int PetscGlobalArgc; + PETSC_INTERN char **PetscGlobalArgs; diff --git a/src/mat/impls/scalapack/matscalapack.c b/src/mat/impls/scalapack/matscalapack.c index 9422402d2e..e15cea0ba6 100644 --- a/src/mat/impls/scalapack/matscalapack.c @@ -220,4 +309,4 @@ index 9422402d2e..e15cea0ba6 100644 +__attribute__((__constructor__)) static void init_Petsc_ScaLAPACK_keyval() { Petsc_ScaLAPACK_keyval = MPI_KEYVAL_INVALID; } static PetscErrorCode Petsc_ScaLAPACK_keyval_free(void) - { \ No newline at end of file + {