CMake does not find PETSc

The Build directory is removed before compiling preCICE every time. PETSC_DIR and PETSC_ARCH are specified in ~/.bashrc beforehand. I am not sure if this is the reason why FindPETSC locates Pestc. Please find below the new CMakeError.log, which I just repeated the installation procedure with removing the Build directory.

CMakeError.log (15.1 KB)

Sorry that I don’t understand what you meant. Which MPI, Intel MPI or OpenMPI, should be used? How to fix the problem? I just tried OpenMPI. It does not work as well… See the configure commands for compiling Petsc with IntelMPI, which is the same as I showed before, and with OpenMPI. When I reinstalled Petsc, the old directory of Petsc was deleted firstly.

  1. IntelMPI
    sudo ./configure --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich -download-fblaslapack --prefix=/scratch/hd/sw/petsc-3.6.4

  2. OpenMPI
    sudo ./configure --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-openmpi -download-fblaslapack --prefix=/scratch/hd/sw/petsc-3.6.4

The error information for preCICE when OpenMPI is used for Petsc:

– Found MPI_CXX: /home/hd/local/bin/mpicxx (found version “3.0”) **
– Found MPI: TRUE (found version “3.0”) **
CMake Error at /usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
** PETSc could not be found. Be sure to set PETSC_DIR and PETSC_ARCH.

** (missing: PETSC_INCLUDES PETSC_LIBRARIES PETSC_EXECUTABLE_RUNS) (Required

** is at least version “3.6”)**
Call Stack (most recent call first):
** /usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)**
** cmake/modules/FindPETSc.cmake:345 (find_package_handle_standard_args)**
** CMakeLists.txt:148 (find_package)**

– Configuring incomplete, errors occurred!
See also “/scratch/hd/sw/precice-develop/build/CMakeFiles/CMakeOutput.log”.

You have to use a single MPI implementation consistently throughout your software stack.
Thus, if you build PETSc with OpenMPI, then you have to build preCICE with OpenMPI too.


This in fact installs PETSc with a custom installation of MPICH (--download-mpich), not Intel MPI.
As far as I understand, you would then have to use the compiler wrapper of the downloaded MPI to compile preCICE (as well as your adapters and solvers if they need to link to preCICE).

Furthermore, sudo may clean your environment variables which can lead to problems. Use the -E flag to preserve the environment. That said, I highly recommend you not to run sudo unless absolutely necessary ( not for configuring and compiling software ).


My recommendation

Please execute the below steps in a single terminal session to preserve the environment.
If everything works smoothly, then you can add them to your ~/.bashrc to make the changes persistent.
This assumes that you have an MPI implementation installed on your system.

1) Setup your environment

export PETSC_DIR=[choose a directory you have write access to]
export PETSC_ARCH=arch-linux2-c-debug
export CXX=[path to your C++ MPI  compiler wrapper]
export CC=[path to your C MPI compiler wrapper]

2) Install PETSc

Extract the sources or clone the git repository to the directory PETSC_DIR.

cd $PETSC_DIR
./configure --with-64-bit-indices
make -j `nproc` all test

3) Install preCICE

cd path/to/preCICE
mkdir build && cd build
cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Debug ..
make -j `nproc` all
make test

Please keep us informed about problems during the process.

@HDY Hi, do you have an update on the issue?

@fsimonis, sorry for the late response. The installation still does not work. I am a bit busy recently, so have no time to summarize the error information. I will come back to you soon.

@fsimonis

I followed exactly the steps that you mentioned except for Step 3, where cmake is added with "-DCMAKE_CXX_COMPILER=mpicxx ". The problem is the same as before.

Besides Step 1 is set with
export PETSC_DIR=/scratch/hd/sw/petsc-3.6.4
export PETSC_ARCH=arch-linux2-c-debug
export CXX=/home/hd/local/bin/mpicxx
export CC=/usr/bin/cc

CmakeError.log and CmakeOutput.log can be downloaded from the links below.

CMakeOutput.log (35.1 KB) CMakeError.log (7.5 KB)

@fsimonis, another update. I also tried openmpi. The problem still exists.

export CXX=/usr/bin/mpicxx.openmpi
export CC=/usr/bin/mpiCC.openmpi
cd $PETSC_DIR
./configure --with-64-bit-indices
make -j 4 all test
cd $preCICE-path
mkdir build && cd build
cmake -DCMAKE_CXX_COMPILER=mpicxx.openmpi -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Debug …

Besides, I am unsure CC path should be set by cc, mpiCC, or mpicc. I tested all three options.

@HDY Thank you very much!
I had a look at the attached logs and I am really puzzled as the test code used by FindPETSc compiles and links to the expected libraries but fails to run.

Can you try to compile, link and run the example manually?
The exact commands are listed at the very bottom of the CMakeError.log.

static const char help[] = "PETSc test program.";
#include <petscts.h>
int main(int argc,char *argv[]) {
  PetscErrorCode ierr;
  TS ts; 
  ierr = PetscInitialize(&argc,&argv,0,help);CHKERRQ(ierr); 
  ierr = TSCreate(PETSC_COMM_WORLD,&ts);CHKERRQ(ierr); 
  ierr = TSSetFromOptions(ts);CHKERRQ(ierr); 
  ierr = TSDestroy(&ts);CHKERRQ(ierr); 
  ierr = PetscFinalize();CHKERRQ(ierr); 
  return 0;
}

Hello,

There are not the directories: CMakeFiles/cmTC_a93ce.dir, CMakeFiles/cmTC_15772.dir, and CMakeFiles/cmTC_e6fe7.dir.

I created one of the above directories, put the test program in src.cxx in this directory, but have no idea how to create link.txt shown in the CMakeError.log

Hi,

there is no need to recreate the folder structure etc.

You can simply put the code from above into a file example.cpp.

Then you can compile example.cpp to example.o using:

/home/hd/local/bin/mpicxx   -I/scratch/hd/sw/petsc-3.6.4/include -I/scratch/hd/sw/petsc-3.6.4/arch-linux2-c-debug/include -I/home/hd/local/include -o example.o -c example.cpp

Followed by linking example.o into the executable example using:

home/hd/local/bin/mpicxx   -rdynamic example.o  -o example -Wl,-rpath,/scratch/hd/sw/petsc-3.6.4/arch-linux2-c-debug/lib /scratch/hd/sw/petsc-3.6.4/arch-linux2-c-debug/lib/libpetsc.so /usr/lib/x86_64-linux-gnu/liblapack.so /usr/lib/x86_64-linux-gnu/libblas.so /usr/lib/x86_64-linux-gnu/libX11.so /usr/lib/x86_64-linux-gnu/libhwloc.so /home/hd/local/lib/libmpi_usempif08.so /home/hd/local/lib/libmpi_usempi_ignore_tkr.so /home/hd/local/lib/libmpi_mpifh.so /usr/lib/gcc/x86_64-linux-gnu/8/libgfortran.so /usr/lib/gcc/x86_64-linux-gnu/8/libquadmath.so -lm /home/hd/local/lib/libmpi_cxx.so /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so /home/hd/local/lib/libmpi.so -lgcc_s /usr/lib/x86_64-linux-gnu/libpthread.so /usr/lib/x86_64-linux-gnu/libdl.so

Finally, you can run the executable using:

./example

@HDY do you have any news regarding this issue? Did you find any solution?

As there has not been an update from @HDY for quite a while I mark this thread as solved.