正在加载图片...
13.5步骤(3) MPI COMM WORLD) 0 MPI_ Recv(&templ[]. MPI CHAR, 0, f(int)"Spt, MPI COMM WORLD) I CHAR, MPI Barrier( LALLTOONE TYPE+ MPI COMM WORLD) MPI COMM WORLD, &request[++D: *每个处理器根据上步送来的P-1个主 MPI Waitall(SumID-1, request, 元把自己的n/P个数据分成P段 status) 记为处理器Pi的第j+1段,其中 j=0,…,P-1,对应于 处理器P0将上一步送来的P段 法13.5步骤(5) 有序的数据序列做P路归并, n= mylength 再选择排序后的第P1, index[0]=0; 2(P-1),…,(P-1)P-1)个共 个主元,对应于算法13.5步 while(arr[oP=templ o)&&(i<SumID)) MPI Barrier( index[21-1]=0; MPI COMM WORLD index 21=0 quicksort( temp1, 0, SumID"Spt-1); MPI COMM WORLD) for(Fl; i <spt+ 1; 1++) index[2*i-11 templo=templ["Spt-1; /处理器P0将这P1个主元播送到 while (i<SumID) 所有处理器中,对应于算法 13.5步骤(4)* c4=templ[: MPI_ Bcast( templ MPI CHAR, O while((arr[c2=c4)&&(cl<c3)) MPI COMM WORLD) MPI Barrier( if(arr[c2>c4 MPI COMM WORLD) 3=c2-1; intx(cl+c3)2) MPI Send( templ, sizeof(int)Spt, MPI CHAR,O ALLTOONE TYPE+MylD cl=c2+1 MPI COMM WORLD) c2=(int(cl+c3)2); MPI COMM WORLD) MPI Barrier( while((arr[c2]=c4)&&(c2<n)7 13.5 步骤(3) */ j = 0; for (i=1;i<SumID;i++) MPI_Irecv(&temp1[i*Spt], sizeof(int)*Spt, MPI_CHAR, i,ALLTOONE_TYPE+i, MPI_COMM_WORLD, &request[j++]); MPI_Waitall(SumID-1, request, status); /* 处理器 P0 将上一步送来的 P 段 有序的数据序列做 P 路归并, 再 选 择 排 序 后 的 第 P-1, 2(P-1),…,(P-1)(P-1)个共 P-1 个主元,,对应于算法 13.5 步 骤(3)*/ MPI_Barrier( MPI_COMM_WORLD); quicksort(temp1,0,SumID*Spt-1); MPI_Barrier( MPI_COMM_WORLD); for (i=1;i<Spt+1;i++) temp1[i] = temp1[i*Spt-1]; /*处理器 P0将这 P-1个主元播送到 所有处理器中,对应于算法 13.5 步骤(4)*/ MPI_Bcast(temp1, sizeof(int)*(1+Spt), MPI_CHAR, 0, MPI_COMM_WORLD); MPI_Barrier( MPI_COMM_WORLD); } else { MPI_Send(temp1,sizeof(int)*Spt, MPI_CHAR,0, ALLTOONE_TYPE+MyID, MPI_COMM_WORLD); MPI_Barrier( MPI_COMM_WORLD); MPI_Barrier( MPI_COMM_WORLD); MPI_Bcast(temp1, sizeof(int)*(1+Spt), MPI_CHAR, 0, MPI_COMM_WORLD); MPI_Barrier( MPI_COMM_WORLD); } /*每个处理器根据上步送来的 P-1 个主 元把自己的 n/P 个数据分成 P 段, 记为处理器 Pi 的第 j+1 段,其中 i=0,…,P-1,j=0,…,P-1,对应于算 法 13.5 步骤(5)*/ n = mylength; index[0] = 0; i = 1; while ((arr[0]>=temp1[i])&&(i<SumID)) { index[2*i-1] = 0; index[2*i] = 0; i++; } if (i==SumID) index[2*i-1] = n; c1 = 0; while (i<SumID) { c4 = temp1[i]; c3 = n; c2 = (int)((c1+c3)/2); while ((arr[c2]!=c4)&&(c1<c3)) { if (arr[c2]>c4) { c3 = c2-1; c2 = (int)((c1+c3)/2); } else { c1 = c2+1; c2 = (int)((c1+c3)/2); } } while ((arr[c2]<=c4)&&(c2<n))
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有