Homepage Books Releases Docs Discourse

Compile ogs wit petsc support

Hi!
I’m trying to compile ogs with PETSc support but it always fails somehow.
I’m running cmake … -DOGS_USE_PETSC=ON -DCMAKE_BUILD_TYPE=RELEASE and I’m trying to use the conan version of PETSc.

-- Configuring for PETSc
-- petsc_lib_dir /home/buchwalj/.conan/data/petsc/3.8.3/bilke/testing/build/abd3ca9581f5ec3d6672fa2ee8818b1f09dbb082/install/lib
-- Recognized PETSc install with single library for all packages
-- Performing Test MULTIPASS_TEST_1_petsc_works_minimal
-- Performing Test MULTIPASS_TEST_1_petsc_works_minimal - Failed
-- Performing Test MULTIPASS_TEST_2_petsc_works_allincludes
-- Performing Test MULTIPASS_TEST_2_petsc_works_allincludes - Failed
-- Performing Test MULTIPASS_TEST_3_petsc_works_alllibraries
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
PETSC_LIBRARY_SINGLE
    linked by target "cmTC_9c7c3" in directory /home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp

CMake Error at /usr/share/cmake-3.16/Modules/CheckCSourceRuns.cmake:97 (try_run):
  Failed to configure test project build system.
Call Stack (most recent call first):
  scripts/cmake/jedbrown/FindPackageMultipass.cmake:97 (check_c_source_runs)
  scripts/cmake/jedbrown/FindPETSc.cmake:281 (multipass_source_runs)
  scripts/cmake/jedbrown/FindPETSc.cmake:308 (petsc_test_runs)
  scripts/cmake/Find.cmake:152 (find_package)
  CMakeLists.txt:78 (include)


-- Configuring incomplete, errors occurred!
See also "/home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeOutput.log".
See also "/home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeError.log".

The cmake error log says it is a linking problem:

Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_eb909/fast && /usr/bin/make -f CMakeFiles/cmTC_eb909.dir/build.make CMakeFiles/cmTC_eb909.dir/build
make[1]: Verzeichnis „/home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp“ wird betreten
Building C object CMakeFiles/cmTC_eb909.dir/src.c.o
/usr/bin/cc   -DCMAKE_HAVE_LIBC_PTHREAD   -o CMakeFiles/cmTC_eb909.dir/src.c.o   -c /home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_eb909
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_eb909.dir/link.txt --verbose=1
/usr/bin/cc     -DCMAKE_HAVE_LIBC_PTHREAD       CMakeFiles/cmTC_eb909.dir/src.c.o  -o cmTC_eb909 
/usr/bin/ld: CMakeFiles/cmTC_eb909.dir/src.c.o: in function `main':
src.c:(.text+0x2f): undefined reference to `pthread_create'
/usr/bin/ld: src.c:(.text+0x3b): undefined reference to `pthread_detach'
/usr/bin/ld: src.c:(.text+0x4c): undefined reference to `pthread_join'
collect2: Fehler: ld gab 1 als Ende-Status zurück
make[1]: *** [CMakeFiles/cmTC_eb909.dir/build.make:87: cmTC_eb909] Fehler 1
make[1]: Verzeichnis „/home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp“ wird verlassen
make: *** [Makefile:121: cmTC_eb909/fast] Fehler 2


Source file was:
#include <pthread.h>

void* test_func(void* data)
{
  return data;
}

int main(void)
{
  pthread_t thread;
  pthread_create(&thread, NULL, test_func, NULL);
  pthread_detach(thread);
  pthread_join(thread, NULL);
  pthread_atfork(NULL, NULL, NULL);
  pthread_exit(NULL);

  return 0;
}

Determining if the function sgemm_ exists failed with the following output:
Change Dir: /home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_64577/fast && /usr/bin/make -f CMakeFiles/cmTC_64577.dir/build.make CMakeFiles/cmTC_64577.dir/build
make[1]: Verzeichnis „/home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp“ wird betreten
Building C object CMakeFiles/cmTC_64577.dir/CheckFunctionExists.c.o
/usr/bin/cc   -fopenmp -DCHECK_FUNCTION_EXISTS=sgemm_   -o CMakeFiles/cmTC_64577.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
Linking C executable cmTC_64577
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_64577.dir/link.txt --verbose=1
/usr/bin/cc     -fopenmp -DCHECK_FUNCTION_EXISTS=sgemm_        CMakeFiles/cmTC_64577.dir/CheckFunctionExists.c.o  -o cmTC_64577 
/usr/bin/ld: CMakeFiles/cmTC_64577.dir/CheckFunctionExists.c.o: in function `main':
CheckFunctionExists.c:(.text+0x10): undefined reference to `sgemm_'

