Why am I getting an "invalid data type" error in this sample mpi broadcast program?
<p><em>After making the changes mentioned in the comments, not getting any output.</em></p>

<p>I'm new to MPI. If I run it with more than two processes I get two additional lines on my console saying:</p>

<p>1- more process has sent help message help-mpi-errors.txt / mpi_errors_are_fatal</p>

<p>2- Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages.</p>

<p>What am I doing wrong?
This is the complete output on my terminal:</p>

<blockquote>
  <p>*** An error occurred in MPI_Bcast</p>
  
  <p>*** reported by process [4248174593,1]</p>
  
  <p>*** on communicator MPI_COMM_WORLD</p>
  
  <p>*** MPI_ERR_TYPE: invalid datatype</p>
  
  <p>*** MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort,</p>
  
  <p>***    and potentially your MPI job)</p>
  
  <p>1 more process has sent help message help-mpi-errors.txt / 
  mpi_errors_are_fatal Set MCA parameter "orte_base_help_aggregate" to 0
  to see all help / error messages</p>
</blockquote>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;mpi.h&gt;

int main(int argc, char** argv)
{
    const int server = 0;
    const int source = server;
    float* array = (float*)NULL;
    int length;
    int num_procs, my_rank, mpi_error_code;
    int index;

    mpi_error_code = MPI_Init(&amp;argc, &amp;argv);
    mpi_error_code = MPI_Comm_rank(MPI_COMM_WORLD, &amp;my_rank);
    mpi_error_code = MPI_Comm_size(MPI_COMM_WORLD, &amp;num_procs);

    /*input, allocate, initialize on server only*/
    if(my_rank == server){
      scanf("%d", &amp;length);
      array = (float*) malloc(sizeof(float) * length);
      for(index = 0; index &lt; length; index++){
          array[index] = 0.0;
      }
    }
    /*broadcast, output on all processes*/
    if(num_procs &gt; 1){
      mpi_error_code = MPI_Bcast(&amp;length, 1, MPI_INT, source, MPI_COMM_WORLD);
      if(my_rank != server){
        array = (float*) malloc(sizeof(float) * length);
      }
      mpi_error_code = MPI_Bcast(array, length, MPI_INT, source, MPI_COMM_WORLD);
      printf("%d: broadcast length = %d\n", my_rank, length);
    }

    mpi_error_code = MPI_Finalize();
}
</code></pre>