我有一个使用 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
任何人都可以帮忙吗?