hello world MPI C code

/*
 * mpi_demo.c
 *
 * Tyler Simon
 * John C. Linford
 * 26 June 2014
 *
 * Do some CPU intensive work with quicksort
 * Print out usage per MPI rank
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include<mpi.h>


int ascending(const void * a, const void * b)
{
  int temp = *(int*)a - *(int*)b;
  if (temp > 0)
    return 1;
  else if (temp < 0)
    return -1;
  else
    return 0;
}

int descending(const void * a, const void * b)
{
  int temp = *(int*)a - *(int*)b;
  if (temp < 0)
    return 1;
  else if (temp > 0)
    return -1;
  else
    return 0;
}


double cpu_test(char *host,long int size, int rank)
{
  int i;
  double start, elapsed;
  int * nums;

  srand(time(NULL)+rank);

  nums = (int*)malloc(sizeof(int) * size);
  if(!nums){
    printf("ERROR ALLOCING MEM\n");
    exit(1);
  }

  for(i=0; i<size; i++){
    nums[i] = rand();
  }

  start = MPI_Wtime();
  qsort(nums, size, sizeof(int), ascending);
  qsort(nums, size, sizeof(int), descending);
  elapsed = MPI_Wtime() - start;

  return elapsed;
}


int main(int argc, char **argv)
{
  size_t const N=200000000;

  int rank, size;
  size_t sortnum;
  float sendbuf;
  char hostname[255];
  double * elapsed;
  double * sort_time;

  srand48(time(NULL));

  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &size);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  elapsed = (double*)malloc(size*sizeof(double));
  sort_time = (double*)malloc(size*sizeof(double));

  sortnum = N/size;
  gethostname(hostname,255);
  sendbuf=drand48();

  if(rank == 0) {
    printf("#[rank] [runtime] [sort_time] [host] [buffvalue] [nums_sorted]\n");
  }

  elapsed[rank] = MPI_Wtime();
  MPI_Bcast(&sendbuf, 1, MPI_FLOAT, 0, MPI_COMM_WORLD);
  sort_time[rank] = cpu_test(hostname,sortnum,rank);
  elapsed[rank] = MPI_Wtime() - elapsed[rank];
  printf("%d %g %g %s %f %ld\n", rank, elapsed[rank], sort_time[rank], hostname, sendbuf, sortnum);

  MPI_Finalize();
  return 0;
}