【问题标题】:warning: passing argument 7 of ‘MPI_Recv’ from incompatible pointer type警告:从不兼容的指针类型传递“MPI_Recv”的参数 7
【发布时间】:2011-12-03 12:54:51
【问题描述】:

我正在尝试编译 MPI_Exchange 函数,但不断收到以下错误。

错误:

OddEvenSort.c: In function ‘MPI_Exchange’:
OddEvenSort.c:75: warning: passing argument 7 of ‘MPI_Recv’ from incompatible pointer type
/usr/lib/openmpi/include/mpi.h:1174: note: expected ‘struct MPI_Status *’ but argument is of type ‘int *’
OddEvenSort.c:84: warning: passing argument 7 of ‘MPI_Recv’ from incompatible pointer type
/usr/lib/openmpi/include/mpi.h:1174: note: expected ‘struct MPI_Status *’ but argument is of type ‘int *’
/usr/bin/mpicc  -o OddEvenSort OddEvenSort.o -lm

代码:

int MPI_Exchange( int n, double *a, int rank1, int rank2,MPI_Comm comm )
{
   int rank, tag1, tag2, size, i, status;
   double * b, * c;


  MPI_Comm_rank(comm, &rank);
  MPI_Comm_size(comm, &size);

   if(rank == rank1){
     MPI_Send(&a[0],n,MPI_DOUBLE,rank2,tag1,comm);
     MPI_Recv(&b[0],n,MPI_DOUBLE,rank2,tag2,comm,&status);
     c = merge_array(n,a,n,b);
     for(i=0;i<n;i++){
       a[i] = c[i];
     }

   }
   else if(rank == rank2){
      MPI_Send(&a[0],n,MPI_DOUBLE,rank1,tag1,comm);
     MPI_Recv(&b[0],n,MPI_DOUBLE,rank1,tag2,comm,&status);
     c = merge_array(n,a,n,b);
     for(i=0;i<n;i++){
       a[i] = c[i+n];
     }
   }

     return MPI_SUCCESS;
    }

我相信在MPI_Recv 的两个实例中,错误指的是&amp;status。我正在尝试获取 status 的地址,该地址在我的代码中之前声明为 MPI_Status status

【问题讨论】:

    标签: compiler-construction mpi


    【解决方案1】:

    您已将 status 声明为本地 int

       int rank, tag1, tag2, size, i, status;
    

    它会覆盖代码中前面的 status 的任何全局声明。

    要么更改本地 status 变量的名称,要么将其设为适当的类型。

    【讨论】:

    • 哇,我怎么错过了。谢谢保罗。
    • 确保您启用了编译器警告 - 当您无意中执行此类操作时应该会收到警告,告诉您局部变量会隐藏全局声明。
    猜你喜欢
    • 2011-01-10
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多