【发布时间】:2012-01-11 17:49:37
【问题描述】:
这个作业需要我开发一个 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]?你认为这意味着什么?
-
&a[0] 我的意思是数组a的第一个元素的地址。