使用MPI_Send& C ++的C ++ MPI程序出错MPI_RECV

时间:2018-03-11 22:08:04

标签: c++

我是MPI的新用户并尝试编写测试程序,我使用MPI_SendMPI_Recv在根目录之间传递两个数字"a""b"流程为0,下一个为1。但每次我得到相同的错误:“Test.exe已触发断点。”你能帮我吗?

#include <iostream>
#include "mpi.h"

using namespace std;

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

    int rank, size;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    unsigned int a;
    unsigned int b;
    MPI_Status status;

    if (rank == 0) {
        a = 1;
        MPI_Send(&a,1,MPI_INTEGER,1,MPI_ANY_TAG,MPI_COMM_WORLD);
        MPI_Recv(&b, 1, MPI_INTEGER, 1, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
        printf("Root has now B: ", rank, b);
    }
    else {
        b = 2;
        MPI_Recv(&a, 1, MPI_INTEGER, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
        MPI_Send(&b, 1, MPI_INTEGER, 0, MPI_ANY_TAG, MPI_COMM_WORLD);
        printf("Proc 1 has now B: ", rank, a);
    }

    MPI_Finalize();
    return(0);  
}

0 个答案:

没有答案