Igu*_*amu 2 c++ parallel-processing mpi
我在windows中安装了mpi,我可以使用它的库.问题是在我写的时候在windows中
mpiexec -n 4 proj.exe
Run Code Online (Sandbox Code Playgroud)
进入命令提示符它没有进行正确的操作.4个不同的进程分别使用整个代码文件.它们的行为不像只在MPI_Init和MPI_Finalize行中工作的并行进程.我该如何解决这个问题?在Windows中使用MPI是不可能的.
Ps:我正在使用Dev c ++
J T*_*ler 17
MPI按照你所说的正确运行 - 而你的假设是不正确的.在每个MPI实现中(无论如何我都使用过),整个程序在每个进程中从头到尾运行.MPI_Init和MPI_Finalize函数是设置和拆除每个进程的MPI结构所必需的,但它们不指定并行执行的开始和结束.并行部分的开头是main中的第一条指令,结束是最终返回.
一个好的"模板"程序,它看起来像你想要的那样(也在如何通过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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4392 次 |
| 最近记录: |