仅在某些情况下,“主要作业正常终止,但1个进程返回了非零的退出代码”

时间:2019-01-14 15:04:51

标签: c mpi

下午好,我已经出于科学目的在MPI中开发了2D FFT。 在实现MPI_Scatterv之前,一切都可以正常工作。 自从我实现了它以来,发生了一些奇怪的事情。特别是,如果我保持在64种模式下,我不会遇到任何问题,但是当我将其推到上面时,会收到消息:

> Primary job  terminated normally, but 1 process returned
> a non-zero exit code. Per user-direction, the job has been aborted.
>-------------------------------------------------------------------------- 

>mpiexec noticed that process rank 0 with PID 0 on node MacBook-Pro-di-Mirco
>exited on signal 11 (Segmentation fault: 11).`

我不知道错误出在哪里,但是我很确定它在MPI_Scatterv中。 有人可以帮我吗?

/********************************** Setup factors for scattering **********************************/
  // Alloc the arrays
  int* displs = (int *)malloc(size*sizeof(int));
  int* scounts = (int *)malloc(size*sizeof(int));
  int* receive = (int *)malloc(size*sizeof(int));

  // Setup matrix
  int modes_per_proc[size];
  for (int i = 0; i < size; i++){
  modes_per_proc[i] = 0;
  }


  // Set modes per processor
  cores_handler( nx*nz, size, modes_per_proc);

  // Scattering parameters
  for (int i=0; i<size; ++i) {
  scounts[i] = modes_per_proc[i]*ny*2;
  receive[i] = scounts[i];
  displs[i] = displs[i-1] + modes_per_proc[i-1] *ny*2;  // *2 to handle complex numbers
  if (i == 0 ) displs[0] = 0;
   }


   /************************************************ Data scattering ***********************************************/
  MPI_Scatterv(U, scounts, displs, MPI_DOUBLE, u, receive[rank] , MPI_DOUBLE, 0, MPI_COMM_WORLD);
  MPI_Barrier(MPI_COMM_WORLD);

core_handler函数:

void cores_handler( int modes, int size, int modes_per_proc[size]) {
int rank =0;
int check=0;

for (int i = 0; i < modes; i++) {
    modes_per_proc[rank] = modes_per_proc[rank]+1;
    rank = rank+1;
    if (rank == size ) rank = 0;
}

for (int i = 0; i < size; i++){
//printf("%d modes on rank %d\n", modes_per_proc[i], i);
check = check+modes_per_proc[i];
}
if ( (int)(check - modes) != 0 ) {
        printf("[ERROR] check - modes = %d!!\nUnable to scatter modes properly\nAbort... \n", check - modes);
}

0 个答案:

没有答案