Exemplo n.º 1
0
extern void malloc_pasl_report(void) {
  printf("malloc_total\t%lld\n",malloc_count_total());
  printf("malloc_peak\t%lld\n",malloc_count_peak());
  printf("malloc_current\t%lld\n",malloc_count_current());
}
Exemplo n.º 2
0
int main(int argc, char* argv[]) {

  if(argc != 3 && argc != 4){
    fprintf(stderr, "Execute: %s <input file> <alphabet size> [<validation_file>]\n", argv[0]);
    exit(-1);
  }

  unsigned long n; // Size of the input sequence
  symbol* text = read_text_from_file(argv[1], &n); // Input sequence
  unsigned int alphabet = (unsigned int)atoi(argv[2]); // Size of the alphabet

  //printf("n: %lu, alphabet: %u, threads: %d\n", n, alphabet, num_threads);

//  printf("%s,%lu,%u,", argv[1], n, alphabet);

  // Memory usage
#ifdef MALLOC_COUNT
  size_t s_total_memory = malloc_count_total();
  size_t s_current_memory = malloc_count_current();
  malloc_reset_peak();

  // Running time. CLOCK_THREAD_CPUTIME_ID: Running time of the thread that call it (main thread in this case)
#else
  struct timespec stime, etime;
  double t;
  if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &stime)) {
    fprintf(stderr, "clock_gettime failed");
    exit(-1);
  }
#endif

  // Wavelet tree construction
#ifdef NO_RANK_SELECT
  BIT_ARRAY** wtree = wt_create(text, n, alphabet);
#else
  bitRankW32Int** wtree = wt_create(text, n, alphabet);
#endif

#ifdef MALLOC_COUNT
  size_t e_total_memory = malloc_count_total();
  size_t e_current_memory = malloc_count_current();
  printf("%s, %u, %zu, %zu, %zu, %zu, %zu\n", argv[1], alphabet, s_total_memory, e_total_memory, malloc_count_peak(), s_current_memory, e_current_memory);

#else
  if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &etime)) {
    fprintf(stderr, "clock_gettime failed");
    exit(-1);
  }

  t = (etime.tv_sec - stime.tv_sec) + (etime.tv_nsec - stime.tv_nsec) / 1000000000.0;
  printf("%d,%s,%lu,%lf\n", __cilkrts_get_nworkers(), argv[1], n, t);
//  printf("%d,%s,%lu\n", __cilkrts_get_nworkers(), argv[1], n); // Merge
#endif

  free(text);

  // Validation mode
  // Generate the original text using the wavelet tree
  if(argc > 3) {
#ifdef NO_RANK_SELECT
    printf("Compile without -DNO_RANK_SELECT to use the validation mode\n");
#else
    FILE *test_file;
    test_file = fopen(argv[3],"wb");

    if (!test_file) {
      printf("Unable to open file!");
      return EXIT_FAILURE;
    }

    symbol access_return = 0;
    unsigned long i = 0;

    if(n*sizeof(symbol) > 10485760)
      printf("Please, use a file smaller than 10MB to validate the algorithm. Otherwise, the validation could take a while.\n");
    else {
      for(i = 0; i < n; i++) {
	access_return =  wt_access(wtree, i, alphabet);
	fwrite(&access_return, sizeof(symbol), 1, test_file);
      }
    }
    fclose(test_file);
#endif
  }

  return EXIT_SUCCESS;
}