meshadaptation / pragmatic

Anisotropic mesh adaptation library
Other
55 stars 18 forks source link

Pragmatic picking up wrong metis installation #120

Open stephankramer opened 5 years ago

stephankramer commented 5 years ago

I'm trying to build pragmatic as part of a petsc build. This is failing because pragmatic's configure picks up my system (/usr/lib) install of metis which conflicts with the one build by petsc. Here's the relevant bit from petsc's configure.log:

              Checking for functions [pragmatic_2d_init] in library ['/home/skramer/firedrake-adapt/src/petsc/arch-linux2-c-debug/lib/libpragmatic.a'] ['/home/skramer/firedrake-adapt/src/petsc/arch-linux2-c-debug/lib/libmetis.a', 'libm.a']
                Pushing language C
Executing: mpicc -c -o /tmp/petsc-IA6IN2/config.libraries/conftest.o -I/tmp/petsc-IA6IN2/config.compilers -I/tmp/petsc-IA6IN2/config.utilities.closure -I/tmp/petsc-IA6IN2/config.setCompilers -I/tmp/petsc-IA6IN2/config.headers -I/tmp/petsc-IA6IN2/config.utilities.cacheDetails -I/tmp/petsc-IA6IN2/config.atomics -I/tmp/petsc-IA6IN2/config.functions -I/tmp/petsc-IA6IN2/config.utilities.featureTestMacros -I/tmp/petsc-IA6IN2/config.utilities.missing -I/tmp/petsc-IA6IN2/PETSc.options.scalarTypes -I/tmp/petsc-IA6IN2/config.types -I/tmp/petsc-IA6IN2/config.packages.MPI -I/tmp/petsc-IA6IN2/config.packages.valgrind -I/tmp/petsc-IA6IN2/config.packages.pthread -I/tmp/petsc-IA6IN2/config.packages.metis -I/tmp/petsc-IA6IN2/config.libraries  -fPIC  -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -fstack-protector -fvisibility=hidden -g3  /tmp/petsc-IA6IN2/config.libraries/conftest.c
Successful compile:
Source:
#include "confdefs.h"
#include "conffix.h"
/* Override any gcc2 internal prototype to avoid an error. */
char pragmatic_2d_init();
static void _check_pragmatic_2d_init() { pragmatic_2d_init(); }

int main() {
_check_pragmatic_2d_init();;
  return 0;
}
                        Pushing language C
                        Popping language C
Executing: mpicc  -o /tmp/petsc-IA6IN2/config.libraries/conftest    -fPIC  -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -fstack-protector -fvisibility=hidden -g3 /tmp/petsc-IA6IN2/config.libraries/conftest.o  -Wl,-rpath,/home/skramer/firedrake-adapt/src/petsc/arch-linux2-c-debug/lib -L/home/skramer/firedrake-adapt/src/petsc/arch-linux2-c-debug/lib -lpragmatic -Wl,-rpath,/home/skramer/firedrake-adapt/src/petsc/arch-linux2-c-debug/lib -L/home/skramer/firedrake-adapt/src/petsc/arch-linux2-c-debug/lib -lmetis -lm -lstdc++ -ldl
Possible ERROR while running linker: exit code 1
stderr:
/usr/bin/ld: gk_cur_jbufs: TLS definition in //usr/lib/x86_64-linux-gnu/libmetis.so.5 section .tdata mismatches non-TLS definition in /home/skramer/firedrake-adapt/src/petsc/arch-linux2-c-debug/lib/libmetis.so section .data
/usr/bin/ld: //usr/lib/x86_64-linux-gnu/libmetis.so.5: error adding symbols: bad value
collect2: error: ld returned 1 exit status

The reason it's picking up /usr/lib/x86_64-linux-gnu/libmetis.so.5 is because of the logic in pragmatic's CMake/Modules/FindMetis.cmake which seems to first check for /usr/local/ and /usr before trying METIS_DIR (as provided by petsc).

taupalosaurus commented 5 years ago

I can't believe this never bit us before, thanks for seeing that. Can you please check PR #121 if it looks like the right fix ?

stephankramer commented 5 years ago

No sorry, doesn't seem to work for me. I don't know much about cmake but I found this to work:

FIND_PATH(METIS_INCLUDE_DIR
  NAMES metis.h
  HINTS ${METIS_DIR}
  PATH_SUFFIXES "include" "include/metis"
  )
message( STATUS ${METIS_INCLUDE_DIR} )

FIND_LIBRARY(METIS_LIBRARY
  NAMES metis
  HINTS ${METIS_DIR}
  PATH_SUFFIXES "lib" "lib/metis"
  )

This is based on what I saw in other packages with a FindMetis.cmake. None of those seem to explicitly add /usr/lib and /usr/local/lib. I don't know if that's because it's not recommended practice, or because cmake looks for these automatically (depending on configuration I presume)?

stephankramer commented 5 years ago

I should clarify "doesn't work for me": it still picks up my system metis in /usr/.

taupalosaurus commented 5 years ago

That looks like what's in the cmake file for eigen, but I don' really understand that... I'll have to read more about Cmake to make sure we're not breaking things for other users, unless @ggorman knows...

taupalosaurus commented 5 years ago

I don't quite understand why your solution works neither why the current one does, after reading the doc: https://cmake.org/cmake/help/v3.0/command/find_path.html

If I read correctly,

  1. Search the paths specified by the PATHS option or in the short-hand version of the command. These are typically hard-coded guesses. I assume PATH can be omitted and these are the current lines, and the lines should be read. I don't understand why the HINT is appropriate there

Conclusion: I don't understand. This has worked on so many platforms... (Of course I can't be sure it has not always picked the wrong metis, which happened to be miraculously compatible).

Are you using a specific version of cmake ? Maybe it's because $ENV{METIS_DIR} is prefixed with ENV ? Or maybe PATHS is missing in out config... I'd love to test these options but it doesn't fail on my machine...