我的mpi程序应该等级0等待来自其他级别的消息,这让他们知道他们已准备好接收数据。此时,我的等级0将发送数据。不幸的是,它只从第1级捕获“准备好”的信号,我不明白为什么!
这是代码:
73 if(nrank == 0)
74 {
75 for(int at = 0; at < 2; at++)
76 {
77 for(int l = 0; l <= Lmax; l++)
78 {
79 for(int m = -l; m <= l; m++)
80 {
81 rank_rdy = 0;
82 /*****************
83 * prep the data *
84 *****************/
85 printf("----------------------------------------------\n");
86 printf("rank(0): generating data for (at, l, m) = (%i, %i, %i)\n", at, l, m);
87 info_space[0] = at;
88 info_space[1] = l;
89 info_space[2] = m;
90 read_d_grid(y_space, at, l, m);
91
92 /* wait for receiving signale */
93 printf("rank(0): waiting for ready signal ... \n");
94 rc = MPI_Recv(&rank_rdy, 1, MPI_INT, MPI_ANY_SOURCE, tag, MPI_COMM_WORLD, &status);
95 printf("rank(0): ready signal caught from rank %i\n", rank_rdy);
96 MPI_Send(info_space, 1, MPI_INT, rank_rdy, tag, MPI_COMM_WORLD);
97 }
98 }
99 }
100 }
101 else
102 {
103 int junk = 0;
104 rank_rdy = nrank;
105 tag = nrank;
106 MPI_Send(&rank_rdy, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
107
108 printf("rank(%i): ready signal sent\n", nrank);
109 // successful send
110 MPI_Recv(info_space, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
111
112 for(int i = 0; i < 900000000; i++)
113 {
114 junk = junk + i;
115 }
116 printf("rank(%i): done spinning\n");
117 }
输出是:
rank(0): inside getInputs: reading command line arguments
rank(2): inside getInputs: reading command line arguments
rank(3): inside getInputs: reading command line arguments
rank(1): inside getInputs: reading command line arguments
rank(0): inside read_r_grid(): reading meldrum.txt
----------------------------------------------
rank(0): generating data for (at, l, m) = (0, 0, 0)
rank(0): inside read_d_grid(y_space, 0, 0, 0)
rank(2): inside read_r_grid(): reading meldrum.txt
rank(3): inside read_r_grid(): reading meldrum.txt
rank(1): inside read_r_grid(): reading meldrum.txt
rank(0): waiting for ready signal ...
rank(2): ready signal sent
rank(3): ready signal sent
rank(1): ready signal sent
rank(0): ready signal caught from rank 1
----------------------------------------------
rank(0): generating data for (at, l, m) = (0, 1, -1)
rank(0): inside read_d_grid(y_space, 0, 1, -1)
rank(0): waiting for ready signal ...
现在,如果我将第101行更改为“else if(nrank == 2)”并且我将第94行更改为“2”而不是“MPI_ANY_SOURCE”,那么我根本没有获得任何信号捕获:
rank(0): inside getInputs: reading command line arguments
rank(3): inside getInputs: reading command line arguments
rank(2): inside getInputs: reading command line arguments
rank(1): inside getInputs: reading command line arguments
rank(0): inside read_r_grid(): reading meldrum.txt
rank(2): inside read_r_grid(): reading meldrum.txt
rank(3): inside read_r_grid(): reading meldrum.txt
rank(1): inside read_r_grid(): reading meldrum.txt
----------------------------------------------
rank(0): generating data for (at, l, m) = (0, 0, 0)
rank(0): inside read_d_grid(y_space, 0, 0, 0)
rank(0): waiting for ready signal ...
rank(2): ready signal sent
因此知道rank(0)根本不接收来自rank(1)以外的任何人的任何信号。任何人都可以看到为什么除了排名1之外的排名不能通过排名0?
答案 0 :(得分:1)
我是一个白痴...标签被初始化为1,因此我只接收来自排名给出相似标签的信号(排名1)。