2016-09-05 5 views
0

MPIを使用して、4つの整数と1つの浮動小数点を含むパックされたメッセージをブロードキャストしています。MPI_UNPACK切り捨て、無効なバッファサイズ

私のバッファサイズの計算方法が間違っていますか?私は、この関数のMPI_BCastにメッセージを切り捨てました。これは、私のバッファサイズが受信データを格納するのに十分な大きさでないことを意味するはずです。

Iveはデータの送信/パッキングのためのバッファサイズを全く同じ方法で計算しました。

void bcast_sharedData(SharedData *d) { 
     fprintf(stderr, "Broadcasting Shared Data\n"); 

     int position = 0; 
     int buff_size = sizeof(int) * 4 + sizeof(float); 
     char * buffer = malloc(buff_size); 

     int result = MPI_SUCCESS; 
     while(result == MPI_SUCCESS) { 
      result = MPI_Pack(&d->max_tree_depth, 1, MPI_INT, buffer, 
           buff_size, &position, MPI_COMM_WORLD); 
      result = MPI_Pack(&d->bit_depth, 1, MPI_INT, buffer, buff_size, 
           &position, MPI_COMM_WORLD); 
      result = MPI_Pack(&d->dimensions, 1, MPI_INT, buffer, buff_size, 
           &position, MPI_COMM_WORLD); 
      result = MPI_Pack(&d->origin, 1, MPI_INT, buffer, buff_size, 
           &position, MPI_COMM_WORLD); 
      result = MPI_Pack(&d->colour_max, 1, MPI_FLOAT, buffer, 
           buff_size, &position, MPI_COMM_WORLD); 
      break; 
     } 

     if (result != MPI_SUCCESS) { 
      fprintf(stderr, 
        "ID 0: Could not Pack Shared Data for Broadcasting"); 
      MPI_Abort(MPI_COMM_WORLD, -1); 
     } 

     if (MPI_Bcast(
      buffer, 5, MPI_PACKED, 0, MPI_COMM_WORLD) != MPI_SUCCESS) { 

      fprintf(stderr, "ID 0: Could not Broadcast Shared Data\n"); 
      MPI_Abort(MPI_COMM_WORLD, -1); 
     }; 

     MPI_Barrier(MPI_COMM_WORLD); 

     fprintf(stderr, "Broadcasting Kernel\n"); 
     if (MPI_Bcast(
      &d->kernel, d->dimensions, MPI_FLOAT, 0, MPI_COMM_WORLD) != MPI_SUCCESS) { 

      fprintf(stderr, "ID 0: Could not Broadcast Shared Data -> Kernel\n"); 
      MPI_Abort(MPI_COMM_WORLD, -1); 
     } 

     MPI_Barrier(MPI_COMM_WORLD); 
     fprintf(stderr, "DONE Broadcasting Kernel\n"); 
    } 

    void recv_sharedData(int me, SharedData *d) { 
     fprintf(stderr, "%d: RECEIVING SHARED DATA\n", me); 
     int buff_size = sizeof(int) * 4 + sizeof(float); 
     char * buffer = malloc(buff_size); 
     int position = 0; 

     if (MPI_Bcast(
       buffer, 5, MPI_PACKED, 0, MPI_COMM_WORLD) != MPI_SUCCESS) { 
      fprintf(stderr, "ID %d: Could not receive SharedData", me); 
      MPI_Abort(MPI_COMM_WORLD, -1); 
     } 

     fprintf(stderr, "%d: UNPACKING SHARED DATA\n", me); 
     MPI_Unpack(buffer, 1, &position, &d->max_tree_depth, buff_size, 
      MPI_INT, MPI_COMM_WORLD); 
     MPI_Unpack(buffer, 1, &position, &d->bit_depth, buff_size, 
      MPI_INT, MPI_COMM_WORLD); 
     MPI_Unpack(buffer, 1, &position, &d->dimensions, buff_size, 
      MPI_INT, MPI_COMM_WORLD); 
     MPI_Unpack(buffer, 1, &position, &d->origin, buff_size, 
      MPI_INT, MPI_COMM_WORLD); 
     MPI_Unpack(buffer, 1, &position, &d->colour_max, buff_size, 
      MPI_FLOAT, MPI_COMM_WORLD); 

     MPI_Barrier(MPI_COMM_WORLD); 
     fprintf(stderr, "%d: Done Recieving SharedData\n", me); 

     d->kernel = (float **) malloc (d->dimensions * sizeof (float *)); 
     int i; 
     for (i = 0; i < d->dimensions; i++) 
     { 
      d->kernel[i] = (float *) malloc (d->dimensions * sizeof (float)); 
     } 

     if (MPI_Bcast(
      d->kernel, d->dimensions, MPI_FLOAT, 0, MPI_COMM_WORLD) != MPI_SUCCESS) { 
      fprintf(stderr, "ID %d: Could not receive SharedData->kernel", me); 
     } 

     MPI_Barrier(MPI_COMM_WORLD); 
     fprintf(stderr, "%d: Done Recieving SharedData->Kernel\n", me); 
    } 

答えて

0

私は「BUFFSIZE」(引数5)と間違った順序で(ARG2)「を解凍する項目を」持っていた - 彼らは切り替えされている必要があります。

関連する問題