// Utilities and system includes
#include <shrUtils.h>
#include "cutil_inline.h"
#include <algorithm>

#include "exo03func.hpp"

///////////////////////////////////////////////////////////////////////////////
// Program main
// Compilation :
//   make
// Execution (exemple):
//   ./exo3 -device=3 -type=double -n=500000001
////////////////////////////////////////////////////////////////////////////////
int
main( int argc, char** argv) {
  int size = 1<<28;    // number of elements to reduce
  int maxThreads = 256;  // number of threads per block
  int maxBlocks = 64;
  int cpuFinalThreshold = 1;
  char *typeChoice;
  ReduceType datatype = REDUCE_INT;

  shrSetLogFileName ("exo03.log");
  shrLog("%s Starting...\n\n", argv[0]);
    
  InitData(argc, argv, typeChoice, datatype, size, maxThreads,
	   maxBlocks, cpuFinalThreshold);  
    
  InitDevice( argc, argv, datatype);

  shrLog("Reducing array of type %s, dimension %d\n\n", typeChoice,size);

  switch (datatype){
    default:
    case REDUCE_INT:
        runExo03<int>(datatype,size,maxThreads,maxBlocks,cpuFinalThreshold);
        break;
    case REDUCE_FLOAT:
        runExo03<float>(datatype,size,maxThreads,maxBlocks,cpuFinalThreshold);
        break;
    case REDUCE_DOUBLE:
        runExo03<double>(datatype,size,maxThreads,maxBlocks,cpuFinalThreshold);
        break;
  }
    
  cudaThreadExit();
  shrEXIT(argc, (const char**)argv);
}