I tried to add -pthread to LDFLAGS which brings me one step further:

Linking C executable cmTC_d022f
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_d022f.dir/link.txt --verbose=1
/usr/bin/cc     -fopenmp -DCHECK_FUNCTION_EXISTS=sgemm_  -pthread      CMakeFiles/cmTC_d022f.dir/CheckFunctionExists.c.o  -o cmTC_d022f~
/usr/bin/ld: CMakeFiles/cmTC_d022f.dir/CheckFunctionExists.c.o: in function `main':
CheckFunctionExists.c:(.text+0x10): undefined reference to `sgemm_'
collect2: Fehler: ld gab 1 als Ende-Status zurück
make[1]: *** [CMakeFiles/cmTC_d022f.dir/build.make:87: cmTC_d022f] Fehler 1
make[1]: Verzeichnis „/home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp“ wird verlassen
make: *** [Makefile:121: cmTC_d022f/fast] Fehler 2



Performing C SOURCE FILE Test MULTIPASS_TEST_1_petsc_works_minimal failed with the following compile output:
Change Dir: /home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_ff146/fast && /usr/bin/make -f CMakeFiles/cmTC_ff146.dir/build.make CMakeFiles/cmTC_ff146.dir/build
make[1]: Verzeichnis „/home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp“ wird betreten
Building C object CMakeFiles/cmTC_ff146.dir/src.c.o
/usr/bin/cc  -I/home/buchwalj/.conan/data/petsc/3.8.3/bilke/testing/package/abd3ca9581f5ec3d6672fa2ee8818b1f09dbb082/include  -fopenmp -DMULTIPASS_TEST_1_petsc_works_minimal   -o CMakeFiles/cmTC_ff146.dir/src.c.o   -c /home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp/src.c
In Datei, eingebunden von /home/buchwalj/.conan/data/petsc/3.8.3/bilke/testing/package/abd3ca9581f5ec3d6672fa2ee8818b1f09dbb082/include/petscis.h:7,
                 von /home/buchwalj/.conan/data/petsc/3.8.3/bilke/testing/package/abd3ca9581f5ec3d6672fa2ee8818b1f09dbb082/include/petscvec.h:9,
                 von /home/buchwalj/.conan/data/petsc/3.8.3/bilke/testing/package/abd3ca9581f5ec3d6672fa2ee8818b1f09dbb082/include/petscmat.h:6,
                 von /home/buchwalj/.conan/data/petsc/3.8.3/bilke/testing/package/abd3ca9581f5ec3d6672fa2ee8818b1f09dbb082/include/petscpc.h:6,
                 von /home/buchwalj/.conan/data/petsc/3.8.3/bilke/testing/package/abd3ca9581f5ec3d6672fa2ee8818b1f09dbb082/include/petscksp.h:6,
                 von /home/buchwalj/.conan/data/petsc/3.8.3/bilke/testing/package/abd3ca9581f5ec3d6672fa2ee8818b1f09dbb082/include/petscsnes.h:6,
                 von /home/buchwalj/.conan/data/petsc/3.8.3/bilke/testing/package/abd3ca9581f5ec3d6672fa2ee8818b1f09dbb082/include/petscts.h:7,
                 von /home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp/src.c:3:
/home/buchwalj/.conan/data/petsc/3.8.3/bilke/testing/package/abd3ca9581f5ec3d6672fa2ee8818b1f09dbb082/include/petscsys.h:130:10: schwerwiegender Fehler: mpi.h: Datei oder Verzeichnis nicht gefunden
  130 | #include <mpi.h>
      |          ^~~~~~~
Kompilierung beendet.
make[1]: *** [CMakeFiles/cmTC_ff146.dir/build.make:66: CMakeFiles/cmTC_ff146.dir/src.c.o] Fehler 1
make[1]: Verzeichnis „/home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp“ wird verlassen

