OpenMPI: I want to read a file on the root node and send the contents of that file to all other nodes. I have found that MPI_Bcast does that :
int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype,
int root, MPI_Comm comm)
All the examples that I have found have the count
value already known, but in my case, the count value is primarily known on the root. Other examples say the same call of MPI_Bcast retrieves data on the other nodes.
I've added this:
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);
When I call it like this : mpirun -np 2 ./mpi_hello_world
it works ok, but when I call it with more than 2, I get this:
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.