下载
用法
mpiexec -n 8 $PROCESS_COUNT x64\Debug\$TARGET.exe 多进程并发启动
mpiexec -f hosts.txt -n 3 $PROCESS_COUNT x64\Debug\$TARGET.exe 联机并发进程,其它联机电脑需在相同路径下有所有程序
//hosts.txt
192.168.86.16
192.168.86.123
192.168.86.108
Demo
#include <stdio.h>
#include <string.h> // For strlen() function
#include <mpi.h> // For MPI programming functions
#define MAX_STRING (100)int _tmain(int argc, _TCHAR* argv[])
{char greeting[MAX_STRING];int comm_sz; // Number of processesint my_rank; // My process rankMPI_Init(NULL, NULL);MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);if (my_rank != 0){sprintf(greeting, "Greetings from process %d of %d!", my_rank, comm_sz);MPI_Send(greeting, strlen(greeting) + 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);}else{printf("Greetings from process %d of %d!\n", my_rank, comm_sz);for (int q = 1; q < comm_sz; q++){MPI_Recv(greeting, MAX_STRING, MPI_CHAR, q, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);printf("%s\n", greeting);}}MPI_Finalize();return 0;
}
参考
win10环境下vs2013+mpich2并行环境搭建_vs2013 mpich-CSDN博客
MPI并行环境配置(Windows 10+VSIDE Community 2019)_amd mpi并行-CSDN博客
windows下安装mpich2_如何安装spmd。exe-CSDN博客