示例#1
0
static int __init init_flicker(void)
{
  int rv = 0;
  logit("Flicker module initializing.");

  if(get_cpu_vendor() == CPU_VENDOR_INTEL) {
      /* Don't bother to load the module if the platform does not support
       * the TXT extensions.
       *
       * TODO: Is this a better home for the checks in prepare_for_launch?
       */
      rv = txt_verify_platform();
      if (!rv) {
          error("Intel Platform that does not support TXT extensions.");
          return rv;
      }
  } else {
      /* On AMD, we need to clear the Microcode on all CPUs. This
       * introduces the requirement that this module is loaded before
       * CPU hotplug disables all the other CPUs, since otherwise they
       * won't all be cleared. */
      do_amducodeclear();
  }

  /* allocate memory for PAL and (on Intel) ACmod */
  rv = do_allocations();
  if (rv) {
    error("Error during alloc_pal(): rv = [%d]", rv);
    return rv;
  }

  /* Initialize sysfs entries */
  rv = flicker_sysfs_init();
  if(rv) {
    error("Error initializing sysfs: rv = [%d]", rv);
    free_allocations();
    return rv;
  }

  assert(0 == rv);
  return rv;
}
示例#2
0
int main (int argc, char** argv) {

  char strbuf[256];
  time_t raw_time;

  // Load parameters from the specified file
  if (argc != 2) {
    printf("Error! Must provide a parameters filename as first argument\n");
    exit(EXIT_FAILURE);
  } else {
    raw_time = time(NULL);
    printf(">> %s", ctime(&raw_time));
  }
  params_fname = new char[strlen(argv[1])];
  strcpy(params_fname, argv[1]);
  printf(">> Reading parameters file %s ...\n", params_fname);
  load_parameters(params_fname);
  
  const int report_interval = (num_cycles > 100 ? num_cycles : 100) / 100; 
  
  // Open log and data files
  log_file = fopen(log_fname,"w");
  output_file = fopen(output_fname,"w");
  printf(">> Opened log file %s\n", log_fname);
  raw_time = time(NULL);
  sprintf(strbuf, ">> %s", ctime(&raw_time)); log(strbuf, false);
  sprintf(strbuf, ">> Read parameters file %s ...\n", params_fname); log(strbuf, false);

  // Report parameters
  sprintf(strbuf, "grid_size = %i\n", grid_size); log(strbuf);
  sprintf(strbuf, "num_cycles = %i\n", num_cycles); log(strbuf);
  sprintf(strbuf, "growth_multiplier = %f\n", growth_multiplier); log(strbuf);
  sprintf(strbuf, "global_death_rate = %f\n", global_death_rate); log(strbuf);
  sprintf(strbuf, "all_die = %s\n", all_die ? "true" : "false"); log(strbuf);
  sprintf(strbuf, "report_to_screen = %s\n", report_to_screen ? "true" : "false"); log(strbuf);
  sprintf(strbuf, "log_fname = %s\n", log_fname); log(strbuf);
  sprintf(strbuf, "output_fname = %s\n", output_fname); log(strbuf);
  sprintf(strbuf, "output_interval = %i\n", output_interval); log(strbuf);
  sprintf(strbuf, "num_strains = %i\n", num_strains); log(strbuf);
  sprintf(strbuf, "strains_fname = %s\n", strains_fname); log(strbuf);
  sprintf(strbuf, "enable_antagonism = %s\n", enable_antagonism ? "true" : "false"); log(strbuf);
  sprintf(strbuf, "antagonism_table_fname = %s\n", antagonism_table_fname); log(strbuf);
  sprintf(strbuf, "use_real_growth = %s\n", use_real_growth ? "true" : "false"); log(strbuf);
  sprintf(strbuf, "growth_intercept = %f\n", growth_intercept); log(strbuf);
  sprintf(strbuf, "growth_slope = %f\n", growth_slope); log(strbuf);
  sprintf(strbuf, "food_source_rations = %i\n", food_source_rations); log(strbuf);
  sprintf(strbuf, "food_source_radius = %i\n", food_source_radius); log(strbuf);
  sprintf(strbuf, "food_source_spawn_rate = %f\n", food_source_spawn_rate); log(strbuf);
  sprintf(strbuf, "start_population_per_strain = %i\n", start_population_per_strain); log(strbuf);
  sprintf(strbuf, "start_num_food_sources = %i\n", start_num_food_sources); log(strbuf);
  log(">> Parameters loaded successfully\n");

  // Allocate data arrays
  do_allocations();
  log(">> Data arrays allocated\n");
  
  // Set RNG seed
  reset_seed();
  sprintf(strbuf, ">> RNG seed: %u\n", global_seed); log(strbuf);
  
  // Create strains using data from file
  log(">> Loading strains ...\n");
  create_strains();
  
  // Load antagonism matrix (if applicable)
  if (enable_antagonism) {
    log(">> Antagonisms ENABLED\n");
    load_antagonisms();
  } else {
    log(">> Antagonisms DISABLED\n");
  }

  // Compute growth_rates if not using real ones
  if (use_real_growth) {
    log(">> Using measured growth rates\n");
  } else {
    log(">> Computing growth rates from sender degrees ...\n");
    compute_growth_rates();
  }
  
  // Report strains
  log(">> Loaded strains:\n");
  log("(name | sender degree | receiver degree | growth rate)\n");
  int max_length = 0;
  int max_size = 0;
  for (int i = 0; i < num_strains; i++) {
    if (strains[i]->name.length() > max_length)
      max_length = strains[i]->name.length();
    if (strains[i]->sender_degree > max_size)
      max_size = strains[i]->sender_degree;
    if (strains[i]->receiver_degree > max_size)
      max_size = strains[i]->receiver_degree;      
  }
  max_size = int(log10(max_size))+1;
  for (int i = 0; i < num_strains; i++) {
    sprintf(strbuf, "%-*s | %*i | %*i | %.6f\n", max_length, strains[i]->name.c_str(), max_size, strains[i]->sender_degree, max_size, strains[i]->receiver_degree, strains[i]->growth_rate); log(strbuf);
  }
  
  // Create starting bacteria
  bac_counter = 0;
  log(">> Creating bacteria ...\n");
  create_starting_bacteria();
  sprintf(strbuf, "Population: %i\n", (int)bacteria_list.size()); log(strbuf);
  compute_strain_counts();
  
  // Create food sources
  log(">> Creating food sources ...\n");
  create_starting_food();
  sprintf(strbuf, "Food sources: %i\n", (int)food_list.size()); log(strbuf);
  flag_bacteria_at_food_sources();

  // Ready!
  log(">> READY. Starting simulation ...\n", true);
  if (!report_to_screen) {
    printf("(no further output written to screen)\n");
  }
 
  // Main loop over cycles
  for (cycle = 1; cycle <= num_cycles; cycle++) {

    move_bacteria();

    flag_bacteria_at_food_sources();

    food_sources_interactions();

    cleanup_empty_food_sources();

    kill_bacteria();

    cleanup_dead_bacteria();
    
    spawn_food_source();

    compute_strain_counts();
    
    sprintf(strbuf, "Cycle %i, %i bacteria, %i sources\n", cycle, (int)bacteria_list.size(), (int)food_list.size());
    log(strbuf, false);
    if (report_to_screen) {
      if (cycle % report_interval == 0) {
        printf(">> Cycle %i, %i bacteria, %i sources\n", cycle, (int)bacteria_list.size(), (int)food_list.size());
      }
    }
    
    if (cycle % output_interval == 0) {
      data_output();
    }

  }
  
  raw_time = time(NULL);
  sprintf(strbuf, ">> %s", ctime(&raw_time)); log(strbuf, true);
  
  deallocate();
  
}