MPI—双机运行

来源:互联网 发布:unity3d eventsystem 编辑:程序博客网 时间:2024/06/08 11:33
#include "stdafx.h"#include "mpi.h"#include <stdio.h>#include <math.h>int main(int argc, char * argv[]){int myid,numprocs;int namelen;char processor_name[MPI_MAX_PROCESSOR_NAME];MPI_Init(&argc,&argv);MPI_Comm_rank(MPI_COMM_WORLD,&myid);MPI_Comm_size(MPI_COMM_WORLD,&numprocs);MPI_Get_processor_name(processor_name,&namelen);fprintf(stderr,"Hello world!Process %d of%d on %s\n",myid,numprocs,processor_name);MPI_Finalize();return 0;}


所有的环境,两台计算机都需要配置,且工程名字及目录都需一致;

之后,编写代码如上,步骤和单机运行无区别;

点击绿色箭头按钮,进行编译生成相应的exe文件。

运行wmpiconfig.exe时,选择Domain中的WORKGROUP,然后依次单击Get Hosts、Scan Hosts当两台计算机都变绿时,单击Scan for Versions;选中两台计算机,点击Apply all,然后点击OK。



运行wmpiexec.exe时,找到需要编译的文件目录,选中run in an separate window,更改线程数量为8;

选中more options,在hosts里面以空格为分界,依次填写主机名字;

最后点击Execute运行,看到想要的结果。

运行结果:



                                             
0 0
原创粉丝点击