FreeFem / FreeFem-sources

FreeFEM source code
https://freefem.org/
Other
755 stars 188 forks source link

New PETSc versions break FF PETSc plugin compilation #219

Closed mbarzegary closed 2 years ago

mbarzegary commented 2 years ago

Hi,

I noticed that a definition of a function is changed in newer versions of PETSc, so building FF with a new version of PETSc doesn't work if one wants to build PETSc separately (which is a mandate in some HPC environments). I did the test on FF 4.10 and PETSc 3.16.5. the only solution is using an older version of PETSc, probably the one that is being downloaded by FF build script (3.16.1).

The reason of the bug is due to the DMPlexCreateFromFile function, defined in petscdmplex.h, called in PETSc-code.hpp:4847. The compilation error is no matching function for call to 'DMPlexCreateFromFile' ... candidate function not viable: requires 5 arguments, but 4 were provided. which is the case since the definition of the function is different in different PETSc versions:

PETSs v3.16.1: PETSC_EXTERN PetscErrorCode DMPlexCreateFromFile(MPI_Comm, const char[], PetscBool, DM *);

PETSs v3.16.5: PETSC_EXTERN PetscErrorCode DMPlexCreateFromFile(MPI_Comm, const char[], const char[], PetscBool, DM *);

(the above error message appeared in building FF using "Cray clang version 11.0.4". the error is probably different in GCC).

prj- commented 2 years ago

FreeFEM master branch and all releases are pinpointed a specific PETSc release, e.g., 4.10 uses PETSc 3.16.1 (https://github.com/FreeFem/FreeFem-sources/blob/v4.10/3rdparty/ff-petsc/Makefile#L151), 4.9 uses PETSc 3.15.0 (https://github.com/FreeFem/FreeFem-sources/blob/v4.9/3rdparty/ff-petsc/Makefile#L151), and so on. There is no guarantee of forward compatibility. Though luck, you tried a new PETSc version which breaks forward compatibility, so you need to use FreeFEM develop branch. The error you are seeing has been spotted first about 5 months ago in https://github.com/FreeFem/FreeFem-sources/commit/8c0e70bd6874b5786eda1d7d402a8d6c082ecd55. BTW, I don't think you are using PETSc 3.16.5, but PETSc 3.016.5, i.e., the main branch of PETSc repository. Because this API change is clearly not in PETSc 3.16.5:

$ git checkout v3.16.5
HEAD is now at 494772aada Increase patchlevel to 3.16.5
$ git grep DMPlexCreateFromFile include/
include/petscdmplex.h:PETSC_EXTERN PetscErrorCode DMPlexCreateFromFile(MPI_Comm, const char[], PetscBool, DM *);
$ git checkout main   
Previous HEAD position was 494772aada Increase patchlevel to 3.16.5
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
$ git grep DMPlexCreateFromFile include/
include/petscdmplex.h:PETSC_EXTERN PetscErrorCode DMPlexCreateFromFile(MPI_Comm, const char[], const char[], PetscBool, DM *);
mbarzegary commented 2 years ago

yes, it makes very sense to not guarantee forward compatibility. I just wanted to report that it will be problematic for newer versions, but I didn't check that it's already resolved in the develop branch in https://github.com/FreeFem/FreeFem-sources/commit/8c0e70bd6874b5786eda1d7d402a8d6c082ecd55.

switching back to 3.16.1 solved the problem for me. and you are right, I was using the main branch of PETSc repo, so I thought that it's the latest version, thus 3.16.5, which is apparently not.