pmpi_gather中的致命错误

时间:2013-09-27 18:02:10

标签: c++ runtime-error openmpi mpich

所以我有一个我正在写的光线跟踪器编译得很好,但是当我到达MPI_Gather()函数时,我得到了这个错误集。如果我写入文件,整个过程就会很好,但是我无法在分布式计算系统上运行它。

Fatal error in PMPI_Gather: Internal MPI error!, error stack:
PMPI_Gather(856)......:
   MPI_Gather(sbuf=0x8e05468, scount=882000, MPI_BYTE, rbuf=0x8df7628, rcount=882000, MPI_BYTE, root=0, MPI_COMM_WORLD) failed
MPIR_Gather_impl(681).: 
MPIR_Gather(641)......: 
MPIR_Gather_intra(152): 
MPIR_Localcopy(378)...:
   memcpy arguments alias each other, dst=0x8df7628 src=0x8e05468 len=882000

===================================================================================
=   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
=   EXIT CODE: 1
=   CLEANING UP REMAINING PROCESSES
=   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
===================================================================================

我不确定这个错误意味着什么,所以很难解决它。

以下是主要功能的来源:

int main(int argc, char **argv) {
  clock_t total_time = clock(), otime;
  init_MPI(argc, argv);   //Initialize OpenMPI
  glutInit(&argc,argv);

  get_params(argc, argv);   //Get parameters from command line
  if (buildScene(scene, cam) == -1) MPI_Abort(MPI_COMM_WORLD,rc); exit(1);
  samples = samples > 0 ? whitted ? 1 : samples : 1;
  if (numprocs == 1) {
    scn = new RGBApixmap(h,w);
    raytrace(h,scn);
    if (smult > 1) *scn = scaleImage(scn,smult);
  } else {
    int rows = h / numprocs;
    subscn = new RGBApixmap(rows,w);
    raytrace(rows, subscn);
    if (smult > 1) *subscn = scaleImage(subscn,smult);

    if (pid == MASTER) scn = new RGBApixmap(h/smult,w/smult);
    MPI_Gather(subscn,rows/smult*w,MPI_BYTE,scn,rows/smult*w,MPI_BYTE,MASTER,MPI_COMM_WORLD);
  }
  if (pid == MASTER) {
    initGlut(argc, argv);
    glutMainLoop();
  }
  MPI_Finalize();
  return 0;
}

编辑:

我已修复此问题并在下方发布了更新的代码:

int main(int argc, char **argv) {
  clock_t total_time = clock(), otime;
  init_MPI(argc, argv);
  glutInit(&argc,argv);    
  bool OK = get_params(argc, argv);
  if (buildScene(scene, cam) == -1) { MPI_Abort(MPI_COMM_WORLD,rc); exit(1); }
  samples = samples > 0 ? whitted ? 1 : samples : 1;
  int rows = h / numprocs;
  subscn = new RGBApixmap(rows,w);
  raytrace(rows, subscn);
  MPI_Barrier(MPI_COMM_WORLD);          /* Synchronize all processes */   
  if (smult > 1) *subscn = scaleImage(subscn,smult); 
  MPI_Barrier(MPI_COMM_WORLD);          /* Synchronize all processes */

  int nElts = subscn->getWidth()*subscn->getHeight();
  RGBA *subscnpix, *scnpix;
  subscnpix = subscn->getPixs();
  scnpix = (RGBA*)malloc(sizeof(RGBA)*((w/smult)*(h/smult)));

  MPI_Datatype pixel;
  MPI_Type_contiguous(4,MPI_UNSIGNED_CHAR,&pixel);
  MPI_Type_commit(&pixel);

  MPI_Gather(subscnpix,nElts,pixel,scnpix,nElts,pixel,MASTER,MPI_COMM_WORLD);

  scn = new RGBApixmap(h/smult,w/smult,scnpix);

  MPI_Type_free(&pixel);

  MPI_Barrier(MPI_COMM_WORLD);          /* Synchonize all processes */
  if (pid == MASTER) {
    initGlut(argc, argv);
    glutMainLoop();
  }
  MPI_Finalize();
  return 0;
}

1 个答案:

答案 0 :(得分:2)

您在MPI_GatherMASTER的调用中的发送和接收缓冲区重叠,这违反了MPI标准规定的限制。 subscn位于0x8e05468,而scn位于0x8df7628。从0x8df76280x8e05468的内存跨度仅为56896个字节,并且您尝试写入882000次numprocs个字节,这将无效。

这是因为您将行数除以比例因子,但仍然忘记将图像宽度w除以比例因子。

MPI_Gather(subscn, rows/smult*w/smult, MPI_BYTE,
           scn, rows/smult*w/smult, MPI_BYTE,
           MASTER, MPI_COMM_WORLD);

请注意,如果像素图不是灰度,则还必须将数据元素的数量乘以颜色分量的数量(可能还要计算alpha通道),或者创建一个连续的派生数据类型。