#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <math.h>
#include <gsl/gsl_math.h>
#include "petaio.h"

#include "allvars.h"
#include "proto.h"
#include "param.h"
#include "config.h"
#include "endrun.h"
#include "fof.h"

int main(int argc, char **argv)
{
    int Ntask, ThisTask;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
    MPI_Comm_size(MPI_COMM_WORLD, &NTask);

    if(ThisTask == 0)
    {
       printf("Running on %d MPI Ranks.\n", NTask);
       printf("           %d OpenMP Threads.\n", omp_get_max_threads());

    }
    read_parameter_file(argv[1]);       /* ... read in parameters for this run */
    int RestartFlag, RestartSnapNum;
    RestartFlag = atoi(argv[2]);    
    RestartSnapNum = atoi(argv[3]);
    read_IDdata(RestartSnapNum);
    MPI_Finalize();
    return 0;
}

read_IDdata(int RestartSnapNum)
{
  size_t n = All.MaxMemSizePerCore * All.NumThreads * ((size_t) 1024 * 1024);
  mymalloc_init(n);
  petaio_init();
  petaio_read_snapshot(RestartSnapNum);
  message(0, " domain garbage\n");
  domain_garbage_collection();
  message(0, "Testing ID Uniqueness before domain decompose\n");
  test_id_uniqueness();
}