MPI_Iprobe:RMA调用中的位移参数无效

时间:2017-07-15 08:54:13

标签: c++ mpi ms-mpi

我收到此错误:

[ranks] message

[0] fatal error
Fatal error in MPI_Iprobe: Invalid displacement argument in RMA call, error stack:
MPI_Iprobe(src=MPI_ANY_SOURCE, tag=MPI_ANY_TAG, MPI_COMM_WORLD, flag=0x0000006C0A8FF214, status=0x0000006C0A8FF238) failed
(unknown)(): Invalid displacement argument in RMA call

[1] terminated

这是我正在使用的函数调用:

MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status);

编辑 - 产生错误的完整代码:

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

using namespace std;

int numOfProc, id;
int *arr = NULL;
MPI_Status status;
const static int tag = 1;
int provided;

void fun_1();
void fun_0();


int main(int argc, char *argv[])
{
    //MPI_Init(&argc, &argv);
    MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);


    MPI_Comm_size(MPI_COMM_WORLD, &numOfProc);
    MPI_Comm_rank(MPI_COMM_WORLD, &id);

    cout << "Hello from Process # " << id << '\n';

    if (id == 0)
        fun_0();
    else
        fun_1();

    MPI_Finalize();
}



void fun_1()
{
    omp_set_num_threads(2);
#pragma omp parallel for
    for (int i = 0; i < 2; i++)
    {

        int flag;
        int recvArr[3];
        int sendArr[3];

        while (true)
        {
            flag = 0;

            //Wait for a msg
            while (!flag)
            {
                MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status);
            }

            MPI_Recv(&recvArr, 3, MPI_INT, status.MPI_SOURCE, tag, MPI_COMM_WORLD, &status);

            sendArr[0] = 1;
            sendArr[1] = 2;
            sendArr[2] = 3;
            int size = 3;

            MPI_Send(sendArr, size, MPI_INT, status.MPI_SOURCE, tag, MPI_COMM_WORLD);
        }
    }
}


void fun_0()
{
    omp_set_num_threads(2);
#pragma omp parallel for
    for (int i = 0; i < 2; i++)
    {
        int num = 1;
        while (true)
        {
            if (num++ % 2 == 0)
            {
                int arr[3];

                arr[0] = 1;
                arr[1] = 2;
                arr[2] = 3;

                MPI_Send(arr, 3, MPI_INT, 1, tag, MPI_COMM_WORLD);

                MPI_Status status;
                int length;

                MPI_Probe(1, tag, MPI_COMM_WORLD, &status);

                MPI_Get_count(&status, MPI_INT, &length);

                // Allocate a buffer to hold the data
                int* recievedResult = (int*)malloc(sizeof(int) * length);

                // Now receive 
                MPI_Recv(recievedResult, length, MPI_INT, 1, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
            }
        }
    }

}

这个错误是什么意思?

1 个答案:

答案 0 :(得分:0)

发现MPI_Iprobe不支持多线程。