Exemple #1
0
void convert_spec(char *in,char *out)
{
  SPECTRUM src,dst;

  if (open_spec(&src,in,"I")<0) {
    print_error("Cannot open input file %s",in);
    exit_session(ERR_OPEN);
  }
  else
    if (create_spec(&dst,out,src.npts,src.start,src.step,src.data_type,
                    src.ident,src.cunit)<0) {
      close_spec(&src);
      print_error("Cannot create output file %s",out);
      exit_session(ERR_CREAT);
    }
    else {
      int i;

      for (i=0;i<src.npts;i++) WR_spec(&dst,i,RD_spec(&src,i));

      CP_non_std_desc(&src,&dst);
      close_spec(&dst);
      close_spec(&src);
    }
}
Exemple #2
0
int main(int argc, char **argv) {

  int i;
  /*** COMMAND LINE ARG PARSING BEGIN ***/

  // default values
  char app = WORDCOUNT;
  impl = THREADS;
  int num_maps = -1;
  int num_reduces = -1;
  char *infile = "input/wordcount.input";
  char *outfile = "output/wordcount.output";

  // parsing
  int c;
  static char usage[] = "usage: %s --app [wordcount, sort] --impl [procs, threads] --maps num_maps --reduces num_reduces --input infline --output outfile\n";
  while (1) {
    static struct option long_options[] =
    {
      {"app",      required_argument, 0, 'a'}, // [wordcount, sort]
      {"impl",     required_argument, 0, 'b'}, // [procs, threads]
      {"maps",     required_argument, 0, 'c'}, // num_maps
      {"reduces",  required_argument, 0, 'd'}, // num_reduces
      {"input",    required_argument, 0, 'e'}, // infile
      {"output",   required_argument, 0, 'f'}, // outfile
      {0, 0, 0, 0}
    };
    int option_index = 0;
    c = getopt_long (argc, argv, "a:b:c:d:e:f",
                     long_options, &option_index);

    // check for end of arguments
    if (c == -1)
      break;
    // set & configure
    switch (c) {
      case 'a': // --app
        if (strcmp(optarg, "wordcount") == 0 )
          app = WORDCOUNT;
        else if (strcmp(optarg, "sort") == 0)
          app = SORT;
        // additional apps go here
        else {
          fprintf(stderr, usage, argv[0]);
          exit(1);
        }
        break;
      case 'b': // --impl
        if (strcmp(optarg, "procs") == 0 )
          impl = PROCS;
        else if (strcmp(optarg, "threads") == 0)
          impl = THREADS;
        else {
          fprintf(stderr, usage, argv[0]);
          exit(1);
        }
        break;
      case 'c': // --maps
        num_maps = atoi(optarg);
        break;
      case 'd': // --reduces
        num_reduces = atoi(optarg);
        break;
      case 'e': // --infile
        infile = optarg;
        break;
      case 'f': // --outfile
        outfile = optarg;
        break;
      case '?':
        break;
      default:
        abort();
    }
  }
  /*** COMMAND LINE ARG PARSING END ***/

#ifdef DEBUG
  printf("\n[DEBUG ENABLED]\n\n");
  // print options
  printf("##################\n");
  printf("# MAPRED OPTIONS #\n");
  printf("##################\n");
  if (app == WORDCOUNT)
    printf("# app:      WORDCOUNT  \n", app);
  else if (app == SORT)
    printf("# app:      SORT  \n", app);
  if (impl == PROCS)
    printf("# impl:     PROCS  \n", impl);
  else if (impl == THREADS)
    printf("# impl:     THREADS  \n", impl);
  printf("# maps:     %d  \n", num_maps);
  printf("# reduces:  %d  \n", num_reduces);
  printf("# infile:   %s  \n", infile);
  printf("# outfile:  %s  \n", outfile);
#endif

  spec_t *spec = create_spec();
  if (num_maps > 0)
    spec->maps = num_maps;
  else
    spec->maps = DEFAULT_MAPS;
  if (num_reduces > 0)
    spec->reduces = num_reduces;
  else
    spec->reduces = DEFAULT_REDUCES;

  // function pointers for read, write, compare, map, and reduce
  void (*map)(void*, void*, spec_t*);
  int (*compare)(void*, void*);
  void (*reduce)(void*, void*, spec_t*, int, int);

  // get app-specific functions for read, write, compare, map, and reduce
  switch (app) {
    case WORDCOUNT:
      map = &wc_map;
      reduce = &wc_reduce;
      compare = &wc_compare;
      spec->work = MAP_REDUCE;
      break;
    case SORT:
      map = &is_map;
      //reduce = &is_reduce;
      compare = &is_compare;
      spec->work = MAP_SORT;
      break;
  }
#ifdef TIME
  clock_t start, end;
#endif

  // READ
#ifdef DEBUG
  printf("\n##############\n");
  printf("# READ START #\n");
  printf("##############\n");
#endif
#ifdef TIME
  start = clock();
#endif
  reader(spec, infile);
#ifdef TIME
  end = clock();
  printf("READ: %.2fms\n", (double)(end-start)/CLOCKS_PER_SEC*1000);
#endif
#ifdef WCDEBUG
  wc_debug(spec, INPUT);
#endif

  // MAP
#ifdef DEBUG
  printf("\n################\n");
  printf("# MAPPER START #\n");
  printf("################\n");
#endif
#ifdef TIME
  start = clock();
#endif
  for (i = 0; i < spec->inputRecords; i += spec->maps)
    mapper(spec, map, i);
#ifdef TIME
  end = clock();
  printf("MAP: %.2fms\n", (double)(end-start)/CLOCKS_PER_SEC*1000);
#endif
#ifdef WCDEBUG
  wc_debug(spec, INTER);
#endif

// SORT/GROUP
#ifdef DEBUG
  printf("\n##############\n");
  printf("# SORT START #\n");
  printf("##############\n");
#endif
#ifdef TIME
  start = clock();
#endif
  sort(spec, compare);
#ifdef TIME
  end = clock();
  printf("SORT/GROUP: %.2fms\n", (double)(end-start)/CLOCKS_PER_SEC*1000);
#endif
#ifdef WCDEBUG
  wc_debug(spec, INTER);
#endif

  // REDUCE
#ifdef DEBUG
  printf("\n################\n");
  printf("# REDUCER START #\n");
  printf("################\n");
#endif
#ifdef TIME
  start = clock();
#endif
  for (i = 0; i < spec->interRecords; i += spec->reduces)
    reducer(spec, reduce, i);
#ifdef TIME
  end = clock();
  printf("REDUCE: %.2fms\n", (double)(end-start)/CLOCKS_PER_SEC*1000);
#endif
#ifdef WCDEBUG
  wc_debug(spec, OUTPUT);
#endif

  // WRITE
#ifdef DEBUG
  printf("\n###############\n");
  printf("# WRITE START #\n");
  printf("###############\n");
#endif
#ifdef TIME
  start = clock();
#endif
  writer(spec, outfile);
#ifdef TIME
  end = clock();
  printf("WRITE: %.2fms\n", (double)(end-start)/CLOCKS_PER_SEC*1000);
#endif

  // clean up
#ifdef DEBUG
  printf("\n############\n");
  printf("# CLEAN UP #\n");
  printf("############\n");
#endif
  destroy_spec(spec, INPUT);
  destroy_spec(spec, INTER);
  destroy_spec(spec, SPEC);

#ifdef DEBUG
  printf("\nDONE\n");
#endif

  pthread_exit(NULL);
  return 0;
}