我是MPI的新手,我在运行雪豹的Mac OS X节点集群上实施mpirun时遇到了一些麻烦。我遇到的问题涉及MPI_Barrier()
。我有一个简单的功能如下所示,工作正常。但是,当我在条件结束时添加MPI_Barrier()
命令时,父节点会停止。其中一个处理器移过屏障命令,而另一个继续卡住。我希望有人可以给我一个快速的解决方法,或者可能会建议我的网络环境阻止命令正常运行。
int main (int argc, char **argv)
{
int me, np, q, sendto;
double t0, t1;
MPI_Status status;
MPI_Init(&argc, &argv);
t0 = MPI_Wtime();
MPI_Comm_size(MPI_COMM_WORLD,&np);
MPI_Commm_rank(MPI_COMM_WORLD,&me);
if (np%2 == 1) return 0;
if (me%2 == 1) {sendto = me - 1;}
else {sendto = me + 1;}
if (me%2 == 0) {
MPI_Send(&me, 1, MPI_INT, sendto, me, MPI_COMM_WORLD);
MPIRecv(&q, 1, MPI_INT, sendto, sendto, MPI_COMM_WORLD, &status);
} else {
MPI_Recv(&q, 1, MPI_INT, sendto, sendto, MPI_COMM_WORLD,&status);
MPI_Send(&me,1,MPI_INT,sendto,me,MPI_COMM_WORLD);
}
printf("Send %d to proc %d, received %d from proc %d\n",me,sendto,q,sendto);
t1 = MPI_Wtime();
printf("Timing is %g",t1-10);
MPI_Finalize();
return 0;
}
答案 0 :(得分:0)
除了修复一些拼写错误之外,我让您的代码无故障地运行。我在IBM集群上使用openmpi和gnu c编译器。我不确定你把障碍放在哪里。我猜对了吗?
#include "mpi.h"
#include "stdio.h"
int main (int argc, char **argv)
{
int me, np, q, sendto;
double t0, t1;
MPI_Status status;
MPI_Init(&argc, &argv);
t0 = MPI_Wtime();
MPI_Comm_size(MPI_COMM_WORLD,&np);
MPI_Comm_rank(MPI_COMM_WORLD,&me);
if (np%2 == 1) {
MPI_Finalize();
return 0;
}
if (me%2 == 1) {sendto = me - 1;}
else {sendto = me + 1;}
if (me%2 == 0) {
MPI_Send(&me, 1, MPI_INT, sendto, me, MPI_COMM_WORLD);
MPI_Recv(&q, 1, MPI_INT, sendto, sendto, MPI_COMM_WORLD, &status);
} else {
MPI_Recv(&q, 1, MPI_INT, sendto, sendto, MPI_COMM_WORLD,&status);
MPI_Send(&me,1,MPI_INT,sendto,me,MPI_COMM_WORLD);
}
MPI_Barrier(MPI_COMM_WORLD);
printf("Send %d to proc %d, received %d from proc %d\n",
me,sendto,q,sendto);
t1 = MPI_Wtime();
printf("Timing is %g\n",t1-t0);
MPI_Finalize();
return 0;
}