Пример #1
0
/* must be protected with a mutex */
int framework_main(enum benchmark_size_t size) {
  int score;
  memset(bench_info_list, 0, sizeof(bench_info_list));
  memset(bench_run_data, 0, sizeof(bench_run_data));

#ifdef ARRAYFILE
  arrayfile_stdout = arrayfile_fopen("arrayfile", "w");
  assert(arrayfile_stdout);
#endif

  if (size == kBenchmarkSmall) {
    SetupSmallBenchmarks();
  } else {
    SetupLargeBenchmarks();
  }

  fasta_10k_ref_output_len = strlen(fasta_10k_ref_output);

  printf("%d benchmarks registered\n", benchmark_count);
  RunAll();
  PrintScores();
  score = (int) GeometricMean();
#ifdef ARRAYFILE
  arrayfile_fclose(arrayfile_stdout);
  arrayfile_stdout = NULL;
#endif
  ClearBenchmarks();

   print_total_stats();
	
  printf("Aggregate score: %d\n", score);

  return score;
}
Пример #2
0
static void
run_checkpoint_actions (bool do_write)
{
  struct checkpoint_action *p;

  for (p = checkpoint_action; p; p = p->next)
    {
      switch (p->opcode)
	{
	case cop_dot:
	  fputc ('.', stdlis);
	  fflush (stdlis);
	  break;

	case cop_bell:
	  if (!tty)
	    tty = fopen ("/dev/tty", "w");
	  if (tty)
	    {
	      fputc ('\a', tty);
	      fflush (tty);
	    }
	  break;

	case cop_echo:
	  {
	    int n = fprintf (stderr, "%s: ", program_name);
	    format_checkpoint_string (stderr, n, p->v.command, do_write,
				      checkpoint);
	    fputc ('\n', stderr);
	  }
	  break;

	case cop_ttyout:
	  if (!tty)
	    tty = fopen ("/dev/tty", "w");
	  if (tty)
	    format_checkpoint_string (tty, 0, p->v.command, do_write,
				      checkpoint);
	  break;

	case cop_sleep:
	  sleep (p->v.time);
	  break;

	case cop_exec:
	  sys_exec_checkpoint_script (p->v.command,
				      archive_name_cursor[0],
				      checkpoint);
	  break;

	case cop_totals:
	  compute_duration ();
	  print_total_stats ();
	}
    }
}
Пример #3
0
int main(int argc, char* argv[]) 
{
    if (argc != 6) {
        std::cout << "Usage: " << argv[0] << " <nphils> <duration> <think_delay_max> <eat_delay_max> <debugflag>\n";
        return EXIT_FAILURE;
    }

    unsigned int nphils = atoi(argv[1]);
    unsigned int duration = atoi(argv[2]);
    unsigned int think_delay_max = atoi(argv[3]);
    unsigned int eat_delay_max = atoi(argv[4]);
    debugflag = atoi(argv[5]);
    
    // Disable buffering for stdout
    setbuf(stdout, NULL);
    srand((unsigned int)time(0));
    
    philosopher_stat* philstats[nphils];
    for (unsigned int i = 0; i < nphils; ++i)
        philstats[i] = new philosopher_stat();
    
    fork* forks[nphils];
    for (unsigned int i = 0; i < nphils; ++i)
        forks[i] = new fork(i + 1);
    
    philosopher* phils[nphils];
    for (unsigned int i = 0; i < nphils; ++i) {
        phils[i] = new philosopher(i + 1, forks[i], forks[(i + 1) % nphils], 
                                   nphils, think_delay_max, eat_delay_max, philstats[i]);
    }
    shed = new scheduler_dinners(nphils);

    std::thread threads[nphils];
    for (unsigned int i = 0; i < nphils; ++i)
        threads[i] = std::thread(&philosopher::run, phils[i]);
    
    // Create observer thread
    std::thread observer(&scheduler_dinners::observer, std::ref(shed));

    // Now we have nphils threads + observer thread + master thread
    
    std::this_thread::sleep_for(std::chrono::seconds(duration));
    std::for_each(phils, phils + nphils, std::mem_fn(&philosopher::stop));
    shed->stop_observe();
    observer.join();
    std::for_each(threads, threads + nphils, std::mem_fn(&std::thread::join));

    std::printf("Dining philosophers problem\n");
    std::printf("nphils = %d, duration = %d, think_delay_max = %d, eat_delay_max = %d, debugflag = %d\n",
                nphils, duration, think_delay_max, eat_delay_max, debugflag);
    std::printf("[TID] <eat_count> <wait_time>\n");
    std::for_each(phils, phils + nphils, std::mem_fn(&philosopher::print_stats));
    
    print_total_stats(philstats, nphils);
    
    for (unsigned int i = 0; i < nphils; ++i) {
        delete phils[i];
        delete forks[i];
        delete philstats[i];
    }
    return 0;
}