So i started cmake using: CC=mpicc CXX=mpic++ LDFLAGS=-pthread cmake … -DOGS_USE_PETSC=ON -DCMAKE_BUILD_TYPE=RELEASE
ending up with a petsc linking problem:

Building C object CMakeFiles/cmTC_402ce.dir/CheckFunctionExists.c.o
/usr/bin/mpicc   -fopenmp -DCHECK_FUNCTION_EXISTS=sgemm_   -o CMakeFiles/cmTC_402ce.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
Linking C executable cmTC_402ce
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_402ce.dir/link.txt --verbose=1
/usr/bin/mpicc     -fopenmp -DCHECK_FUNCTION_EXISTS=sgemm_  -pthread      CMakeFiles/cmTC_402ce.dir/CheckFunctionExists.c.o  -o cmTC_402ce~
/usr/bin/ld: CMakeFiles/cmTC_402ce.dir/CheckFunctionExists.c.o: in function `main':
CheckFunctionExists.c:(.text+0x10): undefined reference to `sgemm_'
collect2: Fehler: ld gab 1 als Ende-Status zurück
make[1]: *** [CMakeFiles/cmTC_402ce.dir/build.make:87: cmTC_402ce] Fehler 1
make[1]: Verzeichnis „/home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp“ wird verlassen
make: *** [Makefile:121: cmTC_402ce/fast] Fehler 2



Performing C SOURCE FILE Test MULTIPASS_TEST_1_petsc_works_minimal failed with the following compile output:
Change Dir: /home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_e1c96/fast && /usr/bin/make -f CMakeFiles/cmTC_e1c96.dir/build.make CMakeFiles/cmTC_e1c96.dir/build
make[1]: Verzeichnis „/home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp“ wird betreten 
Building C object CMakeFiles/cmTC_e1c96.dir/src.c.o
/usr/bin/mpicc  -I/home/buchwalj/.conan/data/petsc/3.8.3/bilke/testing/package/abd3ca9581f5ec3d6672fa2ee8818b1f09dbb082/include  -fopenmp -DMULTIPASS_TEST_1_petsc_works_minimal   -o CMakeFiles/cmTC_e1c96.dir/src.c.o   -c /home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_e1c96
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_e1c96.dir/link.txt --verbose=1
/usr/bin/mpicc     -fopenmp -DMULTIPASS_TEST_1_petsc_works_minimal  -pthread      -rdynamic CMakeFiles/cmTC_e1c96.dir/src.c.o  -o cmTC_e1c96~
/usr/bin/ld: CMakeFiles/cmTC_e1c96.dir/src.c.o: in function `main':
src.c:(.text+0x27): undefined reference to `PetscInitialize'
/usr/bin/ld: src.c:(.text+0x75): undefined reference to `PetscError'
/usr/bin/ld: src.c:(.text+0x85): undefined reference to `PETSC_COMM_WORLD'
/usr/bin/ld: src.c:(.text+0x94): undefined reference to `TSCreate'
/usr/bin/ld: src.c:(.text+0xe2): undefined reference to `PetscError'
/usr/bin/ld: src.c:(.text+0xf7): undefined reference to `TSSetFromOptions'
/usr/bin/ld: src.c:(.text+0x145): undefined reference to `PetscError'
/usr/bin/ld: src.c:(.text+0x15a): undefined reference to `TSDestroy'
/usr/bin/ld: src.c:(.text+0x1a8): undefined reference to `PetscError'
/usr/bin/ld: src.c:(.text+0x1b3): undefined reference to `PetscFinalize'
/usr/bin/ld: src.c:(.text+0x201): undefined reference to `PetscError'
collect2: Fehler: ld gab 1 als Ende-Status zurück
make[1]: *** [CMakeFiles/cmTC_e1c96.dir/build.make:87: cmTC_e1c96] Fehler 1
make[1]: Verzeichnis „/home/buchwalj/github/ogs/build-petsi/CMakeFiles/CMakeTmp“ wird verlassen
make: *** [Makefile:121: cmTC_e1c96/fast] Fehler 2

It really seems that conan isn’t building the petsc libraries correctly.
Building petsc separately and running cmake w/

cmake .. -DCMAKE_BUILT_TYPE=Release -DOGS_USE_PETSC=ON -DOGS_LIB_petsc=System -DPETSC_INCLUDES=path_to_includes -DPETSC_LIBRARIES=path_to_libpetsc.so

solves the problem :slight_smile:

1 Like