0
这个作业要求我制定了MPI程序的并行奇偶排序,并带来三个功能在一起:MPI错误:下标值既不是数组,也不指针
MPI_Compare_exchange()
的P2P比较和交换操作MPI_Sort()
用于并行奇偶排序操作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 : %f\n", array[x]);
}
}
我认为它指的是这样的:&a[0]
,但我不知道如何解决它。有任何想法吗?
为什么要使用&A [0]?你认为这意味着什么? –
By&a [0]我的意思是数组a的第一个元素的地址。 –