开发者

Parent Node Stalling On MPI_Barrier

开发者 https://www.devze.com 2023-03-25 15:03 出处:网络
I\'m new to MPI, and I am having some trouble implementing mpirun on a cluster of Mac OS X nodes running snow leopard.The issue that I\'m having involves MPI_Barrier().I have a simple function shown b

I'm new to MPI, and I am having some trouble implementing mpirun on a cluster of Mac OS X nodes running snow leopard. The issue that I'm having involves MPI_Barrier(). I have a simple function shown below that works fine. However, when I add an MPI_Barrier() command at the end of the conditional, the parent node stalls. One of the processors moves past the barrier command, while the other one stays stuck. I was hoping someone could give me a quick workaround, or maybe suggest some way in which my network environment is preventing the command from functioning properly.

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(&am开发者_开发技巧p;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;
}


Other than fixing a few typos, I get your code to work without issue. I'm using openmpi and gnu c compiler on an IBM cluster. I'm not sure where you put the barrier. Have I guess correctly?

#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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号