我将 mpi 安装到 Windows 中,我可以使用它的库。问题是当我在 Windows 中写
mpiexec -n 4 proj.exe
进入命令提示符后无法进行正确的操作。 4个不同的进程分别使用整个代码文件。它们的行为不像仅在 MPI_Init 和 MPI_Finalize 行中工作的并行进程。我该如何解决这个问题?在 Windows 中无法使用 MPI。
P.s : 我正在使用 Dev c++
最佳答案
根据您所说的,MPI 正在正确运行——相反,您的假设是不正确的。在每个 MPI 实现(无论如何我都使用过)中,整个程序在每个 进程上从头到尾运行。 MPI_Init 和 MPI_Finalize 函数需要为每个进程设置和拆除 MPI 结构,但它们不指定并行执行的开始和结束。并行部分的开始是main中的第一条指令,结束是最后的返回。
一个好的"template"程序看起来像你想要的(也在 How to speed up this problem by MPI 中回答):
int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
if (myid == 0) { // Do the serial part on a single MPI thread
printf("Performing serial computation on cpu %d\n", myid);
PreParallelWork();
}
ParallelWork(); // Every MPI thread will run the parallel work
if (myid == 0) { // Do the final serial part on a single MPI thread
printf("Performing the final serial computation on cpu %d\n", myid);
PostParallelWork();
}
MPI_Finalize();
return 0;
}
关于c++ - Windows 中的 Mpi 用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2015673/