【问题标题】:MPI + Open MP Hybrid InitializationMPI + Open MP 混合初始化
【发布时间】:2020-04-25 21:25:19
【问题描述】:

我正在使用带有 CLion IDE 的 Mac OS,我的任务是使用两个并行库(Open MP 和 MPI)。

问题是

Undefined symbols for architecture x86_64:
  "_MPI_Init", referenced from:
      _main in main.c.o
ld: symbol(s) not found for architecture x86_64
clang-9: error: linker command failed with exit code 1 (use -v to see invocation)

我认为,我无法弄清楚如何为其编写正确的 CMakeLists。

我的 CMakeLists 看起来像:

cmake_minimum_required(VERSION 3.15.3)
project(SeqSol C)

set(CMAKE_C_COMPILER "/usr/local/opt/llvm/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/local/opt/llvm/bin/clang++")
set(OPENMP_LIBRARIES "/usr/local/opt/llvm/lib")
set(OPENMP_INCLUDES "/usr/local/opt/llvm/include")

OPTION(USE_OpenMP "Use OpenMP to enable <omp.h>" ON)
OPTION(USE_MPI "Use MPI to enable <mpi.h>" ON)

# Find OpenMP
if (APPLE AND USE_OpenMP)
    if (CMAKE_C_COMPILER_ID MATCHES "Clang")
        set(OpenMP_C "${CMAKE_C_COMPILER}")
        set(OpenMP_C_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
        set(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp9")
        set(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES})
        set(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES})
        set(OpenMP_libiomp9_LIBRARY ${OpenMP_C_LIB_NAMES})
    endif ()
    if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
        set(OpenMP_CXX "${CMAKE_CXX_COMPILER}")
        set(OpenMP_CXX_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
        set(OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp9")
        set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
        set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
        set(OpenMP_libiomp9_LIBRARY ${OpenMP_CXX_LIB_NAMES})
    endif ()
endif ()

if (USE_OpenMP)
    find_package(OpenMP REQUIRED)
endif (USE_OpenMP)

if (USE_MPI)
    find_package(MPI REQUIRED)
endif (USE_MPI)

if (MPI_FOUND)
    include_directories(${MPI_INCLUDES_PATH})
    link_directories(${MPI_LIBRARIES_PATH})
endif(MPI_FOUND)

if (OPENMP_FOUND)
    include_directories("${OPENMP_INCLUDES}")
    link_directories("${OPENMP_LIBRARIES}")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif (OPENMP_FOUND)

add_executable(SeqSol main.c problem.c fileparse.c)

作为首选项中的 C 编译器是

/usr/local/opt/llvm/bin/clang 

我还写了 CMake 选项:

-DCMAKE_C_COMPILER=/usr/local/opt/llvm/bin/clang

我可以使用 Open MP 功能,但不能使用 MPI。

有什么建议吗?

【问题讨论】:

  • 不用mpicc编译MPI代码吗?它具有获取相关编译器定义/标志的选项,因此,您可以将其添加到您的 make 中。
  • Craig Estey 你是对的,但我找不到正确的方法。如果我将 C Complied 更改为 /usr/local/opt/open-mpi/bin/mpicc,我会遇到 Open MP 问题。你知道如何为 mpicc 充分添加标志吗?
  • @CraigEstey 你知道解决方案吗?
  • man mpicc 从此,您可以使用-showme 选项。在CMakeLists 中,从mpicc 命令的输出中执行set of(例如)OPENMPI_C_FLAGS。我忘记了 set 的确切语法,但是在 shell 中它会类似于 export C_FLAGS="`mpicc -showme`"

标签: c cmake openmp clion openmpi


【解决方案1】:

我终于弄清楚如何混合开放 mp 和 mpi。这个 CMake 文件对我有用

cmake_minimum_required(VERSION 3.15.3)
project(SeqSol C)

set(CMAKE_C_COMPILER "/usr/local/opt/llvm/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/local/opt/llvm/bin/clang++")
set(OPENMP_LIBRARIES "/usr/local/opt/llvm/lib")
set(OPENMP_INCLUDES "/usr/local/opt/llvm/include")

OPTION(USE_OpenMP "Use OpenMP to enable <omp.h>" ON)
OPTION(USE_MPI "Use MPI to enable <mpi.h>" ON)

# Find OpenMP
if (APPLE AND USE_OpenMP)
    if (CMAKE_C_COMPILER_ID MATCHES "Clang")
        set(OpenMP_C "${CMAKE_C_COMPILER}")
        set(OpenMP_C_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
        set(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp9")
        set(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES})
        set(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES})
        set(OpenMP_libiomp9_LIBRARY ${OpenMP_C_LIB_NAMES})
    endif ()
    if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
        set(OpenMP_CXX "${CMAKE_CXX_COMPILER}")
        set(OpenMP_CXX_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
        set(OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp9")
        set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
        set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
        set(OpenMP_libiomp9_LIBRARY ${OpenMP_CXX_LIB_NAMES})
    endif ()
endif ()

if (USE_OpenMP)
    find_package(OpenMP REQUIRED)
endif (USE_OpenMP)

if (USE_MPI)
    find_package(MPI REQUIRED)
endif (USE_MPI)

if (MPI_FOUND)
    include_directories(${MPI_INCLUDES_PATH})
endif(MPI_FOUND)


if (OPENMP_FOUND)
    include_directories("${OPENMP_INCLUDES}")
    link_directories("${OPENMP_LIBRARIES}")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif (OPENMP_FOUND)

add_executable(SeqSol main.c problem.c fileparse.c)
target_link_libraries(SeqSol ${MPI_LIBRARIES})

【讨论】:

    猜你喜欢
    • 2015-03-18
    • 1970-01-01
    • 2021-06-12
    • 2015-03-26
    • 2015-08-08
    • 1970-01-01
    • 2017-03-14
    • 1970-01-01
    • 2013-07-27
    相关资源
    最近更新 更多