Exemplo n.º 1
0
int smpi_main(int (*realmain) (int argc, char *argv[]), int argc, char *argv[])
{
  srand(SMPI_RAND_SEED);

  if (getenv("SMPI_PRETEND_CC") != NULL) {
    /* Hack to ensure that smpicc can pretend to be a simple compiler. Particularly handy to pass it to the
     * configuration tools */
    return 0;
  }
  smpi_init_logs();

  TRACE_global_init(&argc, argv);
  TRACE_add_start_function(TRACE_smpi_alloc);
  TRACE_add_end_function(TRACE_smpi_release);

  SIMIX_global_init(&argc, argv);
  MSG_init(&argc,argv);

  SMPI_switch_data_segment = smpi_switch_data_segment;

  smpi_init_options();

  // parse the platform file: get the host list
  SIMIX_create_environment(argv[1]);
  SIMIX_comm_set_copy_data_callback(&smpi_comm_copy_buffer_callback);
  SIMIX_function_register_default(realmain);
  SIMIX_launch_application(argv[2]);

  smpi_global_init();

  smpi_check_options();

  if(smpi_privatize_global_variables)
    smpi_initialize_global_memory_segments();

  /* Clean IO before the run */
  fflush(stdout);
  fflush(stderr);

  if (MC_is_active()) {
    MC_run();
  } else {
  
    SIMIX_run();

    xbt_os_walltimer_stop(global_timer);
    if (xbt_cfg_get_boolean("smpi/display-timing")){
      double global_time = xbt_os_timer_elapsed(global_timer);
      XBT_INFO("Simulated time: %g seconds. \n\n"
          "The simulation took %g seconds (after parsing and platform setup)\n"
          "%g seconds were actual computation of the application",
          SIMIX_get_clock(), global_time , smpi_total_benched_time);
          
      if (smpi_total_benched_time/global_time>=0.75)
      XBT_INFO("More than 75%% of the time was spent inside the application code.\n"
      "You may want to use sampling functions or trace replay to reduce this.");
    }
  }
  int count = smpi_process_count();
  int i, ret=0;
  for (i = 0; i < count; i++) {
    if(process_data[i]->return_value!=0){
      ret=process_data[i]->return_value;//return first non 0 value
      break;
    }
  }
  smpi_global_destroy();

  TRACE_end();

  return ret;
}
Exemplo n.º 2
0
void RawContectFactory::run_all_adaptative()
{
  unsigned long nb_processes = xbt_dynar_length(simix_global->process_to_run);
  unsigned long threshold = SIMIX_context_get_parallel_threshold();
  reached_seq_limit = (seq_sched_round % SCHED_ROUND_LIMIT == 0);
  reached_par_limit = (par_sched_round % SCHED_ROUND_LIMIT == 0);

  if(reached_seq_limit && reached_par_limit){
    par_ratio = (par_proc_that_ran != 0) ? (par_time / (double)par_proc_that_ran) : 0;
    seq_ratio = (seq_proc_that_ran != 0) ? (seq_time / (double)seq_proc_that_ran) : 0;
    if(seq_ratio > par_ratio){
       if(nb_processes < avg_par_proc) {
          threshold = (threshold>2) ? threshold - 1 : threshold ;
          SIMIX_context_set_parallel_threshold(threshold);
        }
    } else {
        if(nb_processes > avg_seq_proc){
          SIMIX_context_set_parallel_threshold(threshold+1);
        }
    }
  }

  if (nb_processes >= SIMIX_context_get_parallel_threshold()) {
    simix_global->context_factory->suspend = smx_ctx_raw_suspend_parallel;
    if (nb_processes < par_window){
      par_sched_round++;
      xbt_os_walltimer_start(round_time);
      smx_ctx_raw_runall_parallel();
      xbt_os_walltimer_stop(round_time);
      par_time += xbt_os_timer_elapsed(round_time);

      prev_avg_par_proc = avg_par_proc;
      delta = nb_processes - avg_par_proc;
      avg_par_proc = (par_sched_round==1) ? nb_processes : avg_par_proc + delta / (double) par_sched_round;

      if(par_sched_round>=2){
        s_par_proc = s_par_proc + (nb_processes - prev_avg_par_proc) * delta;
        sd_par_proc = sqrt(s_par_proc / (par_sched_round-1));
        par_window = (int) (avg_par_proc + sd_par_proc);
      }else{
        sd_par_proc = 0;
      }

      par_proc_that_ran += nb_processes;
    } else{
      smx_ctx_raw_runall_parallel();
    }
  } else {
    simix_global->context_factory->suspend = smx_ctx_raw_suspend_serial;
    if(nb_processes > seq_window){
      seq_sched_round++;
      xbt_os_walltimer_start(round_time);
      smx_ctx_raw_runall_serial();
      xbt_os_walltimer_stop(round_time);
      seq_time += xbt_os_timer_elapsed(round_time);

      prev_avg_seq_proc = avg_seq_proc;
      delta = (nb_processes-avg_seq_proc);
      avg_seq_proc = (seq_sched_round==1) ? nb_processes : avg_seq_proc + delta / (double) seq_sched_round;

      if(seq_sched_round>=2){
        s_seq_proc = s_seq_proc + (nb_processes - prev_avg_seq_proc)*delta;
        sd_seq_proc = sqrt(s_seq_proc / (seq_sched_round-1));
        seq_window = (int) (avg_seq_proc - sd_seq_proc);
      } else {
        sd_seq_proc = 0;
      }

      seq_proc_that_ran += nb_processes;
    } else {
      smx_ctx_raw_runall_serial();
    }
  }
}