- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Ubuntu 13.04 64 位上,我正在尝试使用 CMake 在 PETSc 中构建一个“Hello world”程序。
我有以下程序 solve1.c
(松散地基于 PETSc 示例中的 ex1.c),它解决了一个简单的线性方程组:
/* minimal example of solving a linear equation system in petsc
(in serial) */
/* based on http://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/examples/tutorials/ex1.c.html */
#include <petscksp.h>
#define SIZE 3
int main(int argc,char **argv) {
Vec x,b; /* approx solution, rhs */
Mat A; /* linear system matrix */
KSP ksp; /* linear solver context */
PC pc; /* preconditioner context */
int size;
PetscInt col[3],i;
PetscScalar temp[SIZE];
PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
MPI_Comm_size(PETSC_COMM_WORLD,&size);
if(size!=1) PetscPrintf(PETSC_COMM_WORLD,"warning, %d threads\n",size);
/* create vectors */
VecCreate(PETSC_COMM_WORLD,&x);
VecSetSizes(x,PETSC_DECIDE,SIZE);
VecSetFromOptions(x);
VecDuplicate(x,&b);
temp[0]=14.5; temp[1]=54; temp[2]=0.423;
for(i=0;i<3;i++) VecSetValues(b,1,&i,&temp[i],INSERT_VALUES);
/* need to assemble after setting values! do necessary
message passing etc to propagate matrix to all ranks */
VecAssemblyBegin(b);
VecAssemblyEnd(b);
/* create matrix */
MatCreate(PETSC_COMM_WORLD,&A);
MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,SIZE,SIZE);
MatSetFromOptions(A);
MatSetUp(A);
temp[0]=1; temp[1]=1; temp[2]=1;
col[0]=0; col[1]=1; col[2]=2;
for(i=0;i<3;i++) {
MatSetValues(A,1,&i,3,col,temp,INSERT_VALUES);
temp[i]=0;
}
/* need to assemble matrix for the same reasons as above */
MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
/* linear solver context! */
KSPCreate(PETSC_COMM_WORLD,&ksp);
/* operator is A matrix, also set matrix for preconditioning here */
KSPSetOperators(ksp,A,A,DIFFERENT_NONZERO_PATTERN);
/* get pc context from ksp context */
KSPGetPC(ksp,&pc);
/* set preconditioner type */
PCSetType(pc,PCJACOBI);
KSPSetTolerances(ksp,1e-6,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT);
KSPSetFromOptions(ksp);
/* solve! */
KSPSolve(ksp,b,x);
/* display everything */
MatView(A,PETSC_VIEWER_STDOUT_WORLD);
VecView(b,PETSC_VIEWER_STDOUT_WORLD);
VecView(x,PETSC_VIEWER_STDOUT_WORLD);
KSPView(ksp,PETSC_VIEWER_STDOUT_WORLD);
/* get rid of everything */
KSPDestroy(&ksp);
VecDestroy(&x);
VecDestroy(&b);
PetscFinalize();
return 0;
}
CMakeLists.txt
(基于网络上的各种 PETSc 教程和项目):
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(helloworld)
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-modules")
FIND_PACKAGE(PETSc REQUIRED)
INCLUDE_DIRECTORIES(${PETSC_INCLUDES})
ADD_DEFINITIONS(${PETSC_DEFINITIONS})
ADD_EXECUTABLE(solve1 solve1.c)
TARGET_LINK_LIBRARIES(solve1 ${PETSC_LIBRARIES})
cmake-modules
我有文件的地方
CorrectWindowsPaths.cmake
,
FindPETSc.cmake
,
FindPackageMultipass.cmake
和
ResolveCompilerPaths.cmake
我从
https://github.com/jedbrown/cmake-modules 得到的(按照
PETSc FAQ 的推荐)。
/home/ruben/hello
):
mkdir build
cd build
cmake ..
make
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is GNU 4.8.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- petsc_lib_dir /home/ruben/petsc-3.4.2/arch-linux2-c-debug/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 - Success
-- Minimal PETSc includes and libraries work. This probably means we are building with shared libs.
-- Found PETSc: /home/ruben/petsc-3.4.2/arch-linux2-c-debug/include;/home/ruben/petsc-3.4.2/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ruben/hello/build
make VERBOSE=1
的输出(这不好):
/usr/bin/cmake -H/home/ruben/hello -B/home/ruben/hello/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/ruben/hello/build/CMakeFiles /home/ruben/hello/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/ruben/hello/build'
make -f CMakeFiles/solve1.dir/build.make CMakeFiles/solve1.dir/depend
make[2]: Entering directory `/home/ruben/hello/build'
cd /home/ruben/hello/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/ruben/hello /home/ruben/hello /home/ruben/hello/build /home/ruben/hello/build /home/ruben/hello/build/CMakeFiles/solve1.dir/DependInfo.cmake --color=
Dependee "/home/ruben/hello/build/CMakeFiles/solve1.dir/DependInfo.cmake" is newer than depender "/home/ruben/hello/build/CMakeFiles/solve1.dir/depend.internal".
Dependee "/home/ruben/hello/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/ruben/hello/build/CMakeFiles/solve1.dir/depend.internal".
Scanning dependencies of target solve1
make[2]: Leaving directory `/home/ruben/hello/build'
make -f CMakeFiles/solve1.dir/build.make CMakeFiles/solve1.dir/build
make[2]: Entering directory `/home/ruben/hello/build'
/usr/bin/cmake -E cmake_progress_report /home/ruben/hello/build/CMakeFiles 1
[100%] Building C object CMakeFiles/solve1.dir/solve1.c.o
/usr/bin/cc -D__INSDIR__="" -I/home/ruben/petsc-3.4.2/arch-linux2-c-debug/include -I/home/ruben/petsc-3.4.2/include -o CMakeFiles/solve1.dir/solve1.c.o -c /home/ruben/hello/solve1.c
Linking C executable solve1
/usr/bin/cmake -E cmake_link_script CMakeFiles/solve1.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/solve1.dir/solve1.c.o -o solve1 -rdynamic /home/ruben/petsc-3.4.2/arch-linux2-c-debug/lib/libpetsc.so -Wl,-rpath,/home/ruben/petsc-3.4.2/arch-linux2-c-debug/lib
/usr/bin/ld: CMakeFiles/solve1.dir/solve1.c.o: undefined reference to symbol 'MPI_Comm_size'
/usr/bin/ld: note: 'MPI_Comm_size' is defined in DSO /home/ruben/petsc-3.4.2/arch-linux2-c-debug/lib/libmpich.so.10 so try adding it to the linker command line
/home/ruben/petsc-3.4.2/arch-linux2-c-debug/lib/libmpich.so.10: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make[2]: *** [solve1] Error 1
make[2]: Leaving directory `/home/ruben/hello/build'
make[1]: *** [CMakeFiles/solve1.dir/all] Error 2
make[1]: Leaving directory `/home/ruben/hello/build'
make: *** [all] Error 2
CMakeLists.txt
来自
Dohp项目。不幸的是,我发现这个 CMake 文件很难理解(Dohp 不是一个特别小的例子,它除了 PETSc 之外还有其他依赖项),而且我无法使用这个文件来修复我的链接器错误。
CMakeLists.txt
怎么了我该如何解决? (或者,如果我的 CMake 文件是正确的:我还犯了什么其他错误?)
/home/ruben/petsc-3.4.2/
中,与我想使用的 MPI 一起安装)、CMake 2.8.10.1、gcc 4.8.1,全部在 Intel i7 上的 Ubuntu 13.04 64 位-3930k。我能够使用常规的 makefile 编译和运行上述程序,并且我能够编译和运行我迄今为止尝试过的所有 PETSc 示例。
最佳答案
错误的原因是调用了错误的编译器。从make输出(开启VERBOSE)可以看出/usr/bin/cc
被调用而不是支持 MPI 的编译器 (mpicc)
解决此问题的一种方法是告诉 CMake 使用哪个编译器。更新后的构建说明如下:
mkdir build
cd build
cmake -D CMAKE_C_COMPILER=${PETSC_DIR}/${PETSC_ARCH}/bin/mpicc ..
make
cmake ..
,因为编译器路径现在存储在此构建树的配置文件中。
关于c - 使用 CMake 时链接 PETSc 程序时出现的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19023664/
我有 Windows 7 操作系统。我已按照 PETSc web page 的说明进行操作;在 VS 2005 的命令提示符中,我打开了 cygwin 并使用以下命令安装了 PETSc: ./conf
我对 PETSC 有疑问。我在 matlab 中编写了一段代码,我正在尝试使用 PETSC 库将这段代码翻译成 C++。我正在为多相流编写流体动力学模拟,我正在尝试以一种简单的方式进行与此 matla
我有一个非常初学者的问题,但我现在真的迷路了。我从 PETSc 开始,但我在编译代码时遇到问题。我正在尝试使用我自己的 Makefile,但编译器一直大喊“ undefined reference ”
在没有 Petsc 的情况下,我可以看到哪些文件、哪些函数以及哪些行发生错误并从中传播。使用 Petsc,我总是收到相同的错误消息。 Petsc 中是否有任何我遗漏的标志? 谢谢。 [0]PETSC
我正在尝试在 PETSc 中编写 LU 分解应用程序。我的想法是,程序将打印未因式分解的矩阵,然后打印因式分解的矩阵并计算因式分解本身所花费的时间。 我根据在互联网上找到的少量信息编写了代码(我使用
下面这个问题可能比较容易回答,但是我在网上没有找到任何解决办法。简而言之,我将一些 petsc 函数调用放在一个类中。 下面的方程式求解器脚本没有任何问题: static char help[] =
我正在使用 C 代码进行辐射传输的水力模拟。需要 PETSc,我在本地机器上编译了它。但在编译我的代码时,我收到错误消息:error: '__SDIR__' undeclared(在此函数中首次使用)
我正在尝试创建并打印 MATDENSE PETSc 中的矩阵。我的 MWE 看起来像这样: static char help[] = ""; #include #include int main(
我有一个使用 PETSC 的非常基本的程序 #include "PETSC/petsc.h" #include "PETSC/petscsys.h" #include "PETSC/petscm
我正在尝试在 Windows 7 上安装 PETSc 库以与 Visual Studio Express 2008 一起使用,但到目前为止我没有成功。我用 python、make、diff 安装了 c
我在 Ubuntu 13.04 64 位上,我正在尝试使用 CMake 在 PETSc 中构建一个“Hello world”程序。 我有以下程序 solve1.c (松散地基于 PETSc 示例中的
我想制作PETSc(的子集) Haskell 通过 FFI 接口(interface)提供库,以便对用户隐藏内存和错误管理; 使用如下所示的命令构建带有共享库的 PETSc 3.5.3,测试套件运行成
我正在使用Petsc,我想组合一个分布式Vec,以便每个进程都有一个完整的Vec副本。我有一个最小的示例,它从一个数据数组开始,从中构造一个 MPI Vec,然后尝试使用 VecScatter 来组合
我正在学习在 c/c++ 中使用 petsc,以便在其中使用稀疏矩阵分解函数 (MatICCFactor)。我做的第一步是将玩具矩阵读入 petsc 以创建稀疏矩阵并在对其进行任何操作之前查看该矩阵。
您好,我有一个用 C++ 编写的程序,其中许多函数中有一个或两个正在使用 PETSc。 当我调用这些函数时,这将是使用 PETSc 的正确方法 1) a)change all MPI_COMM_WOR
我正在从事科学计算并为多 CPU 系统开发基于 petsc 的应用程序。 出于调试目的,我想在我自己的电脑上安装那个软件,这是一个运行 Ubuntu (Karmic Koala) 的双核系统。 但我不
我开始使用 PETSc 库来并行求解线性方程组。我已经安装了所有软件包,构建并成功运行了 petsc/src/ksp/ksp/examples/tutorials/文件夹中的示例,例如 ex.c 但是
这里是 hello.cpp。我在 OS X 上。我直接从源代码构建了 PETSc。 #include int main(int argc,char **argv) { Vec x; PetscI
我最近开始学习 PETSc,在尝试完成一些简单任务时遇到了问题。这段代码有什么问题: static char help[] = "Test 2d DMDAs Vecs.\n\n"; #include
在 3.3 中他们有一个 grate news - 在 GPU 上仅使用 PETC SNES 进行 FEM 求解的示例。我是 PETSc 的新手并且有一个问题 - 我需要在 3d 空间中创建一个球体并
我是一名优秀的程序员,十分优秀!