编译 MPI 时出错

Errors while compiling MPI

本文关键字:出错 MPI 编译      更新时间:2023-10-16

我正在尝试使用来自 https://stackoverflow.com/questions/5953979/sending-and-receiving-array-using-mpi-part-2 的代码编译C++代码。

我使用以下命令进行编译:mpiicpc -o <filename> xxxx.cc -lmpi

编译后,我的所有错误似乎都是指我在源代码中定义的两个函数,用于打印输出值并执行 MPI Isend 和 MPI Irecv。具体来说,我得到两种类型的错误

  1. 错误:标识符"变量"未定义
  2. 错误:函数调用中的参数太少:MPI_Isend/MPI_IrecvMPI Waitall();最后,它与以下消息一起存在:编译中止 xxxx.cc(代码 2)。

您能否指出我在定义变量时一定做错了什么?

以下是我的源代码摘录(完整的代码可在 https://stackoverflow.com/questions/5953979/sending-and-receiving-array-using-mpi-part-2 获得):

int main (int argc, char *argv[])
{
int my_rank;
int p;
int source; 
int dest;
int tag = 0;
//Allocating Memory
double *A = new double[Rows*sizeof(double)];
double *B = new double[Rows*sizeof(double)];
....
....
....
//MPI Commands
MPI_Status status;
MPI_Init (&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &p);
//For number of beats
for (ibeat=0;ibeat<beats;ibeat++)
{
    for (i=0; i<Cols/2; i++)
    {
        for (y=0; y<Rows/2; y++)
        {
            if (my_rank == 0)
                if (i < 48)
                    if (y<48)
                       V[i][y] = 0;
            if (my_rank ==
              .....
                ....
                  ....        
        }
    }
    //Load the Array with the edge values
    for (r=0; r<Rows/2; y++)
    {
        if ((my_rank == 0) || (my_rank == 1))
        {
            A[r] = V[r][48];
            BB[r] = V[r][48];
        }
        if ((my_rank
            ...
            ...
    }
    prttofile ();
    outputpass ();
    ibeat = ibeat+1;
 }
 MPI_Finalize ();
}

void prttofile ()
{
for (i = 0; i<Cols/2; i++)
  {
    for (y = 0; y<Rows/2; y++)
    {
        if (my_rank == 0)
           fout << V[i][y] << " " ;
        ....
           .... 
    }
  }
if (my_rank == 0)
    fout << endl;
 ....
}

void outputpass ()
{
int test = 2;
if ((my_rank%test) == 0)
{
    MPI_Isend(C, Rows, MPI_DOUBLE, my_rank+1, MPI_COMM_WORLD); //Non blocking Send
    MPI_Irecv(CC, Rows, MPI_DOUBLE, my_rank+1, MPI_COMM_WORLD, &status); //Non Blocking Recv
}
else if ((my_rank%test) == 1)
....
....
MPI_Waitall ();
}
  1. 您没有声明很多变量 - 特别是循环计数器。 将它们全部声明在函数的顶部,你会没事的。

  2. 根据文档,MPI_Isend()的签名是:

    int MPI_Isend( void *buf, int count, MPI_Datatype datatype, int dest,
           int tag, MPI_Comm comm, MPI_Request *request ) 
    

    它有七个参数 - 你只传递五个参数。 您需要更正这一点。 MPI_Irecv()也是如此.

MPI_Isend()需要的参数比您提供的要多得多。这是你的台词:

MPI_Isend(C, Rows, MPI_DOUBLE, my_rank+1, MPI_COMM_WORLD);

标签在哪里?请求在哪里?

同样,您的MPI_Waitall()根本没有任何论据!您需要请求数组、请求数和状态数组。

我建议您阅读 MPI 中的非阻塞通信示例。