計算後,使用笛卡爾拓撲將矩陣與矢量相乘。我用他們的等級和向量得到以下過程。在MPI中按元素明智地收集和收集元素
P0 (process with rank = 0) =[2 , 9].
P1 (process with rank = 1) =[2 , 3]
P2 (process with rank = 2) =[1 , 9]
P3 (process with rank = 3) =[4 , 6].
現在。我需要分別總結偶數等級過程的奇數那些的元素和,如下所示:
temp1目錄= [3,18]
TEMP2 = [6,9]
,然後,收集結果在不同的載體,就像這樣:
result = [3 , 18 , 6 , 9]
我attampt做到這一點是使用MPI_Reduce然後MPI_Gather這樣的:
// Previous code
double* temp1 , *temp2;
if(myrank %2 == 0){
BOOLEAN flag = Allocate_vector(&temp1 ,local_m); // function to allocate space for vectors
MPI_Reduce(local_y, temp1, local_n, MPI_DOUBLE, MPI_SUM, 0 , comm);
MPI_Gather(temp1, local_n, MPI_DOUBLE, gResult, local_n, MPI_DOUBLE,0, comm);
free(temp1);
}
else{
Allocate_vector(&temp2 ,local_m);
MPI_Reduce(local_y, temp2, local_n , MPI_DOUBLE, MPI_SUM, 0 , comm);
MPI_Gather(temp2, local_n, MPI_DOUBLE, gResult, local_n, MPI_DOUBLE, 0,comm);
free(temp2);
}
但答案不correct.It seemd該代碼求和偶數和奇數處理togather的所有元素,然後給出一個分段錯誤: Wrong_result = [21 15 0 0] 和此錯誤
** Error in
./test': double free or corruption (fasttop): 0x00000000013c7510 *** *** Error in
./test': double free or corruption (fasttop): 0x0000000001605b60 ***
請參閱[如何創建最小,完整和可驗證的示例](https://stackoverflow.com/help/mcve) – Arash