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: ” (MSM