0

我有一个使用 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;
 }

但是,当我尝试使用 mpic++ 编译时,我得到了未定义的引用错误PETSC_COMM_WORLD和其他垃圾PetscInitialize

我现在正在尝试使用build和cmake。这是我的尝试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})

此外,我有一个cmake-modules包含 PETSc 的 cmake-modules的目录

但是,当我尝试通过键入ccmake ..然后生成生成文件时c,我得到了输出

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

任何人都可以帮忙吗?

4

1 回答 1

1

基于FindPETSC.cmake似乎默认选项PETSC_ARCH是:

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

或者您在手动构建的情况下使用的那个。

CMake 尝试查找文件${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h${PETSC_DIR}/bmake/${PETSC_ARCH}/petscconf.h.

于 2015-05-14T08:03:43.050 回答