使用CMake,Microsoft MPI和Visual Studio 2017-找不到mpi.h [英] Using CMake, Microsoft MPI and Visual Studio 2017 - cannot find mpi.h

查看:667
本文介绍了使用CMake,Microsoft MPI和Visual Studio 2017-找不到mpi.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找/开发一个非常简单的示例,说明如何将CMake与Microsoft MPI一起用于Visual Studio.我让CMake运作良好,并且大致了解它如何创建CMake项目.我还让MS MPI与Visual Studio一起工作,并确认我可以按照以下示例创建MPI项目:

I am trying to find/develop a very simple example of how to use CMake with Microsoft MPI with Visual Studio. I have CMake working well and generally understand it how to create CMake projects. I also have MS MPI working with Visual Studio and have confirmed I can create an MPI project following this example: https://blogs.technet.microsoft.com/windowshpc/2015/02/02/how-to-compile-and-run-a-simple-ms-mpi-program/

我只是无法让他们一起工作.具体来说,我正在寻找CMake命令放入要在Visual Studio 17中启用MS MPI构建的CMakeLists.txt文件中.我创建了一个CMake项目(位于:

I just have not been able to get them working together. Specifically, I am looking for the CMake commands to put into my CMakeLists.txt file that enables MS MPI builds in Visual Studio 17. I created a CMake project (found here: https://github.com/PSUCompBio/cmake-visualstudio-msmpi) that compiles and runs fine without the inclusion of:

#include "mpi.h"

我要建立项目的步骤是: 1.使用Cmake-GUI应用程序配置和生成makefile 2.使用CMake-GUI中的打开项目"按钮启动Visual Studio 2017. 3.将HelloWorld解决方案设置为启动项目. 4.构建(转到顶部菜单栏,然后​​单击构建->构建解决方案)

The steps I take to build the project are: 1. use the Cmake-GUI application to configure and generate the makefile 2. Use the open project button in the CMake-GUI to launch Visual Studio 2017. 3. Set the HelloWorld solution as the startup project. 4. Build (Got to top menu bar, then Build->Build Solution)

但是,其中包含了mpi.h:

However, with the mpi.h included:

#include <stdio.h>

#include "mpi.h"

int main()
{
   // printf() displays the string inside quotation
   printf("Hello, World!!\n");
   return 0;
}

找不到mpi.h:
生成的Visual Studio错误

the mpi.h is not found:
visual studio error from build

我的顶级CmakeLists.txt文件非常简单,确实找到了MSMPI:

My top level CmakeLists.txt file is pretty simple and does find MSMPI fine:

cmake_minimum_required(VERSION 3.0)
PROJECT (hellocmake)
ADD_SUBDIRECTORY (src)
option(ENABLE_MPI "Enable MPI parallelization" OFF)
if(ENABLE_MPI)
    if(WIN32)
        find_package(MPI REQUIRED)
        if(MPI_FOUND)
            message("Using MPI")
        endif(MPI_FOUND)
    endif(WIN32)
endif(ENABLE_MPI)

我的项目的结构是:

-CMakeLists.txt
-src
----test.cpp
----CMakeLists.txt

我的主要问题是为什么找不到mpi.h?我可以看到CMake-GUI定位了MS MPI包含目录(请参见下图): CMake GUI配置显示MS MPI包含路径

My primary question is why is the mpi.h not being found? I can see that the MS MPI include directory is located by CMake-GUI (see following image): CMake-GUI configure showing MS MPI include path

我还需要在顶层CMakeLists.txt文件中放置另一个CMake命令吗?

Is there another CMake command I need to place in my top level CMakeLists.txt file?

在下面,我展示了CMakeCache.txt的一部分,该部分处理MPI选项:

Below I show a portion of the CMakeCache.txt that deals with MPI options:

//Enable MPI parallelization
ENABLE_MPI:BOOL=ON

//Executable for running MPI programs.
MPIEXEC_EXECUTABLE:FILEPATH=C:/Program Files/Microsoft MPI/Bin/mpiexec.exe

//Maximum number of processors available to run MPI applications.
MPIEXEC_MAX_NUMPROCS:STRING=2

//Flag used by MPI to specify the number of processes for mpiexec;
// the next option will be the number of processes.
MPIEXEC_NUMPROC_FLAG:STRING=-n

//These flags will be placed after all flags passed to mpiexec.
MPIEXEC_POSTFLAGS:STRING=

//These flags will be directly before the executable that is being
// run by mpiexec.
MPIEXEC_PREFLAGS:STRING=

//MPI CXX additional include directories
MPI_CXX_ADDITIONAL_INCLUDE_DIRS:STRING=

//MPI compiler for CXX
MPI_CXX_COMPILER:FILEPATH=MPI_CXX_COMPILER-NOTFOUND

//MPI CXX compilation definitions
MPI_CXX_COMPILE_DEFINITIONS:STRING=

//MPI CXX compilation flags
MPI_CXX_COMPILE_OPTIONS:STRING=

//Path to a file.
MPI_CXX_HEADER_DIR:PATH=C:/Program Files (x86)/Microsoft SDKs/MPI/Include

//MPI CXX libraries to link against
MPI_CXX_LIB_NAMES:STRING=msmpi

//MPI CXX linker flags
MPI_CXX_LINK_FLAGS:STRING=

//If true, the MPI-2 C++ bindings are disabled using definitions.
MPI_CXX_SKIP_MPICXX:BOOL=OFF

//MPI C additional include directories
MPI_C_ADDITIONAL_INCLUDE_DIRS:STRING=

//MPI compiler for C
MPI_C_COMPILER:FILEPATH=MPI_C_COMPILER-NOTFOUND

//MPI C compilation definitions
MPI_C_COMPILE_DEFINITIONS:STRING=

//MPI C compilation flags
MPI_C_COMPILE_OPTIONS:STRING=

//Path to a file.
MPI_C_HEADER_DIR:PATH=C:/Program Files (x86)/Microsoft SDKs/MPI/Include

//MPI C libraries to link against
MPI_C_LIB_NAMES:STRING=msmpi

//MPI C linker flags
MPI_C_LINK_FLAGS:STRING=

//Location of the msmpi library for Microsoft MPI
MPI_msmpi_LIBRARY:FILEPATH=C:/Program Files (x86)/Microsoft SDKs/MPI/Lib/x86/msmpi.lib

//Value Computed by CMake
hellocmake_BINARY_DIR:STATIC=C:/Users/rhk12/code/cmake-visualstudio-msmpi/build

//Value Computed by CMake
hellocmake_SOURCE_DIR:STATIC=C:/Users/rhk12/code/cmake-visualstudio-msmpi

谢谢您的任何建议.

推荐答案

我能够通过使用以下CMakeLists.txt来使其正常工作.

I was able to get this working by using the following CMakeLists.txt.

在顶级目录中,CMakeLists.txt

In top-level directory, CMakeLists.txt

cmake_minimum_required(VERSION 3.0)

PROJECT (hellocmake)

option(ENABLE_MPI "Enable MPI parallelization" OFF)

if(ENABLE_MPI)
    find_package(MPI REQUIRED)
    include_directories(${MPI_INCLUDE_PATH})
    set(CMAKE_C_FLAGS "${CMAKE_FLAGS} ${MPI_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_CXX_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_EXE_LINKER_FLAGS}")
endif(ENABLE_MPI)

ADD_SUBDIRECTORY (src)

然后在src目录CMakeLists.txt中

Then in the src directory CMakeLists.txt

ADD_EXECUTABLE(hellocmake test.cpp)

if(ENABLE_MPI)
    target_link_libraries(hellocmake ${MPI_LIBRARIES})
endif(ENABLE_MPI)

完成此操作后,我返回CMake-GUI并配置并生成Makefile,然后选择打开项目以打开Visual Studio.当我构建并运行时,我得到以下信息:

Once I did this I went back to CMake-GUI and configured and generated Makefile, then selected open project which opened Visual Studio. When I build and run I get this:

Hello, World!!
Hello world from processor MNE-REKR02.engr.psu.edu, rank 0 out of 1 processors

C:\Users\rhk12\code\cmake-visualstudio-msmpi\build\src\Debug\hellocmake.exe (process 18728) exited with code 0.
Press any key to close this window . . .

我不确定如何在Visual Studio中指定处理器数量. CMake配置找到了2,但这是一个不同的问题.

I am not sure how to specify the number of processors in visual studio. The CMake configuration found 2, but that is a different question.

这篇关于使用CMake,Microsoft MPI和Visual Studio 2017-找不到mpi.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