#include<mpi.h>
#include<stdlib.h>

void allpossregs(float *u,float *v,int n,int np,int r,
   float *adjr2);

int me; //Stores MPI rank

float timediff(struct timespec t1, struct timespec t2)
{  
  if (t1.tv_nsec > t2.tv_nsec) 
  {
    t2.tv_sec -= 1;
    t2.tv_nsec += 1000000000;
   }
   return t2.tv_sec-t1.tv_sec + 0.000000001 * (t2.tv_nsec-t1.tv_nsec);
}


void init(int argc, char **argv)
{  
   int i;
   MPI_Init(&argc,&argv);
   MPI_Comm_size(MPI_COMM_WORLD,&nnodes);
   MPI_Comm_rank(MPI_COMM_WORLD,&me);
}

int number_subsets(int np, int r)
{
  //return sum_{k = 0}^{r} np \choose r
}

int main(int argc, char** argv)
{
  //This is a simple version. It is possible to extend this easily to
  //make it call allpossregs() multiple times, possibly with different 
  //values for u, v etc.

  float *u= 0, *v=0, *adjr2 = 0;
  int n,int np,int r;
  //Code to read in n, np and r from commandline or a file.

  init(argc, argv);
  if(me == 0)
  {
    u = malloc(n*np1*sizeof(float));
    v = malloc(n*sizeof(float));
    adjr = malloc(number_subsets(np, r)*sizeof(float)) ;
    //Read in u, v from the file
  }
  
  clock_gettime(CLOCK_REALTIME, &bgn);

  allpossregs(u, v, n, np, r, adjr2);

  clock_gettime(CLOCK_REALTIME, &nd);
  printf("%f\n",timediff(bgn,nd));

  if (me == 0)
  {
    //do something with adjr
  }

  //Do something else

  MPI_Finalize();
}
