0

I have a very basic program using PETSC

 #include "PETSC/petsc.h"
 #include "PETSC/petscsys.h"
 #include "PETSC/petscmat.h"

 int main(int argc, char *argv[]) {
     PetscMPIInt    rank,size;
     PetscInitialize(&argc,&argv,0,0);
     MPI_Comm_size(PETSC_COMM_WORLD,&size);
     MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
     PetscPrintf(PETSC_COMM_WORLD,"Number of processors = %d, rank = %d\n",size,rank);
     PetscSynchronizedPrintf(PETSC_COMM_WORLD,"synchronized rank = %d\n",rank);

     MPI_Barrier(PETSC_COMM_WORLD);
 PetscFinalize();
     return 0;
 }

However, I got undefined reference errors to PETSC_COMM_WORLD, PetscInitialize and other junk, when I tried to compile using mpic++

I am now trying to use build and cmake. This is my attempt at a CMakeLists

 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

 PROJECT(checkMPI)

 SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-modules")

 set(PETSC_ARCH linux-gnu)
 set(PETSC_DIR l${PROJECT_SOURCE_DIR}/third-party/petsc)

 FIND_PACKAGE(PETSc REQUIRED)

 INCLUDE_DIRECTORIES(${PETSC_INCLUDES})
 ADD_DEFINITIONS(${PETSC_DEFINITIONS})

 ADD_EXECUTABLE(checkMPI checkMPI.cpp)

 TARGET_LINK_LIBRARIES(checkMPI ${PETSC_LIBRARIES})

In addition, I have a directory cmake-modules containing the cmake-modules for PETSc

However, when I try to generate the makefile by typing ccmake .. and then c, I get the output

CMake Error at cmake-modules/FindPETSc.cmake:127 (message):
   The pair PETSC_DIR=l/directory/HPC/third-party/petsc
   PETSC_ARCH=linux-gnu do not specify a valid PETSc installation
 Call Stack (most recent call first):
   CMakeLists.txt:10 (FIND_PACKAGE)

 CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:108
(message):
   PETSc could not be found.  Be sure to set PETSC_DIR and PETSC_ARCH.
   (missing: PETSC_INCLUDES PETSC_LIBRARIES PETSC_EXECUTABLE_RUNS)
 Call Stack (most recent call first):
   /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:315

Anyone can help?

M K
  • 69
  • 2
  • 8

1 Answers1

1

Based on FindPETSC.cmake it seems that the default options for PETSC_ARCH are:

linux-gnu-c-debug 
linux-gnu-c-opt
x86_64-unknown-linux-gnu 
i386-unknown-linux-gnu

or the one you have used in case of the manual build.

CMake tries to find file ${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h or ${PETSC_DIR}/bmake/${PETSC_ARCH}/petscconf.h.

Peter Petrik
  • 9,701
  • 5
  • 41
  • 65