本地MPI并行程序调试Visual Studio
1、下载并安装MSMPI安装包MSMPISetup及开发者工具msmpisdk
下载地址:http://go.microsoft.com/fwlink/?LinkID=389556
如果按照默认路径安装这两个软件,那么会在C盘下生成两个不同的目录,分别为:
c:\Program Files (x86)\Microsoft SDKs\MPI\
c:\Program Files\Microsoft MPI\
2、打开Visual Studio,创建新的解决方案,添加自己写的cpp源文件
这里提供一个带命令行输入参数的源代码:
#include <iostream>
#include "mpi.h"
using namespace std;
int main( int argc, char ** argv )
{
int myRank, nProcs, length;
char name[ MPI_MAX_PROCESSOR_NAME ];
double T0, T1;
MPI_Init( & argc, & argv );
T0 = MPI_Wtime();
MPI_Comm_size( MPI_COMM_WORLD, & nProcs );
MPI_Comm_rank( MPI_COMM_WORLD, & myRank );
MPI_Get_processor_name( name, & length );
cout << "argc = " << argc << endl;
for ( int i = 0; i < argc; ++ i )
{
cout << "argv" << i << "= " << argv[ i ] << endl;
}
cout << "my rank is " << myRank << endl;
cout << "processor name is " << name << endl;
cout << "number of procs is " << nProcs << endl;
T1 = MPI_Wtime();
double t0 = T1 - T0;
cout << "wall time is " << t0 << endl;
double totalTime;
//MPI_Reduce( &t0, &totalTime, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD );
MPI_Allreduce( &t0, &totalTime, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
cout << "total wall time is " << totalTime << endl;
MPI_Finalize();
int a = getchar();
return 0;
}
3、项目---属性---添加C++包含目录,以及库目录,注意!!!Debug模式和Release模式都需要分别添加,否则不能正确运行,下同
4、添加链接库文件,链接器---输入---附加依赖项---msmpi.lib
5、1. 调试---要启动的调试器---MPI群集调试器
2. 运行环境---localhost/4,说明选择4个进程并行
3. 应用程序参数--- 1 3 5 7,此为程序命令行输入参数,即argc = 5; argv = 程序路径,1, 3, 5, 7,通过调试可以验证此结果
6、在Debug模式下调试程序,程序可正常运行,输出5个屏幕,其中第一个为cmd,其他4个即为4个并行进程,从输出来看,启动了4个进程,并且读入了相应的命令行参数,可以F10逐行进入程序调试。