【问题标题】:MPI communicator errorMPI 通讯器错误
【发布时间】:2011-12-16 11:37:32
【问题描述】:

我在使用 MPI 的程序时遇到了问题,我刚刚修复了它,但是,我一开始似乎不明白出了什么问题。我对编程相关的东西很陌生,所以请原谅。

程序是:

#include <iostream>
#include <cstdlib>
#include <mpi.h>

#define RNumber     3

using namespace std;

int main() {
    /*Initiliaze MPI*/
    int     my_rank;    //My process rank
    int         comm_sz;    //Number of processes
    MPI_Comm    GathComm;   //Communicator for MPI_Gather
    MPI_Init(NULL, NULL);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
    MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);

    /*Initialize an array for results*/
    long rawT[RNumber];
    long * Times = NULL;        //Results from threads
    if (my_rank == 0) Times = (long*) malloc(comm_sz*RNumber*sizeof(long));

    /*Fill rawT with results at threads*/
    for (int i = 0; i < RNumber; i++) {
        rawT[i] = i;
    }


    if (my_rank == 0) {
        /*Main thread recieves data from other threads*/
        MPI_Gather(rawT, RNumber, MPI_LONG, Times, RNumber, MPI_LONG, 0, GathComm);

    }
    else {
        /*Other threads send calculation results to main thread*/
        MPI_Gather(rawT, RNumber, MPI_LONG, Times, RNumber, MPI_LONG, 0, GathComm);
    }

    /*Finalize MPI*/
    MPI_Finalize();
    return 0;
};

程序在执行时返回以下消息:

PMPI_Gather 中的致命错误:无效的通信器,错误堆栈: PMPI_Gather(863): MPI_Gather(sbuf=0xbf824b70, scount=3, MPI_LONG, rbuf=0x98c55d8, rcount=3, MPI_LONG, root=0, comm=0xe61030) 失败 PMPI_Gather(757):无效的通信器 PMPI_Gather 中的致命错误: 无效的通信器,错误堆栈:PMPI_Gather(863): MPI_Gather(sbuf=0xbf938960, scount=3, MPI_LONG, rbuf=(nil), rcount=3, MPI_LONG, root=0, comm=0xa6e030) 失败 PMPI_Gather(757): 无效 沟通者

在我完全删除 GathComm 并将其替换为 MPI_COMM_WORLD 默认通信器后,一切正常。

谁能解释一下我做错了什么以及这个调整是如何让一切正常的?

【问题讨论】:

    标签: c++ mpi parallel-processing


    【解决方案1】:

    那是因为GathComm 没有被分配一个有效的通讯器。 "MPI_Comm GathComm;" 只声明变量来保存一个通信器,但不创建一个。

    如果您只想在操作中包含所有 proc,可以使用默认通信器 (MPI_COMM_WORLD)。

    当你想将你的进程组织在不同的组中或使用virtual communication topologies.时,自定义通信器很有用

    要了解更多信息,请查看描述组、通信器和拓扑的 this article

    【讨论】:

      猜你喜欢
      • 2019-07-23
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 2014-01-25
      • 2016-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多