提问人:Flerovium 114 提问时间:9/4/2023 最后编辑:Flerovium 114 更新时间:9/9/2023 访问量:55
使用 OpenACC 链接 CFD 求解器时对GOACC_符号的未定义引用
Undefined references to GOACC_ symbols when linking CFD solver using OpenACC
问:
我正在尝试使用 OPENACC 加速名为 FEST-3D 的内部计算流体动力学求解器。我正在使用 Windows 作为主机的 Ubuntu 22.04 虚拟机(在 VirtualBox 上)。 FEST-3D 具有用 Fortran90 编写的源文件。我在源文件中添加了 OPENACC 指令,并且需要在 FEST3D 的构建目录中运行 cmake 命令,然后运行 make clean 和 make 命令。它应该编译所有文件而不会出错。但是我遇到了一些我无法解决的错误。
我所做的事情和编译器的响应的复制粘贴如下:
abel@Mistborn:~/FEST-3D1$ cd build/
abel@Mistborn:~/FEST-3D1/build$ cmake ..
make cle-- Configuring done
-- Generating done
-- Build files have been written to: /home/abel/FEST-3D1/build
abel@Mistborn:~/FEST-3D1/build$ make clean
abel@Mistborn:~/FEST-3D1/build$ make -j4
Scanning dependencies of target lib
[ 3%] Building Fortran object ../bin/CMakeFiles/lib.dir/global/global_sst.f90.o
[ 3%] Building Fortran object ../bin/CMakeFiles/lib.dir/vartypes.f90.o
[ 3%] Building Fortran object ../bin/CMakeFiles/lib.dir/utils.f90.o
[ 4%] Building Fortran object ../bin/CMakeFiles/lib.dir/global/global_kkl.f90.o
[ 5%] Building Fortran object ../bin/CMakeFiles/lib.dir/global/global_sa.f90.o
[ 7%] Building Fortran object ../bin/CMakeFiles/lib.dir/boundary/copy_bc.f90.o
[ 9%] Building Fortran object ../bin/CMakeFiles/lib.dir/face/state/muscl.f90.o
[ 9%] Building Fortran object ../bin/CMakeFiles/lib.dir/boundary/read_bc.f90.o
[ 10%] Building Fortran object ../bin/CMakeFiles/lib.dir/face/state/ppm.f90.o
[ 11%] Building Fortran object ../bin/CMakeFiles/lib.dir/face/state/weno.f90.o
[ 13%] Building Fortran object ../bin/CMakeFiles/lib.dir/face/state/weno_NM.f90.o
[ 14%] Building Fortran object ../bin/CMakeFiles/lib.dir/face/flux/convective/ausm.f90.o
[ 15%] Building Fortran object ../bin/CMakeFiles/lib.dir/face/flux/convective/ausmUP.f90.o
[ 16%] Building Fortran object ../bin/CMakeFiles/lib.dir/face/flux/convective/ldfss0.f90.o
[ 17%] Building Fortran object ../bin/CMakeFiles/lib.dir/face/flux/convective/slau.f90.o
[ 19%] Building Fortran object ../bin/CMakeFiles/lib.dir/face/flux/convective/van_leer.f90.o
[ 20%] Building Fortran object ../bin/CMakeFiles/lib.dir/mapping.f90.o
[ 21%] Building Fortran object ../bin/CMakeFiles/lib.dir/layout.f90.o
[ 22%] Building Fortran object ../bin/CMakeFiles/lib.dir/read_write/check_output_control.f90.o
[ 23%] Building Fortran object ../bin/CMakeFiles/lib.dir/read_write/read/read.f90.o
[ 25%] Building Fortran object ../bin/CMakeFiles/lib.dir/resnorm.f90.o
[ 26%] Building Fortran object ../bin/CMakeFiles/lib.dir/geometry.f90.o
[ 27%] Building Fortran object ../bin/CMakeFiles/lib.dir/gradients.f90.o
[ 28%] Building Fortran object ../bin/CMakeFiles/lib.dir/read_write/read/read_output_tec.f90.o
[ 29%] Building Fortran object ../bin/CMakeFiles/lib.dir/read_write/read/read_output_vtk.f90.o
[ 30%] Building Fortran object ../bin/CMakeFiles/lib.dir/wall/wall.f90.o
[ 32%] Building Fortran object ../bin/CMakeFiles/lib.dir/wall/wall_dist.f90.o
[ 33%] Building Fortran object ../bin/CMakeFiles/lib.dir/boundary/FT_bc.f90.o
[ 34%] Building Fortran object ../bin/CMakeFiles/lib.dir/boundary/bc.f90.o
[ 35%] Building Fortran object ../bin/CMakeFiles/lib.dir/face/state/face_interpolant.f90.o
[ 36%] Building Fortran object ../bin/CMakeFiles/lib.dir/grid.f90.o
[ 38%] Building Fortran object ../bin/CMakeFiles/lib.dir/interface1.f90.o
[ 39%] Building Fortran object ../bin/CMakeFiles/lib.dir/boundary/bc_primitive.f90.o
[ 40%] Building Fortran object ../bin/CMakeFiles/lib.dir/convergence.f90.o
[ 41%] Building Fortran object ../bin/CMakeFiles/lib.dir/face/flux/convective/ausmP.f90.o
[ 42%] Building Fortran object ../bin/CMakeFiles/lib.dir/read_write/read/read_output.f90.o
[ 44%] Building Fortran object ../bin/CMakeFiles/lib.dir/CC.f90.o
[ 45%] Building Fortran object ../bin/CMakeFiles/lib.dir/boundary/boundary_state_reconstruction.f90.o
[ 46%] Building Fortran object ../bin/CMakeFiles/lib.dir/viscosity.f90.o
[ 47%] Building Fortran object ../bin/CMakeFiles/lib.dir/face/flux/convective/scheme.f90.o
[ 48%] Building Fortran object ../bin/CMakeFiles/lib.dir/state.f90.o
[ 51%] Building Fortran object ../bin/CMakeFiles/lib.dir/forces.f90.o
[ 51%] Building Fortran object ../bin/CMakeFiles/lib.dir/lusgs.f90.o
[ 52%] Building Fortran object ../bin/CMakeFiles/lib.dir/plusgs.f90.o
[ 53%] Building Fortran object ../bin/CMakeFiles/lib.dir/read_write/write/write_output_tec.f90.o
[ 54%] Building Fortran object ../bin/CMakeFiles/lib.dir/read_write/write/write_output_tec_node.f90.o
[ 55%] Building Fortran object ../bin/CMakeFiles/lib.dir/read_write/write/write_output_vtk.f90.o
[ 57%] Building Fortran object ../bin/CMakeFiles/lib.dir/time.f90.o
[ 58%] Building Fortran object ../bin/CMakeFiles/lib.dir/source.f90.o
[ 59%] Building Fortran object ../bin/CMakeFiles/lib.dir/viscous.f90.o
[ 60%] Building Fortran object ../bin/CMakeFiles/lib.dir/read_write/write/write_output.f90.o
[ 61%] Building Fortran object ../bin/CMakeFiles/lib.dir/read_write/write/dump_solution.f90.o
[ 63%] Building Fortran object ../bin/CMakeFiles/lib.dir/update.f90.o
[ 64%] Building Fortran object ../bin/CMakeFiles/lib.dir/solver.f90.o
[ 64%] Built target lib
Scanning dependencies of target FEST3D
Scanning dependencies of target testsuite_fortran
[ 65%] Building Fortran object ../bin/CMakeFiles/FEST3D.dir/main.f90.o
[ 69%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_alloc.f90.o
[ 69%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_layout.f90.o
[ 69%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_mpi.f90.o
[ 70%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_grid.f90.o
[ 71%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_geometry.f90.o
[ 72%] Linking Fortran executable FEST3D
[ 73%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_read.f90.o
[ 75%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_state.f90.o
[ 76%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_gradient.f90.o
[ 77%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_viscosity.f90.o
[ 78%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_first_order.f90.o
[ 79%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_muscl.f90.o
[ 79%] Built target FEST3D
[ 80%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_ppm.f90.o
[ 82%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_weno.f90.o
[ 83%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_weno_NM.f90.o
[ 84%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_ausm.f90.o
[ 85%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_ausmp.f90.o
[ 86%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_ausmUP.f90.o
[ 88%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_slau.f90.o
[ 89%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_ldfss.f90.o
[ 90%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_van_leer.f90.o
[ 91%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_residue.f90.o
[ 92%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_bc.f90.o
[ 94%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_time.f90.o
[ 95%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_convergence.f90.o
[ 96%] Building Fortran object tests/CMakeFiles/testsuite_fortran.dir/test_succeeds_1.f90.o
[ 97%] Linking Fortran static library libtestsuite_fortran.a
[ 97%] Built target testsuite_fortran
[ 98%] Building C object tests/CMakeFiles/testsuite.dir/main.c.o
[100%] Linking C executable testsuite
/usr/bin/ld: libtestsuite_fortran.a(resnorm.f90.o): in function `__resnorm_MOD_find_resnorm':
resnorm.f90:(.text+0x330b): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: resnorm.f90:(.text+0x401e): undefined reference to `GOACC_data_start'
/usr/bin/ld: resnorm.f90:(.text+0x4167): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: resnorm.f90:(.text+0x416c): undefined reference to `GOACC_data_end'
/usr/bin/ld: libtestsuite_fortran.a(mapping.f90.o): in function `__mapping_MOD_read_interface_map':
mapping.f90:(.text+0xb44): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: libtestsuite_fortran.a(geometry.f90.o): in function `__geometry_MOD_allocate_memory':
geometry.f90:(.text+0x244): undefined reference to `GOACC_enter_exit_data'
/usr/bin/ld: geometry.f90:(.text+0x9f0): undefined reference to `GOACC_update'
/usr/bin/ld: libtestsuite_fortran.a(geometry.f90.o): in function `__geometry_MOD_normalize_face_normals':
geometry.f90:(.text+0x1412): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: geometry.f90:(.text+0x158b): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: geometry.f90:(.text+0x1716): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: libtestsuite_fortran.a(geometry.f90.o): in function `__geometry_MOD_compute_face_area_vectors':
geometry.f90:(.text+0xa72e): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: geometry.f90:(.text+0xaa86): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: libtestsuite_fortran.a(geometry.f90.o):geometry.f90:(.text+0xadcc): more undefined references to `GOACC_parallel_keyed' follow
/usr/bin/ld: libtestsuite_fortran.a(gradients.f90.o): in function `__gradients_MOD_apply_gradient_bc_face':
gradients.f90:(.text+0x5680): undefined reference to `GOACC_data_start'
/usr/bin/ld: gradients.f90:(.text+0x5e46): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: gradients.f90:(.text+0x5e4b): undefined reference to `GOACC_data_end'
/usr/bin/ld: libtestsuite_fortran.a(gradients.f90.o): in function `__gradients_MOD_compute_gradient_g':
gradients.f90:(.text+0x67d0): undefined reference to `GOACC_data_start'
/usr/bin/ld: gradients.f90:(.text+0x6b7a): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: gradients.f90:(.text+0x6b7f): undefined reference to `GOACC_data_end'
/usr/bin/ld: gradients.f90:(.text+0x6cef): undefined reference to `GOACC_data_start'
/usr/bin/ld: gradients.f90:(.text+0x71fa): undefined reference to `GOACC_data_start'
/usr/bin/ld: libtestsuite_fortran.a(wall_dist.f90.o): in function `__wall_dist_MOD_read_destroy_nodefile':
wall_dist.f90:(.text+0x928): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: libtestsuite_fortran.a(wall_dist.f90.o): in function `__wall_dist_MOD_find_wall_dist':
wall_dist.f90:(.text+0xd48): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: wall_dist.f90:(.text+0xe89): undefined reference to `GOACC_parallel_keyed'
collect2: error: ld returned 1 exit status
make[2]: *** [tests/CMakeFiles/testsuite.dir/build.make:98: tests/testsuite] Error 1
make[1]: *** [CMakeFiles/Makefile2:225: tests/CMakeFiles/testsuite.dir/all] Error 2
make: *** [Makefile:101: all] Error 2
可以看出,在“ [100%] Linking C executable testsuite ”行之后,编译器返回了错误,我无法解决。提到的 .f90 文件存在于 FEST-3D 的 src 文件夹中。
当我运行 make VERBOSE=1 时,编译器显示的输出如下:
abel@Mistborn:~/FEST-3D1/build$ make VERBOSE=1
/usr/bin/cmake -S/home/abel/FEST-3D1 -B/home/abel/FEST-3D1/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/abel/FEST-3D1/build/CMakeFiles /home/abel/FEST-3D1/build//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/abel/FEST-3D1/build'
make -f ../bin/CMakeFiles/lib.dir/build.make ../bin/CMakeFiles/lib.dir/depend
make[2]: Entering directory '/home/abel/FEST-3D1/build'
cd /home/abel/FEST-3D1/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/abel/FEST-3D1 /home/abel/FEST-3D1/src /home/abel/FEST-3D1/build /home/abel/FEST-3D1/bin /home/abel/FEST-3D1/bin/CMakeFiles/lib.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/abel/FEST-3D1/build'
make -f ../bin/CMakeFiles/lib.dir/build.make ../bin/CMakeFiles/lib.dir/build
make[2]: Entering directory '/home/abel/FEST-3D1/build'
make[2]: Nothing to be done for '../bin/CMakeFiles/lib.dir/build'.
make[2]: Leaving directory '/home/abel/FEST-3D1/build'
[ 64%] Built target lib
make -f ../bin/CMakeFiles/FEST3D.dir/build.make ../bin/CMakeFiles/FEST3D.dir/depend
make[2]: Entering directory '/home/abel/FEST-3D1/build'
cd /home/abel/FEST-3D1/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/abel/FEST-3D1 /home/abel/FEST-3D1/src /home/abel/FEST-3D1/build /home/abel/FEST-3D1/bin /home/abel/FEST-3D1/bin/CMakeFiles/FEST3D.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/abel/FEST-3D1/build'
make -f ../bin/CMakeFiles/FEST3D.dir/build.make ../bin/CMakeFiles/FEST3D.dir/build
make[2]: Entering directory '/home/abel/FEST-3D1/build'
make[2]: Nothing to be done for '../bin/CMakeFiles/FEST3D.dir/build'.
make[2]: Leaving directory '/home/abel/FEST-3D1/build'
[ 66%] Built target FEST3D
make -f tests/CMakeFiles/testsuite_fortran.dir/build.make tests/CMakeFiles/testsuite_fortran.dir/depend
make[2]: Entering directory '/home/abel/FEST-3D1/build'
cd /home/abel/FEST-3D1/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/abel/FEST-3D1 /home/abel/FEST-3D1/tests /home/abel/FEST-3D1/build /home/abel/FEST-3D1/build/tests /home/abel/FEST-3D1/build/tests/CMakeFiles/testsuite_fortran.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/abel/FEST-3D1/build'
make -f tests/CMakeFiles/testsuite_fortran.dir/build.make tests/CMakeFiles/testsuite_fortran.dir/build
make[2]: Entering directory '/home/abel/FEST-3D1/build'
make[2]: Nothing to be done for 'tests/CMakeFiles/testsuite_fortran.dir/build'.
make[2]: Leaving directory '/home/abel/FEST-3D1/build'
[ 97%] Built target testsuite_fortran
make -f tests/CMakeFiles/testsuite.dir/build.make tests/CMakeFiles/testsuite.dir/depend
make[2]: Entering directory '/home/abel/FEST-3D1/build'
cd /home/abel/FEST-3D1/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/abel/FEST-3D1 /home/abel/FEST-3D1/tests /home/abel/FEST-3D1/build /home/abel/FEST-3D1/build/tests /home/abel/FEST-3D1/build/tests/CMakeFiles/testsuite.dir/DependInfo.cmake --color=
Dependencies file "tests/CMakeFiles/testsuite.dir/main.c.o.d" is newer than depends file "/home/abel/FEST-3D1/build/tests/CMakeFiles/testsuite.dir/compiler_depend.internal".
Consolidate compiler generated dependencies of target testsuite
make[2]: Leaving directory '/home/abel/FEST-3D1/build'
make -f tests/CMakeFiles/testsuite.dir/build.make tests/CMakeFiles/testsuite.dir/build
make[2]: Entering directory '/home/abel/FEST-3D1/build'
[ 98%] Linking C executable testsuite
cd /home/abel/FEST-3D1/build/tests && /usr/bin/cmake -E cmake_link_script CMakeFiles/testsuite.dir/link.txt --verbose=1
/usr/bin/cc -O3 -DNDEBUG CMakeFiles/testsuite.dir/main.c.o -o testsuite -L/opt/mpich1/lib libtestsuite_fortran.a -lmpifort -lmpi -lgfortran -lm -lquadmath -lm
/usr/bin/ld: libtestsuite_fortran.a(resnorm.f90.o): in function `__resnorm_MOD_find_resnorm':
resnorm.f90:(.text+0x330b): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: resnorm.f90:(.text+0x401e): undefined reference to `GOACC_data_start'
/usr/bin/ld: resnorm.f90:(.text+0x4167): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: resnorm.f90:(.text+0x416c): undefined reference to `GOACC_data_end'
/usr/bin/ld: libtestsuite_fortran.a(mapping.f90.o): in function `__mapping_MOD_read_interface_map':
mapping.f90:(.text+0xb44): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: libtestsuite_fortran.a(geometry.f90.o): in function `__geometry_MOD_allocate_memory':
geometry.f90:(.text+0x244): undefined reference to `GOACC_enter_exit_data'
/usr/bin/ld: geometry.f90:(.text+0x9f0): undefined reference to `GOACC_update'
/usr/bin/ld: libtestsuite_fortran.a(geometry.f90.o): in function `__geometry_MOD_normalize_face_normals':
geometry.f90:(.text+0x1412): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: geometry.f90:(.text+0x158b): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: geometry.f90:(.text+0x1716): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: libtestsuite_fortran.a(geometry.f90.o): in function `__geometry_MOD_compute_face_area_vectors':
geometry.f90:(.text+0xa72e): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: geometry.f90:(.text+0xaa86): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: libtestsuite_fortran.a(geometry.f90.o):geometry.f90:(.text+0xadcc): more undefined references to `GOACC_parallel_keyed' follow
/usr/bin/ld: libtestsuite_fortran.a(gradients.f90.o): in function `__gradients_MOD_apply_gradient_bc_face':
gradients.f90:(.text+0x5680): undefined reference to `GOACC_data_start'
/usr/bin/ld: gradients.f90:(.text+0x5e46): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: gradients.f90:(.text+0x5e4b): undefined reference to `GOACC_data_end'
/usr/bin/ld: libtestsuite_fortran.a(gradients.f90.o): in function `__gradients_MOD_compute_gradient_g':
gradients.f90:(.text+0x67d0): undefined reference to `GOACC_data_start'
/usr/bin/ld: gradients.f90:(.text+0x6b7a): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: gradients.f90:(.text+0x6b7f): undefined reference to `GOACC_data_end'
/usr/bin/ld: gradients.f90:(.text+0x6cef): undefined reference to `GOACC_data_start'
/usr/bin/ld: gradients.f90:(.text+0x71fa): undefined reference to `GOACC_data_start'
/usr/bin/ld: libtestsuite_fortran.a(wall_dist.f90.o): in function `__wall_dist_MOD_read_destroy_nodefile':
wall_dist.f90:(.text+0x928): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: libtestsuite_fortran.a(wall_dist.f90.o): in function `__wall_dist_MOD_find_wall_dist':
wall_dist.f90:(.text+0xd48): undefined reference to `GOACC_parallel_keyed'
/usr/bin/ld: wall_dist.f90:(.text+0xe89): undefined reference to `GOACC_parallel_keyed'
collect2: error: ld returned 1 exit status
make[2]: *** [tests/CMakeFiles/testsuite.dir/build.make:98: tests/testsuite] Error 1
make[2]: Leaving directory '/home/abel/FEST-3D1/build'
make[1]: *** [CMakeFiles/Makefile2:225: tests/CMakeFiles/testsuite.dir/all] Error 2
make[1]: Leaving directory '/home/abel/FEST-3D1/build'
make: *** [Makefile:101: all] Error 2
cmake 目录中的 SetFortranFlags.cmake 文件的内容如下所示:
######################################################
# Determine and set the Fortran compiler flags we want
######################################################
####################################################################
# Make sure that the default build type is RELEASE if not specified.
####################################################################
INCLUDE(${CMAKE_MODULE_PATH}/SetCompileFlag.cmake)
# Make sure the build type is uppercase
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT)
IF(BT STREQUAL "RELEASE")
SET(CMAKE_BUILD_TYPE RELEASE CACHE STRING
"Choose the type of build, options are DEBUG, RELEASE, or TESTING."
FORCE)
ELSEIF(BT STREQUAL "DEBUG")
SET (CMAKE_BUILD_TYPE DEBUG CACHE STRING
"Choose the type of build, options are DEBUG, RELEASE, or TESTING."
FORCE)
ELSEIF(BT STREQUAL "TESTING")
SET (CMAKE_BUILD_TYPE TESTING CACHE STRING
"Choose the type of build, options are DEBUG, RELEASE, or TESTING."
FORCE)
ELSEIF(NOT BT)
SET(CMAKE_BUILD_TYPE RELEASE CACHE STRING
"Choose the type of build, options are DEBUG, RELEASE, or TESTING."
FORCE)
MESSAGE(STATUS "CMAKE_BUILD_TYPE not given, defaulting to RELEASE")
ELSE()
MESSAGE(FATAL_ERROR "CMAKE_BUILD_TYPE not valid, choices are DEBUG, RELEASE, or TESTING")
ENDIF(BT STREQUAL "RELEASE")
#########################################################
# If the compiler flags have already been set, return now
#########################################################
IF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fortran_FLAGS_DEBUG)
RETURN ()
ENDIF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fortran_FLAGS_DEBUG)
########################################################################
# Determine the appropriate flags for this compiler for each build type.
# For each option type, a list of possible flags is given that work
# for various compilers. The first flag that works is chosen.
# If none of the flags work, nothing is added (unless the REQUIRED
# flag is given in the call). This way unknown compiles are supported.
#######################################################################
#####################
### GENERAL FLAGS ###
#####################
## Orignal intent: Don't add underscores in symbols for C-compatability
## However, this following flag is not being used because
## of incomptibilty issue created for MacOSX
#SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}"
# Fortran "-fno-underscoring")
# There is some bug where -march=native doesn't work on Mac
IF(APPLE)
SET(GNUNATIVE "-mtune=native")
ELSE()
SET(GNUNATIVE "-march=native")
ENDIF()
# Optimize for the host's architecture
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}"
Fortran "-xHost" # Intel
"/QxHost" # Intel Windows
${GNUNATIVE} # GNU
"-ta=host" # Portland Group
)
# preprocessor
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}"
Fortran "-cpp" Intel # Intel/GNU
)
# double precision
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}"
Fortran "-r8" # Intel
"-fdefault-real-8" # GNU
)
# Set Free format
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}"
Fortran "-ffree-line-length-256" #GNU
"-extend_soruce" #Intel
)
# fpic
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}"
Fortran "-fPIC" Intel # Intel/GNU
)
###################
### DEBUG FLAGS ###
###################
# NOTE: debugging symbols (-g or /debug:full) are already on by default
# Disable optimizations
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}"
Fortran REQUIRED "-O0" # All compilers not on Windows
"/Od" # Intel Windows
)
# Turn on all warnings
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}"
Fortran "-warn all" # Intel
"/warn:all" # Intel Windows
"-Wall" # GNU
# Portland Group (on by default)
)
# Traceback
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}"
Fortran "-traceback" # Intel/Portland Group
"/traceback" # Intel Windows
"-fbacktrace" # GNU (gfortran)
"-ftrace=full" # GNU (g95)
)
# Check array bounds
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}"
Fortran "-check all" # Intel
"/check:bounds" # Intel Windows
"-fcheck=bounds" # GNU (New style)
"-fbounds-check" # GNU (Old style)
"-Mbounds" # Portland Group
)
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}"
Fortran "-I_MPI_HYDRA_DEBUG=1" #intel
)
#####################
### TESTING FLAGS ###
#####################
# Optimizations
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_TESTING "${CMAKE_Fortran_FLAGS_TESTING}"
Fortran REQUIRED "-O2" # All compilers not on Windows
"/O2" # Intel Windows
)
#####################
### RELEASE FLAGS ###
#####################
# NOTE: agressive optimizations (-O3) are already turned on by default
# Unroll loops
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-funroll-loops" # GNU
"-unroll" # Intel
"/unroll" # Intel Windows
"-Munroll" # Portland Group
)
# Inline functions
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-inline" # Intel
"/Qinline" # Intel Windows
"-finline-functions" # GNU
"-Minline" # Portland Group
)
# Single-file optimizations
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-ip" # Intel
"/Qip" # Intel Windows
)
# Add -fopenacc flag
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-fopenacc"
)
在这里,以“# Add -fopenacc flag”开头的最后一部分是我添加的。这有什么错误吗?还是我应该在其他地方添加标志?
如果有人能帮助我解决这个问题,那将非常有帮助,因为我对 OPENACC 很陌生。如果需要更多信息,请询问并提供。 提前致谢。
答:
0赞
Patrick
12/15/2023
#1
我认为您还需要在链接时添加 -fopenacc 标志,以允许您的编译器使用正确的库调用 ld。
评论
1赞
Vladimir F Героям слава
12/15/2023
是的,这在评论中很清楚,在提问者在上一个问题中得到的上一个答案中。开放的问题是,如何在他们的 CMake 配置中做到这一点。不幸的是,OP 从未透露他们当前使用的相关配置文件。
评论
make VERBOSE=1
make VERBOSE=1