簡體   English   中英

致命錯誤:MPI_Gatherv

[英]Fatal error: MPI_Gatherv

我是MPI的新手,嘗試使用MPI_Gatherv。 有兩個問題,首先,該功能無法從所有處理器中收集所有項目,有時會給我致命錯誤。 我不明白發生了什么!

每個處理器都有一個向量,其中包含最小數目的索引,每個處理器中向量的大小可能不同。

哪一部分錯了? 任何幫助,將不勝感激。

我的代碼:

MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
vector<int> localMin;
for (int i=0; i<numPerProc; i++)
{
    if (receive_buffer[i]==min) {
        int adjIndex=numPerProc*my_rank+i;
        localMin.push_back(adjIndex);
    }
}
// I thought I might be better use array instead of vector:
int nelements=localMin.size();
int* localMinArray=new int[nelements];
for (int i=0; i<nelements; i++) {
    localMinArray[i]=localMin[i];
}

int *counts = new int[comm_size];

// Each process tells the root how many elements it holds
MPI_Gather(&nelements, 1, MPI_INT, counts, 1, MPI_INT, 0, MPI_COMM_WORLD);

// Displacements in the receive buffer for MPI_GATHERV
int *disps = new int[comm_size];
// Displacement for the first chunk of data - 0
for (int i = 0; i < comm_size; i++)
    disps[i] = (i > 0) ? (disps[i-1] + counts[i-1]) : 0;

int *allMin;
if (my_rank == 0)
    // disps[size-1]+counts[size-1] == total number of elements
    allMin = new int[disps[comm_size-1]+counts[comm_size-1]];


// Collect everything into the root
MPI_Gatherv(&localMinArray, nelements, MPI_INT, &allMin, counts, disps, MPI_INT, 0, MPI_COMM_WORLD);

結果是這樣的:

Vector values in Rank  0: 4,11,
Vector values in Rank  1: 
Vector values in Rank  2: 24,31,
count values:
2,0,2,
disps values:
0,2,2,
allMin values:
4,11,0,-268435456,

這些是我有時會得到的錯誤:

*** An error occurred in MPI_Gatherv
*** reported by process [3485859841,1]
*** on communicator MPI_COMM_WORLD
*** MPI_ERR_COUNT: invalid count argument
*** MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort,
***    and potentially your MPI job)

我通過以下更改解決了該問題:

 MPI_Gatherv(*&localMinArray, nelements, MPI_INT,*&allMin, counts, disps, MPI_INT, 0, MPI_COMM_WORLD);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM