Skip to content

Instantly share code, notes, and snippets.

@Liudx1985
Created October 28, 2014 08:29
Show Gist options
  • Save Liudx1985/a66c98d19ac30a1b8fda to your computer and use it in GitHub Desktop.
Save Liudx1985/a66c98d19ac30a1b8fda to your computer and use it in GitHub Desktop.
Boost.MPI
MPI实践起来真是有点困难,因为好多外国网站上不去,只能自己摸索:
1.setup mpich2
mpiexec -remove to remove account for each computer node
mpiexec -register to add account for each computer 'node'
mpiexec -validate to validate the account
Notice ,you must create a account(username/password all same) for all nodes on windows.
2.build boost.mpi
修改boost_1_47_0\tools\build\v2\tools\mpi.jam文件,修改的地方如下:
#local cluster_pack_path_native = "C:\\Program Files\\Microsoft Compute Cluster Pack" ;
local cluster_pack_path_native = "D:\\Program Files\\MPICH2" ;
..
options = <include>$(cluster_pack_path)/Include
<address-model>64:<library-path>$(cluster_pack_path)/Lib/amd64
<library-path>$(cluster_pack_path)/Lib
<find-static-library>mpich2d
<toolset>msvc:<define>_SECURE_SCL=0
找到
需要在boost_1_47_0\tools\build\v2\user-config.jam中加入(注意空格!!!)
using MPI ;
加入mpich2的include/lib到VC编译器路径,然后执行b2 --with-mpi stage [blabla...]
3.write mpi application
/*
run in command line [mpiexec -localonly 2 mpid.exe] in local mode.
P2P communication
*/
#include "mpi.h"
#pragma comment(lib, "mpich2d.lib")
#include <string>
#include <iostream>
#include <boost/mpi.hpp>
#include <boost/serialization/string.hpp>
namespace mpi = boost::mpi;
int main(int argc, char* argv[])
{
mpi::environment env(argc, argv);
mpi::communicator world;
std::string value;
if (world.rank() == 0) {
value = "Hello, World!";
}
broadcast(world, value, 0);
std::cout << env.processor_name() <<"%? ";
std::cout << "Process #" << world.rank() << "of " << world.size()
<< " says:" << value << std::endl;
return 0;
}
build a mpid.exe ,put it on each node like:"d:/mpid.exe";
4.!test
on your main host, create a machine.txt contains:
[
#host file:
10.85.20.7 slots=2
10.78.20.220 slots =4
]
in command line switch to "d:/" and run:
mpiexec -machinefile machine.txt -n 8 mpid.exe
sample output:
D:\>mpiexec -machinefile machine.txt -n 3 mpid
LIUDX-PC%? Process #2of 3 says:Hello, World!
LIUDX-PC%? Process #0of 3 says:Hello, World!
WIN-4UAAJ3D0DD8%? Process #1of 3 says:Hello, World!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment