MPI错误:下标的值既不是数组也不是指针



这项任务要求我开发一个并行奇偶排序的MPI程序,并将三个函数结合在一起:

  1. MPI_Compare_exchange()用于P2P比较和交换操作
  2. MPI_Sort()用于并行奇偶排序
  3. MPI_Is_sorted()测试并行数组排序是否完成
当编译 时,我得到这些错误
OddEvenSort.c:102: error: invalid operands to binary / (have ‘int *’ and ‘int’)
OddEvenSort.c:102: error: subscripted value is neither array nor pointer
OddEvenSort.c:104: error: subscripted value is neither array nor pointer
OddEvenSort.c:112: error: subscripted value is neither array nor pointer
OddEvenSort.c:116: error: subscripted value is neither array nor pointer
OddEvenSort.c:123: error: subscripted value is neither array nor pointer

这是代码:

int MPI_Sort(int n,double * array, int root, MPI_Comm comm){
    int rank, x, m, size, a, i;
    if( rank == 0 )
    {
        array = (double *) calloc( n, sizeof(double) );
        srand( ((unsigned)time(NULL)+rank) );
        for( x = 0; x < n; x++ ) array[x]=((double)rand()/RAND_MAX)*m;
    }
    MPI_Scatter(array, n/size, MPI_DOUBLE, &a[0], n/size, MPI_DOUBLE, 0, comm );
    merge_sort(n/size,&a[0]);
    for(i=0;i<size;i++){
        if( (i+rank)%2 ==0 ){
            if( rank < size-1 ) 
                exchange(n/size,&a[0],rank,rank+1,comm);
            } else{
                if( rank > 0 ) exchange(n/size,&a[0],rank-1,rank,comm);
            }
            MPI_Barrier(comm);
        }
    MPI_Gather(&a[0], n/size, MPI_DOUBLE, array, n/size, MPI_DOUBLE, 0, comm);
    if( rank == 0 )
    {
        for( x = 0; x < n; x++ )  printf( "Output : %fn", array[x] );
    }

}

我认为它是指这个:&a[0],但我不知道如何修复它。什么好主意吗?

'a'被定义为整型而不是数组,因此不能传递元素0的地址。

我想你的意思是'a'被定义为双精度类型,并且与'array'具有相同的大小。

double a[n];

最新更新