为什么我无法附加到此 MPI 代码的 bootstrap 队列?

Why do i get the failed to attach to a bootstrap queue for this MPI code?

我正在尝试做的练习要求我们构建一个进程环,其中每个进程将数字 x 传递给以下进程,只有 rank=0 的进程减少 x。当 x 等于 0 时,程序结束。 工作代码如下:

#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include "mpi.h"

int main(int argc, char** argv) {

int x = 0;
int tag = 99;

MPI_Status status;

MPI_Init(&argc, &argv);

int myRank;
MPI_Comm_rank(MPI_COMM_WORLD, &myRank);

int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);

if (myRank == 0) {
    printf("Process %d enter a value: \n", myRank);
    fflush(stdout);
    scanf_s("%d", &x);

    while (x>0) {
        MPI_Send(&x, 1, MPI_INT, 1, tag, MPI_COMM_WORLD);
        MPI_Recv(&x, 1, MPI_INT, MPI_ANY_SOURCE, tag, MPI_COMM_WORLD, &status);
        printf("Process %d : lap number %d \n", myRank, x);
        x--;
    } 


}
else {

    do {

        
        MPI_Recv(&x, 1, MPI_INT, MPI_ANY_SOURCE, tag, MPI_COMM_WORLD, &status);
        printf("Process %d : lap number %d \n", myRank, x);
        MPI_Send(&x, 1, MPI_INT, (myRank + 1) % size, tag, MPI_COMM_WORLD); 
    } while (x > 1);
}

MPI_Finalize();
return 0;
}

但是如果我像这样更改最后一个 do while 循环:

#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include "mpi.h"

int main(int argc, char** argv) {

int x = 0;
int tag = 99;

MPI_Status status;

MPI_Init(&argc, &argv);

int myRank;
MPI_Comm_rank(MPI_COMM_WORLD, &myRank);

int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);

if (myRank == 0) {
    printf("Process %d enter a value: \n", myRank);
    fflush(stdout);
    scanf_s("%d", &x);

    while (x>0) {
        MPI_Send(&x, 1, MPI_INT, 1, tag, MPI_COMM_WORLD);
        MPI_Recv(&x, 1, MPI_INT, MPI_ANY_SOURCE, tag, MPI_COMM_WORLD, &status);
        printf("Processo %d : giro numero %d \n", myRank, x);
        x--;
    } 


}
else {

    while (x>0) {

        
        MPI_Recv(&x, 1, MPI_INT, MPI_ANY_SOURCE, tag, MPI_COMM_WORLD, &status);
        printf("Processo %d : giro numero %d \n", myRank, x);
        MPI_Send(&x, 1, MPI_INT, (myRank + 1) % size, tag, MPI_COMM_WORLD); 
    } 
}

MPI_Finalize();
return 0;
}

我收到这个错误:

job aborted:
[ranks] message

[0] fatal error
Fatal error in MPI_Send: Other MPI error, error stack:
MPI_Send(buf=0x000000F6100FF514, count=1, MPI_INT, dest=1, tag=99, MPI_COMM_WORLD) failed
failed to attach to a bootstrap queue - 10616:296

[1-2] terminated

但是我不明白为什么...这两个代码不应该是等价的吗?

您将 x 设置为零,然后除零以外的所有进程都执行 while (x>0) { stuff }。所以他们什么都不做。