MS-MPI+boost 编译

来源:互联网 发布:mysql解压版配置 编辑:程序博客网 时间:2024/05/29 04:11

First, the MPI should work, Before using Boost MPI, the computer should have a working MPI implementation. Boost MPI should work with any MPI implementation. The following codes can be used to test if there is a working MPI in the current computer:

#include "stdafx.h"#include <mpi.h>#include <iostream>int main(int argc,  char** argv){  MPI_Init(&argc, &argv);  int rank;  MPI_Comm_rank(MPI_COMM_WORLD, &rank);  if (rank == 0) {    int value = 17;    int result = MPI_Send(&value, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);    if (result == MPI_SUCCESS)      std::cout << "Rank 0 OK!" << std::endl;  } else if (rank == 1) {    int value;    int result = MPI_Recv(&value, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,              MPI_STATUS_IGNORE);    if (result == MPI_SUCCESS && value == 17)      std::cout << "Rank 1 OK!" << std::endl;  }  MPI_Finalize();  return 0;}

Under MS-MPI with VS2012. Go to the project folder and run: mpiexe -np -2 (+name of .exe). The output should be:
Rank 0 OK!
Rank 1 OK!
If we saw this, indicating there is a working MPI implementation and we can go to the next. Otherwise, we need to install a MPI implementation, taking MS-MPI as an example.

首先mpi: (详细步骤见:http://blogs.technet.com/b/windowshpc/archive/2015/02/02/how-to-compile-and-run-a-simple-ms-mpi-program.aspx)
1: 下载,安装MS-MPI SDK
2: 新建一个 Visual C++ Win32 Console Application project.
3: set include directories: for 64 bits: include: ” (MSMPIINC);(MSMPI_INC)\x64”
for 32 bits: include”(MSMPIINC);(MSMPI_INC)\x86”
这里写图片描述
4: set link directories: add “msmpi.lib” to the additional dependencies;
for 64 bits: add (MSMPILIB64)totheAdditionalLibraryDirectories)for32bits:add(MSMPI_LIB32);
这里写图片描述

==================So far, MPI should work==============================
Next, build boost_1_60:

1: Download boost_1_60_0,Unzip it to (http://www.boost.org/users/history/version_1_60_0.html)
2: Modify the setting of build boost engine:

boost_1_60_0\tools\build\src\tools\mpi.jam249-251 linelocal microsoft_mpi_sdk_path = "C:\\Program Files (x86)\\Microsoft SDKs\\MPI" ;local microsoft_mpi_path = "C:\\Program Files\\Microsoft MPI" ;if [ GLOB $(microsoft_mpi_sdk_path)\\Include : mpi.h ]260-262 lineoptions = <include>$(microsoft_mpi_sdk_path)/Include          <address-model>64:<library-path>$(microsoft_mpi_sdk_path)/Lib/x64          <library-path>$(microsoft_mpi_sdk_path)/Lib/x86268 line.mpirun = "\"$(microsoft_mpi_path)\\Bin\\mpiexec.exe"\" ;

3: Start the developer command prompt of Visual Studio with administrator privileges.
go to boost folder and run:
bootstrap.bat
4: A new file of poject-config.jam is generated, modify it by adding
“using mpi ;”
in line 4.
5: run:

b2.exe toolset=msvc-11.0 address-model=64

After step 5, there are two new folders are generated: one is stage and the other one is bin.v2.
6: add boost into additional include directories(c/c++->general).
for example: the folder is:
c:\program files\boost_1_60_0\boost_1_60_0;
这里写图片描述
Then, go to “linker”-all options-additional library directories: add
c:\program files\boost_1_60_0\boost_1_60_0\stage\lib:
这里写图片描述

, then it is done. and test the following codes:

#include "stdafx.h"#include <boost/mpi/environment.hpp>#include <boost/mpi/communicator.hpp>#include <iostream>namespace mpi = boost::mpi;int main(){  mpi::environment env;  mpi::communicator world;  std::cout << "I am process " << world.rank() << " of " << world.size()            << "." << std::endl;  return 0;}

run above code using 20 cpus and the output is:

这里写图片描述

0 0
原创粉丝点击