警告:从不兼容的指针类型传递'MPI_Recv'的参数7

时间:2011-12-03 12:54:52

标签: compiler-construction mpi

我正在尝试编译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;
    }

我认为错误在&status的两个实例中引用MPI_Recv。我正在尝试获取状态地址,该地址在我的代码中先前已声明为MPI_Status status

1 个答案:

答案 0 :(得分:2)

您已将status声明为本地int

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

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

更改本地status变量的名称或使其成为合适的类型。