我有一个奇怪的问题,我在MPI Bcast的缓冲区中打包的值与已解压缩的值不同。
我不确定这可能是由什么造成的。第一个打包值(MTD)始终是正确的,但之后的那些非常关闭。
我需要其中一个值(维度)用于动态内存分配,其结果会导致我的程序崩溃。
如果任何熟悉MPI的人都可以把目光投向我,我将永远感激不尽!
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);
}
MPI_Unpack(buffer, buff_size, &position, &d->max_tree_depth, 1,
MPI_INT, MPI_COMM_WORLD);
MPI_Unpack(buffer, buff_size, &position, &d->bit_depth, 1,
MPI_INT, MPI_COMM_WORLD);
MPI_Unpack(buffer, buff_size, &position, &d->dimensions, 1,
MPI_INT, MPI_COMM_WORLD);
MPI_Unpack(buffer, buff_size, &position, &d->origin, 1,
MPI_INT, MPI_COMM_WORLD);
MPI_Unpack(buffer, buff_size, &position, &d->colour_max, 1,
MPI_FLOAT, MPI_COMM_WORLD);
fprintf(stderr, "%d: MTD: %d\n", me, d->max_tree_depth);
fprintf(stderr, "%d: BitDepth: %d\n", me, d->bit_depth);
fprintf(stderr, "%d: DIM: %d\n", me, d->dimensions);
fprintf(stderr, "%d: ORIGIN: %d\n", me, d->origin);
....
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);
}
fprintf(stderr, "%d: MTD: %d\n", 0, d->max_tree_depth);
fprintf(stderr, "%d: BitDepth: %d\n", 0, d->bit_depth);
fprintf(stderr, "%d: DIM: %d\n", 0, d->dimensions);
fprintf(stderr, "%d: ORIGIN: %d\n", 0, d->origin);
以下输出上述相关值。根值(0 :)是正在打包的内容:
Broadcasting Shared Data
0: MTD: 2
0: BitDepth: 24
0: DIM: 19
0: ORIGIN: 9
3: MTD: 2
3: BitDepth: 32536
3: DIM: 11816240
3: ORIGIN: 0
3: Done Recieving SharedData
1: MTD: 2
1: BitDepth: 32536
1: DIM: 30698800
1: ORIGIN: 0
1: Done Recieving SharedData
1: ALLOCATING KERNEL
2: MTD: 2
2: BitDepth: 32536
2: DIM: 27622704
2: ORIGIN: 0
2: Done Recieving SharedData