簡體   English   中英

如何用 0xC0000005 修復 MPI_Gatherv 問題

[英]How to fix the MPI_Gatherv problem with 0xC0000005

社區中的第一個問題,如果我的格式有任何問題,請告訴我。

我正在使用 MPI_Gatherv 來收集數據。 我可能需要收集像 vector<vector> 這樣的東西。 我聽說 MPI_Gatherv 只能做向量,所以我決定一個向量一個向量地發送數據。 下面是我的想法的例子。 但是,它在 MPI_Finalize() 中失敗,並顯示為 0xC0000005。 如果我刪除 MPI_Gatherv(&c,count.at(i),MPI_INT,&temre,&count.at(i),displs,MPI_INT,0,MPI_COMM_WORLD),它會起作用。 我想知道它是否與地址沖突有關。 謝謝你的幫助!

int main(int argc, char *argv[]) {

    MPI_Init(&argc, &argv);

    int gsize;
    int myrank;

    MPI_Comm_size(MPI_COMM_WORLD, &gsize);
    MPI_Comm_rank(MPI_COMM_WORLD, &myrank);

    vector<vector<int>> a,reci;
    vector<int> count(1,10);
    vector<int> b(10,1),NU(1,0);
    a.push_back(b);
    reci.push_back(NU);
    for ( int i = 0; i < myrank*3+2; i++ )
    {
        b.push_back(i); 
        count.push_back(11+i);
        a.push_back(b);
        reci.push_back(NU);
    }

    vector<int> c,temre(1,1);
    int displs[1]={0};

    for ( int i = 0; i < myrank*3+3; i++ )
    {
        c = a.at(i);
        MPI_Gatherv(&c,count.at(i),MPI_INT,
            &temre,&count.at(i),displs,MPI_INT,0,MPI_COMM_WORLD);
        reci.at(i).swap(temre);
    }

    MPI_Finalize(); 
    return 0;
}

非常感謝您的任何評論和回答。 經過幾天的工作,我發現了錯誤。 對於 MPI 中的矢量,您必須使用 &c[0] 而不是MPI_Gatherv(&c,count.at(i),MPI_INT, &temre,&count.at(i),displs,MPI_INT,0,MPI_COMM_WORLD); (還有 &temre[0] 而不是 &temre)

但是,目前它可以串行工作,但不能並行工作。 我正在嘗試解決問題並放置可執行代碼。 再次感謝任何幫助!

您必須意識到 MPI 嚴格來說是一個 C 庫。 所以你不能直接用std::vector作為緩沖區發送/接收。 您的緩沖區必須是int*或您使用的任何類型。 所以在你的情況下: MPI_Gatherv(c.data(),...

暫無
暫無

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

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