You are making a very typical mistake. The MPI_Bcast
operation requires that an already allocated array is passed as its first argument at both the root and at all other ranks. Therefore the code has to be modified, e.g. like this:
// Allocate the array everywhere
a = (float*) calloc(9,sizeof(float));
// Initialise the array at rank 0 only
if (nid == 0)
{
for (int i = 0; i < 9; i++)
{
a[i] = i;
}
}