【发布时间】:2015-03-11 17:01:00
【问题描述】:
OpenMPI:我想读取根节点上的文件并将该文件的内容发送到所有其他节点。 我发现 MPI_Bcast 可以做到这一点:
int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype,
int root, MPI_Comm comm)
我发现的所有示例都具有已知的 count 值,但在我的例子中,计数值主要在根上是已知的。其他 examples 说 MPI_Bcast 的相同调用检索其他节点上的数据。
我已经添加了这个:
typedef short Descriptor[128];
MPI_Datatype descriptorType;
MPI_Type_contiguous(sizeof(Descriptor), MPI_SHORT, &descriptorType);
MPI_Type_commit(&descriptorType);
if(world_rank == 0) {
struct stat finfo;
if(stat(argv[1], &finfo) == 0) {
querySize = finfo.st_size/sizeof(Descriptor);
}
{
//read binary query
queryDescriptors = new Descriptor[querySize];
fstream qFile(argv[1], ios::in | ios::binary);
qFile.read((char*)queryDescriptors, querySize*sizeof(Descriptor));
qFile.close();
}
}
MPI_Bcast((void*)&querySize, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (world_rank != 0)
{
queryDescriptors = new Descriptor[querySize];
}
MPI_Bcast((void*)queryDescriptors, querySize, descriptorType, 0, MPI_COMM_WORLD);
当我这样调用它时:mpirun -np 2 ./mpi_hello_world 它工作正常,但是当我用超过 2 调用它时,我得到这个:
mpi_hello_world: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
mpi_hello_world: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
【问题讨论】:
-
所以发出两个广播,第一个带有计数,第二个带有缓冲区内容。
-
你是对的,这是一个解决方案。我想知道 MPI 中是否有针对这种情况的机制。
-
我不知道,但我的 MPI 有点生锈了。
-
马克是对的——唯一的解决办法是使用两个广播。与常规的点对点通信不同,MPI 无法提前探测广播消息。事实上,这也适用于所有集体电话,例如
MPI_SCATTER、MPI_GATHER等 -
我使用了 Mark 指出的解决方案,但由于第二个 MPI_Bcast,querySize 为 23,我收到此错误。我正在处理单个节点,这会是一个问题吗?