Example #1
0
/*
 * init_fsecs - initialize the timing package
 */
void init_fsecs(void)
{
	Mhz = 0; /* keep gcc -Wall happy */

#if USE_FCYC
	if (verbose)
		printf("Measuring performance with a cycle counter.\n");

	/* set key parameters for the fcyc package */
	set_fcyc_maxsamples(20); 
	set_fcyc_clear_cache(1);
	set_fcyc_compensate(1);
	set_fcyc_epsilon(0.01);
	set_fcyc_k(3);
	Mhz = mhz(verbose > 0);
#elif USE_ITIMER
	if (verbose)
		printf("Measuring performance with the interval timer.\n");
#elif USE_GETTOD
	if (verbose)
		printf("Measuring performance with gettimeofday().\n");
#endif
}
Example #2
0
int main(int argc, char *argv[])
{
  int i;
  int quit_after_dump = 0;
  int skip_studentname_check = 0;
  int autograder = 0;
  int seed = 1729;
  char c = '0';
  char *bench_func_file = NULL;
  char *func_dump_file = NULL;

  /* register all the defined functions */
  register_rotate_functions();
  register_smooth_functions();

  /* parse command line args */
  while ((c = getopt(argc, argv, "tgqf:d:s:h")) != -1)
    switch (c) {

    case 't': /* skip student name check (hidden flag) */
      skip_studentname_check = 1;
      break;

    case 's': /* seed for random number generator (hidden flag) */
      seed = atoi(optarg);
      break;

    case 'g': /* autograder mode (checks only rotate() and smooth()) */
      autograder = 1;
      break;

    case 'q':
      quit_after_dump = 1;
      break;

    case 'f': /* get names of benchmark functions from this file */
      bench_func_file = strdup(optarg);
      break;

    case 'd': /* dump names of benchmark functions to this file */
      func_dump_file = strdup(optarg);
      {
	int i;
	FILE *fp = fopen(func_dump_file, "w");	

	if (fp == NULL) {
	  printf("Can't open file %s\n",func_dump_file);
	  exit(-5);
	}

	for(i = 0; i < rotate_benchmark_count; i++) {
	  fprintf(fp, "R:%s\n", benchmarks_rotate[i].description); 
	}
	for(i = 0; i < smooth_benchmark_count; i++) {
	  fprintf(fp, "S:%s\n", benchmarks_smooth[i].description); 
	}
	fclose(fp);
      }
      break;

    case 'h': /* print help message */
      usage(argv[0]);

    default: /* unrecognized argument */
      usage(argv[0]);
    }

  if (quit_after_dump) 
    exit(EXIT_SUCCESS);


  /* Print student info */
  if (!skip_studentname_check) {
    if (strcmp("J. Doe", student.name) == 0) {
      printf("%s: Please fill in the student struct in kernels.c.\n", argv[0]);
      exit(1);
    }
    printf("Student: %s\n", student.name);
    printf("Login: %s\n", student.login);
    printf("Email: %s\n", student.email);
    printf("\n");
  }

  srand(seed);

  /* 
   * If we are running in autograder mode, we will only test
   * the rotate() and bench() functions.
   */
  if (autograder) {
    rotate_benchmark_count = 1;
    smooth_benchmark_count = 1;

    benchmarks_rotate[0].tfunct = rotate;
    benchmarks_rotate[0].description = "rotate() function";
    benchmarks_rotate[0].valid = 1;

    benchmarks_smooth[0].tfunct = smooth;
    benchmarks_smooth[0].description = "smooth() function";
    benchmarks_smooth[0].valid = 1;
  }

  /* 
   * If the user specified a file name using -f, then use
   * the file to determine the versions of rotate and smooth to test
   */
  else if (bench_func_file != NULL) {
    char flag;
    char func_line[256];
    FILE *fp = fopen(bench_func_file, "r");

    if (fp == NULL) {
      printf("Can't open file %s\n",bench_func_file);
      exit(-5);
    }
    
    while(func_line == fgets(func_line, 256, fp)) {
      char *func_name = func_line;
      char **strptr = &func_name;
      char *token = strsep(strptr, ":");
      flag = token[0];
      func_name = strsep(strptr, "\n");
#ifdef DEBUG
      printf("Function Description is %s\n",func_name);
#endif

      if (flag == 'R') {
	for(i=0; i<rotate_benchmark_count; i++) {
	  if (strcmp(benchmarks_rotate[i].description, func_name) == 0)
	    benchmarks_rotate[i].valid = 1;
	}
      }
      else if (flag == 'S') {
	for(i=0; i<smooth_benchmark_count; i++) {
	  if (strcmp(benchmarks_smooth[i].description, func_name) == 0)
	    benchmarks_smooth[i].valid = 1;
	}
      }      
    }

    fclose(fp);
  }

  /* 
   * If the user didn't specify a dump file using -f, then 
   * test all of the functions
   */
  else { /* set all valid flags to 1 */
    for (i = 0; i < rotate_benchmark_count; i++)
      benchmarks_rotate[i].valid = 1;
    for (i = 0; i < smooth_benchmark_count; i++)
      benchmarks_smooth[i].valid = 1;
  }

  /* Set measurement (fcyc) parameters */
  set_fcyc_cache_size(1 << 16); /* 64 KB cache size */
  set_fcyc_clear_cache(1); /* clear the cache before each measurement */
  set_fcyc_compensate(1); /* try to compensate for timer overhead */
 
  for (i = 0; i < rotate_benchmark_count; i++) {
    if (benchmarks_rotate[i].valid) {
      test_rotate(i);
    }
    
  }
  for (i = 0; i < smooth_benchmark_count; i++) {
    if (benchmarks_smooth[i].valid) {
      test_smooth(i);
    }
  }


  if (autograder) {
    printf("\nbestscores:%.1f:%.1f:\n", rotate_maxmean, smooth_maxmean);
  }
  else {
    printf("Summary of Your Best Scores:\n");
    printf("  Rotate: %3.1f (%s)\n", rotate_maxmean, rotate_maxmean_desc);
    printf("  Smooth: %3.1f (%s)\n", smooth_maxmean, smooth_maxmean_desc);
  }

  return 0;
}