Example #1
0
/** Main function */
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;

#ifdef _MSC_VER
  unsigned int prev_exponent_format =
      _set_output_format(_TWO_DIGIT_EXPONENT);
#endif

  MSG_init(&argc, argv);


  if (argc != 3) {
    XBT_CRITICAL("Usage: %s platform_file deployment_file <model>\n",
              argv[0]);
    XBT_CRITICAL
        ("example: %s msg_platform.xml msg_deployment.xml KCCFLN05_Vegas\n",
         argv[0]);
    exit(1);
  }

  /* Options for the workstation/model:

     KCCFLN05              => for maxmin
     KCCFLN05_proportional => for proportional (Vegas)
     KCCFLN05_Vegas        => for TCP Vegas
     KCCFLN05_Reno         => for TCP Reno
   */
  //MSG_config("workstation/model", argv[3]);

  res = test_all(argv[1], argv[2]);

  XBT_INFO("Total simulation time: %le", MSG_get_clock());

#ifdef _MSC_VER
  _set_output_format(prev_exponent_format);
#endif

  if (res == MSG_OK)
    return 0;
  else
    return 1;
}                               /* end_of_main */
Example #2
0
File: peer2.c Project: tof25/DST
/** Test function */
msg_error_t test_all(const char *platform_file,
                     const char *application_file)
{
  msg_error_t res = MSG_OK;

  /* MSG_config("workstation/model","KCCFLN05"); */
  {                             /*  Simulation setting */
    MSG_create_environment(platform_file);
  }
  {                             /*   Application deployment */
    MSG_function_register("sender", sender);
    MSG_function_register("receiver", receiver);
    MSG_launch_application(application_file);
  }
  res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());
  return res;
}                               /* end_of_test_all */
Example #3
0
/** Receiver function  */
int slave(int argc, char *argv[])
{

  msg_task_t task = NULL;
  int a = MSG_OK;
  int id = 0;
  char id_alias[10];

  xbt_assert(argc==2,"Strange number of arguments expected 1 got %d", argc - 1);

  XBT_DEBUG ("Slave started");

  id = atoi(argv[1]);
  sprintf(id_alias, "%d", id);

  a = MSG_task_receive(&(task), id_alias);

  count_finished--;
  if(count_finished == 0){
      timer_start = 0;
  }



  if (a != MSG_OK) {
    XBT_INFO("Hey?! What's up?");
    xbt_die("Unexpected behavior.");
  }

  elapsed_time = MSG_get_clock() - start_time;
  
  XBT_INFO("FLOW[%d] : Receive %.0f bytes from %s to %s",
      id,
      MSG_task_get_bytes_amount(task),
       masternames[id],
       slavenames[id]);
//  MSG_task_execute(task);
  MSG_task_destroy(task);

  XBT_DEBUG ("Finished");
  return 0;
}                               /* end_of_slave */
Example #4
0
/** Test function */
MSG_error_t test_all(void)
{
  MSG_error_t res = MSG_OK;

  /*  Simulation setting */
  MSG_set_channel_number(MAX_CHANNEL);
  surf_parse = surf_parse_bypass_platform;
  MSG_create_environment(NULL);

  /*   Application deployment */
  MSG_function_register("master", master);
  MSG_function_register("slave", slave);
  surf_parse = surf_parse_bypass_application;
  MSG_launch_application(NULL);

  res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());
  return res;
}                               /* end_of_test_all */
/** Test function */
MSG_error_t test_all(const char *platform_file,
			    const char *application_file)
{
  MSG_error_t res = MSG_OK;

  /* MSG_config("surf_workstation_model","KCCFLN05"); */
  {				/*  Simulation setting */
    MSG_set_channel_number(0);
    MSG_create_environment(platform_file);
  }
  {                            /*   Application deployment */
    MSG_function_register("master", master);
    MSG_function_register("slave", slave);
    MSG_launch_application(application_file);
  }
  res = MSG_main();
  
  INFO1("Simulation time %g",MSG_get_clock());
  return res;
} /* end_of_test_all */
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;

  MSG_init(&argc, argv);
  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
             "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);

  MSG_function_register("master", master);
  MSG_function_register("worker", worker);
  MSG_launch_application(argv[2]);

  res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());

  return res != MSG_OK;
}
Example #7
0
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;

  MSG_init(&argc, argv);
  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
             "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);/* - Load the platform description */

  MSG_function_register("sender", sender);
  MSG_function_register("receiver", receiver);
  MSG_launch_application(argv[2]);/* - Deploy the sender and receiver processes */

  res = MSG_main();  /* - Run the simulation */

  XBT_INFO("Simulation time %g", MSG_get_clock());

  return res != MSG_OK;
}
Example #8
0
static int master_main(int argc, char *argv[])
{
  xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
  msg_host_t pm0 = MSG_host_by_name("Fafard");
  msg_vm_t   vm0 = MSG_vm_create_core(pm0, "VM0");
  MSG_vm_start(vm0);

  launch_computation_worker(vm0);

  while(MSG_get_clock()<100) {
  if (atask != NULL)
    XBT_INFO("aTask remaining duration: %g", MSG_task_get_flops_amount(atask));
  MSG_process_sleep(1);
  }

  MSG_process_sleep(10000);
  MSG_vm_destroy(vm0);
  xbt_dynar_free(&hosts_dynar);
  return 1;
}
Example #9
0
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;
  sg_energy_plugin_init();
  MSG_init(&argc, argv);

  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
       "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);

  MSG_function_register("onoff_test", onoff);
  MSG_launch_application(argv[2]);

  res = MSG_main();

  XBT_INFO("Total simulation time: %.2f", MSG_get_clock());

  return res != MSG_OK;
}
Example #10
0
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;

  MSG_init(&argc, argv);

  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
             "\tExample: %s ../../platform/small_platform.xml app-pingpong_d.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);          /* - Load the platform description */

  MSG_function_register("pinger", pinger);  /* - Register the function to be executed by the processes */
  MSG_function_register("ponger", ponger);

  MSG_launch_application(argv[2]);          /* - Deploy the application */

  res = MSG_main();                         /* - Run the simulation */

  XBT_INFO("Total simulation time: %e", MSG_get_clock());
  return res!=MSG_OK;
}
Example #11
0
msg_error_t test_all(const char *platform_file,
                     const char *application_file)
{
  msg_error_t res = MSG_OK;


  MSG_config("workstation/model", "ptask_L07");

  /*  Simulation setting */
  MSG_create_environment(platform_file);

  /*   Application deployment */
  MSG_function_register("execute", execute);
  MSG_function_register("redistribute", redistribute);
  MSG_launch_application(application_file);

  res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());
  return res;
}
Example #12
0
int main(int argc, char *argv[])
{
  MSG_init(&argc, argv);
  MSG_config("host/model", "ptask_L07");
  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../examples/platforms/two_hosts.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);

  MSG_process_create("sequential", seq_task, NULL, MSG_get_host_by_name("Tremblay"));

  MSG_process_create("parallel", par_task, NULL, MSG_get_host_by_name("Tremblay"));

  // Create a process to test in progress task
  MSG_process_create("get_progress", get_progress, NULL, MSG_get_host_by_name("Tremblay"));

  msg_error_t res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());

  return res != MSG_OK;
}
Example #13
0
int main(int argc, char **argv)
{
  int res;
  xbt_dynar_t all_hosts;
  msg_host_t first_host;
  MSG_init(&argc, argv);
  MSG_create_environment(argv[1]);
  MSG_function_register("host", host);
  all_hosts = MSG_hosts_as_dynar();
  first_host = xbt_dynar_pop_as(all_hosts,msg_host_t);
  MSG_process_create( "host", host, NULL, first_host);
  xbt_dynar_free(&all_hosts);

  res = MSG_main();
  XBT_INFO("Simulation time %g", MSG_get_clock());

  if (res == MSG_OK)
    return 0;
  else
    return 1;
}
Example #14
0
int broker(int argc, char *argv[]){
    //set number of request
    int requests_per_second= atoi(argv[1]);
    double static broker_id = 0;
    request list_requests[50]; 
    int list_requests_len = 0;

    //set mailbox
    char mailbox[50];
    sprintf(mailbox,"%s_%lf",argv[0],broker_id++);

    msg_comm_t msg_send;
   //create list of requests
    int i;
    for( i = 2;i < argc;i = i+3){
	make_request(&list_requests[list_requests_len++],argv[i],argv[i+1],argv[i+2]);
    }

    //send requests
    int j;
    for(j =0;j < list_requests_len;j++){
	m_task_t task =  MSG_task_create(list_requests[j].method,0,
		list_requests[j].input_size,NULL);
	task->data = xbt_new(task_data,1);

	create_task_data((task_data *) task->data,task_id++,mailbox);

	msg_send = MSG_task_isend(task,list_requests[j].role);

	task_data data_to_print = *(task_data *)task->data;
	XBT_INFO("sending task %lf to %s",data_to_print.id,list_requests[j].role );
	
     //receive response
	task_data data_received = receive_task(mailbox);
	XBT_INFO("received task %lf", data_received.id); 
	double endtime = MSG_get_clock();
	write_log(data_received.starttime,endtime,"time_total");
    }
  XBT_INFO("ending choreography"); 
}
Example #15
0
/** Test function */
MSG_error_t test_all(const char *platform_file,
                     const char *application_file)
{
  MSG_error_t res = MSG_OK;

  {                             /*  Simulation setting */
    MSG_set_channel_number(0);
    MSG_create_environment(platform_file);
  }
  {
    /* declaring tracing categories */

    //declaring user variables
    TRACE_host_variable_declare("is_slave");
    TRACE_host_variable_declare("is_master");
    TRACE_host_variable_declare("task_creation");
    TRACE_host_variable_declare("task_computation");

    //declaring user markers
    TRACE_declare_mark("msmark");

    //declaring user categories with RGB colors (values from 0 to 1)
    TRACE_category_with_color ("compute", "1 0 0");  //compute is red
    TRACE_category_with_color ("finalize", "0 1 0"); //finalize is green
    //categories without user-defined colors receive
    //random colors generated by the tracing system
    TRACE_category ("request");
    TRACE_category_with_color ("report", NULL);
  }
  {                             /*   Application deployment */
    MSG_function_register("master", master);
    MSG_function_register("slave", slave);
    MSG_launch_application(application_file);
  }
  res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());
  return res;
}
Example #16
0
int main(int argc, char *argv[])
{
  MSG_init(&argc, argv);
  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
       "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);
  MSG_function_register("receiver", receiver);
  MSG_function_register("sender", sender);

  MSG_launch_application(argv[2]);
#ifndef DISABLE_THE_MUTEX
  mutex = xbt_mutex_init();
#endif
  msg_error_t res = MSG_main();
#ifndef DISABLE_THE_MUTEX
  xbt_mutex_destroy(mutex); mutex = NULL;
#endif
  XBT_INFO("Simulation time %g", MSG_get_clock());

  return res != MSG_OK;
}
Example #17
0
int main(int argc, char **argv)
{
  int res;
  MSG_init(&argc, argv);
  MSG_create_environment(argv[1]);
  xbt_dynar_t hosts =  MSG_hosts_as_dynar();
  MSG_function_register("host", host);
  unsigned long nb_hosts = xbt_dynar_length(hosts);
  XBT_INFO("Number of host '%lu'",nb_hosts);
  char* name_host = xbt_strdup("0");
  MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,0,msg_host_t) );
  free(name_host);

  xbt_dynar_free(&hosts);

  res = MSG_main();
  XBT_INFO("Simulation time %g", MSG_get_clock());
  if (res == MSG_OK)
    return 0;
  else
    return 1;

}
Example #18
0
/** \brief Main function. */
int main(int argc, char *argv[])
{
  MSG_init(&argc, argv);
  xbt_assert(argc > 2, 
       "Usage: %s [-nb_bits=n] [-timeout=t] platform_file deployment_file\n"
       "\tExample: %s ../msg_platform.xml pastry10.xml\n", 
       argv[0], argv[0]);

  char **options = &argv[1];
  while (!strncmp(options[0], "-", 1)) {
    int length = strlen("-nb_bits=");
    if (!strncmp(options[0], "-nb_bits=", length) && strlen(options[0]) > length) {
      nb_bits = xbt_str_parse_int(options[0] + length, "Invalid nb_bits parameter: %s");
      XBT_DEBUG("Set nb_bits to %d", nb_bits);
    } else {
      length = strlen("-timeout=");
      if (!strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) {
        timeout = xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s");
        XBT_DEBUG("Set timeout to %d", timeout);
      } else {
        xbt_die("Invalid chord option '%s'", options[0]);
      }
    }
    options++;
  }

  MSG_create_environment(options[0]);

  MSG_function_register("node", node);
  MSG_launch_application(options[1]);

  msg_error_t res = MSG_main();
  XBT_CRITICAL("Messages created: %ld", smx_total_comms);
  XBT_INFO("Simulated time: %g", MSG_get_clock());

  return res != MSG_OK;
}
Example #19
0
int main(int argc, char **argv)
{
	int res;
  MSG_global_init(&argc, argv);
  MSG_set_channel_number(MAX_CHANNEL);
  MSG_create_environment(argv[1]);

  MSG_function_register("master", master);
  MSG_function_register("slave", slave);
  surf_parse = surf_parse_bypass_application;
  MSG_launch_application(NULL);

  res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());

  MSG_clean();

  if (res == MSG_OK)
    return 0;
  else
    return 1;

}
Example #20
0
/** Test function */
MSG_error_t test_all(const char *platform_file,
                     const char *application_file)
{
  MSG_error_t res = MSG_OK;

  {                             /*  Simulation setting */
    MSG_set_channel_number(0);
    MSG_create_environment(platform_file);
  }
  {
    //declaring user categories
    TRACE_category_with_color ("compute", "1 0 0");  //compute is red
    TRACE_category_with_color ("finalize", "0 1 0"); //finalize is green
  }
  {                             /*   Application deployment */
    MSG_function_register("master", master);
    MSG_function_register("slave", slave);
    MSG_launch_application(application_file);
  }
  res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());
  return res;
}
Example #21
0
/** Emitter function  */
int master(int argc, char *argv[])
{
  int workers_count = 0;
  msg_host_t *workers = NULL;
  msg_task_t *todo = NULL;
  msg_host_t host_self = MSG_host_self();
  char *master_name = (char *) MSG_host_get_name(host_self);
  double task_comp_size = 0;
  double task_comm_size = 0;
  char channel[1024];
  double timeout = -1;

  int i;

  TRACE_category(master_name);

  _XBT_GNUC_UNUSED int res = sscanf(argv[1], "%lg", &timeout);
  xbt_assert(res,"Invalid argument %s\n", argv[1]);
  res = sscanf(argv[2], "%lg", &task_comp_size);
  xbt_assert(res, "Invalid argument %s\n", argv[2]);
  res = sscanf(argv[3], "%lg", &task_comm_size);
  xbt_assert(res, "Invalid argument %s\n", argv[3]);

  {                             /* Process organisation */
    workers_count = MSG_get_host_number();
    workers = xbt_dynar_to_array(MSG_hosts_as_dynar());
    
    for (i = 0; i < workers_count; i++)
      if(host_self == workers[i]) {
	workers[i] = workers[workers_count-1];
	workers_count--;
	break;
      }

    for (i = 0; i < workers_count; i++)
	MSG_process_create("worker", worker, master_name, workers[i]);
  }

  XBT_INFO("Got %d workers and will send tasks for %g seconds!", 
	   workers_count, timeout);

  for (i = 0; 1; i++) {
    char sprintf_buffer[64];
    msg_task_t task = NULL;

    if(MSG_get_clock()>timeout) break;

    sprintf(sprintf_buffer, "Task_%d", i);
    task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size,
			   NULL);
    MSG_task_set_category(task, master_name);

    build_channel_name(channel,master_name,
		       MSG_host_get_name(workers[i % workers_count]));
    
    XBT_DEBUG("Sending \"%s\" to channel \"%s\"", task->name, channel);
    MSG_task_send(task, channel);
    XBT_DEBUG("Sent");
  }

  int task_num = i;

  XBT_DEBUG
      ("All tasks have been dispatched. Let's tell everybody the computation is over.");
  for (i = 0; i < workers_count; i++) {
    msg_task_t finalize = MSG_task_create("finalize", 0, 0, FINALIZE);
    MSG_task_send(finalize, build_channel_name(channel,master_name,
		    MSG_host_get_name(workers[i % workers_count])));
  }

  XBT_INFO("Sent %d tasks in total!", task_num);
  free(workers);
  free(todo);
  return 0;
}                               /* end_of_master */
Example #22
0
/**
 * \brief Node Function
 * Arguments:
 * - my id
 * - the id of a guy I know in the system (except for the first node)
 * - the time to sleep before I join (except for the first node)
 * - the deadline time
 */
static int node(int argc, char *argv[])
{
  double init_time = MSG_get_clock();
  msg_task_t task_received = NULL;  
  int join_success = 0;  
  double deadline;
  xbt_assert(argc == 3 || argc == 5, "Wrong number of arguments for this node");
  s_node_t node = {0};
  node.id = xbt_str_parse_int(argv[1], "Invalid ID: %s");
  node.known_id = -1;
  node.ready = -1;
  node.pending_tasks = xbt_fifo_new();
  get_mailbox(node.id, node.mailbox);
  XBT_DEBUG("New node with id %s (%08x)", node.mailbox, node.id);
  
  int i,j,d;
  for (i=0; i<LEVELS_COUNT; i++){
    d = domain(node.id, i);
    for (j=0; j<LEVEL_SIZE; j++)
      node.routing_table[i][j] = (d==j) ? node.id : -1;
  }

  for (i=0; i<NEIGHBORHOOD_SIZE; i++)
    node.neighborhood_set[i] = -1;

  for (i=0; i<NAMESPACE_SIZE; i++)
    node.namespace_set[i] = -1;

  if (argc == 3) { // first ring
    XBT_DEBUG("Hey! Let's create the system.");
    deadline = xbt_str_parse_double(argv[2], "Invalid deadline: %s");
    create(&node);
    join_success = 1;
  }
  else {
    node.known_id = xbt_str_parse_int(argv[2], "Invalid known ID: %s");
    double sleep_time = xbt_str_parse_double(argv[3], "Invalid sleep time: %s");
    deadline = xbt_str_parse_double(argv[4], "Invalid deadline: %s");

    // sleep before starting
    XBT_DEBUG("Let's sleep during %f", sleep_time);
    MSG_process_sleep(sleep_time);
    XBT_DEBUG("Hey! Let's join the system.");

    join_success = join(&node);
  }

  if (join_success) {
    XBT_DEBUG("Waiting ….");

    while (MSG_get_clock() < init_time + deadline
//      && MSG_get_clock() < node.last_change_date + 1000
        && MSG_get_clock() < max_simulation_time) {
      if (node.comm_receive == NULL) {
        task_received = NULL;
        node.comm_receive = MSG_task_irecv(&task_received, node.mailbox);
        // FIXME: do not make MSG_task_irecv() calls from several functions
      }
      if (!MSG_comm_test(node.comm_receive)) {
        MSG_process_sleep(5);
      } else {
        // a transfer has occurred

        msg_error_t status = MSG_comm_get_status(node.comm_receive);

        if (status != MSG_OK) {
          XBT_DEBUG("Failed to receive a task. Nevermind.");
          MSG_comm_destroy(node.comm_receive);
          node.comm_receive = NULL;
        }
        else {
          // the task was successfully received
          MSG_comm_destroy(node.comm_receive);
          node.comm_receive = NULL;
          handle_task(&node, task_received);
        }
      }

    }
    print_node(&node);
  }
  return 1;
}
static int master(int argc, char *argv[])
{
  int i;

  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
  double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
  double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");
  long workers_count = xbt_str_parse_int(argv[4], "Invalid amount of workers: %s");

  XBT_INFO("Got %ld workers and %ld tasks to process", workers_count, number_of_tasks);

  for (i = 0; i < number_of_tasks; i++) {
    char mailbox[256];
    snprintf(mailbox, 255, "worker-%ld", i % workers_count);

    msg_task_t task = MSG_task_create("Task", task_comp_size, task_comm_size, xbt_new0(double, 1));
    *((double *) task->data) = MSG_get_clock();

    switch ( MSG_task_send_with_timeout(task,mailbox,10.0) ) {
    case MSG_OK:
      XBT_INFO("Send completed");
      break;

    case MSG_HOST_FAILURE:
      XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
      free(task->data);
      MSG_task_destroy(task);
      return 0;

    case MSG_TRANSFER_FAILURE:
      XBT_INFO("Mmh. Something went wrong with '%s'. Nevermind. Let's keep going!", mailbox);
      free(task->data);
      MSG_task_destroy(task);
      break;

    case MSG_TIMEOUT:
      XBT_INFO ("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", mailbox);
      free(task->data);
      MSG_task_destroy(task);
      break;

    default:
      xbt_die( "Unexpected behavior");
    }
  }

  XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over.");
  for (i = 0; i < workers_count; i++) {
    char mailbox[256];
    snprintf(mailbox, 255, "worker-%ld", i % workers_count);
    msg_task_t task = MSG_task_create("finalize", 0, 0, FINALIZE);

    switch (MSG_task_send_with_timeout(task,mailbox,1.0)) {
    case MSG_HOST_FAILURE:
      XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
      MSG_task_destroy(task);
      break;

    case MSG_TRANSFER_FAILURE:
      XBT_INFO("Mmh. Can't reach '%s'! Nevermind. Let's keep going!", mailbox);
      MSG_task_destroy(task);
      break;

    case MSG_TIMEOUT:
      XBT_INFO("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", mailbox);
      MSG_task_destroy(task);
      break;

    case MSG_OK:
      /* nothing */
      break;

    default:
      xbt_die("Unexpected behavior with '%s'", mailbox);
    }
  }

  XBT_INFO("Goodbye now!");
  return 0;
}
Example #24
0
/** Receiver function  */
int slave(int argc, char *argv[])
{

  msg_task_t task = NULL;
  int a;
  int id = 0;
#ifdef HAVE_LATENCY_BOUND_TRACKING
  int limited_latency = 0;
#endif
  double remaining = 0;
  char id_alias[10];

  if (argc != 2) {
    XBT_INFO("Strange number of arguments expected 1 got %d", argc - 1);
  }

  id = atoi(argv[1]);
  sprintf(id_alias, "%d", id);
  int trace_id = id;

  a = MSG_task_receive(&(task), id_alias);

  count_finished--;
  if(count_finished == 0){
      timer_start = 0;
  }



  if (a != MSG_OK) {
    XBT_INFO("Hey?! What's up?");
    xbt_die("Unexpected behavior.");
  }

  elapsed_time = MSG_get_clock() - start_time;
  
  
  if (!bool_printed) {
    bool_printed = 1;
    
    for (id = 0; id < NTASKS; id++) {
      if (gl_task_array[id] == NULL) continue;
      if (gl_task_array[id] == task) {
#ifdef HAVE_LATENCY_BOUND_TRACKING
        limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
        if (limited_latency) {
          XBT_INFO("WARNING FLOW[%d] is limited by latency!!", id);
        }
#endif
        XBT_INFO
            ("===> Estimated Bw of FLOW[%d] : %f ;  message from %s to %s  with remaining : %f",
             id, gl_data_size[id] / elapsed_time, masternames[id],
             slavenames[id], 0.0);
        MSG_task_destroy(gl_task_array[id]);
        gl_task_array[id]=NULL;
      } else {
        remaining =
            MSG_task_get_remaining_communication(gl_task_array[id]);
#ifdef HAVE_LATENCY_BOUND_TRACKING
        limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);

        if (limited_latency) {
          XBT_INFO("WARNING FLOW[%d] is limited by latency!!", id);
        }
#endif
        XBT_INFO
            ("===> Estimated Bw of FLOW[%d] : %f ;  message from %s to %s  with remaining : %f",
             id, (gl_data_size[id] - remaining) / elapsed_time,
             masternames[id], slavenames[id], remaining);
        if(remaining==0) {
          MSG_task_destroy(gl_task_array[id]);
          gl_task_array[id]=NULL;
        }
      }
    }
    bool_printed = 2;
  }
  char mark[100];
  snprintf(mark, 100, "flow_%d_finished", trace_id);
  TRACE_mark("endmark", mark);

  if(bool_printed==2 && gl_task_array[trace_id]) MSG_task_destroy(gl_task_array[trace_id]);

  return 0;
}                               /* end_of_slave */
Example #25
0
/**
 * @brief  Kill all copies of a task.
 * @param  ti  The task information of any task instance.
 */
static void finish_all_task_copies (task_info_t ti)
{
    int     i;
    int     phase = ti->phase;
    size_t  tid = ti->id;

    for (i = 0; i < MAX_SPECULATIVE_COPIES; i++)
    {
	if (job.task_list[phase][tid][i] != NULL)
	{
	    MSG_task_cancel (job.task_list[phase][tid][i]);
	    //FIXME: MSG_task_destroy (job.task_list[phase][tid][i]);
	    job.task_list[phase][tid][i] = NULL;
	    fprintf (tasks_log, "%d_%zu_%d,%s,%zu,%.3f,END,%.3f\n", ti->phase, tid, i, (ti->phase==MAP?"MAP":"REDUCE"), ti->wid, MSG_get_clock (), ti->shuffle_end);
	}
    }
}
Example #26
0
    else
      snprintf(mailbox, 255, "%d", rank + 1);
    XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"", rank, task->name, mailbox);
    MSG_task_send(task, mailbox);
  }
  return 0;
}

int main(int argc, char* argv[])
{
  MSG_init(&argc, argv);
  xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
  MSG_create_environment(argv[1]); /* - Load the platform description */
  xbt_dynar_t hosts = MSG_hosts_as_dynar();

  XBT_INFO("Number of hosts '%zu'", MSG_get_host_number());
  unsigned int i;
  msg_host_t h;
  xbt_dynar_foreach (hosts, i,
                     h) { /* - Give a unique rank to each host and create a @ref relay_runner process on each */
    char* name_host = bprintf("%u", i);
    MSG_process_create(name_host, relay_runner, NULL, h);
    free(name_host);
  }
  xbt_dynar_free(&hosts);

  int res = MSG_main(); /* - Run the simulation */
  XBT_INFO("Simulation time %g", MSG_get_clock());
  return res != MSG_OK;
}
Example #27
0
/** @brief  Main master function. */
int master (int argc, char* argv[])
{
    heartbeat_t  heartbeat;
    msg_error_t  status;
    msg_host_t   worker;
    msg_task_t   msg = NULL;
    size_t       wid;
    task_info_t  ti;
    double total_cpu_time = 0.0;
    double total_task_time = 0.0;

    print_config ();
    XBT_INFO ("JOB BEGIN"); XBT_INFO (" ");

    tasks_log = fopen ("tasks.csv", "w");
    fprintf (tasks_log, "task_id,phase,worker_id,time,action,shuffle_end\n");

    while (job.tasks_pending[MAP] + job.tasks_pending[REDUCE] > 0)
    {
	msg = NULL;
	status = receive (&msg, MASTER_MAILBOX);
	if (status == MSG_OK)
	{
	    worker = MSG_task_get_source (msg);
	    wid = get_worker_id (worker);

	    if (message_is (msg, SMS_HEARTBEAT))
	    {
		heartbeat = &job.heartbeats[wid];

		if (is_straggler (worker))
		{
		    set_speculative_tasks (worker);
		}
		else
		{
		    if (heartbeat->slots_av[MAP] > 0)
			send_scheduler_task(MAP, wid);

		    if (heartbeat->slots_av[REDUCE] > 0)
			send_scheduler_task(REDUCE, wid);
		}
	    }
	    else if (message_is (msg, SMS_TASK_DONE))
	    {
		ti = (task_info_t) MSG_task_get_data (msg);

		if (job.task_status[ti->phase][ti->id] != T_STATUS_DONE)
		{
		    job.task_status[ti->phase][ti->id] = T_STATUS_DONE;
		    finish_all_task_copies (ti);
		    job.tasks_pending[ti->phase]--;
		    if (job.tasks_pending[ti->phase] <= 0)
		    {
			XBT_INFO (" ");
			XBT_INFO ("%s PHASE DONE", (ti->phase==MAP?"MAP":"REDUCE"));
			XBT_INFO (" ");
		    }
                    ti->finished_time = MSG_get_clock();
                    ti->elapsed_time = ti->finished_time - ti->start_time;

                    total_task_time += ti->elapsed_time;
                    total_cpu_time  += ti->cpu_time;
		}
		xbt_free_ref (&ti);
	    }
	    MSG_task_destroy (msg);
	}
    }

    fclose (tasks_log);

    job.finished = 1;

    print_config ();
    print_stats ();

    XBT_INFO ("JOB END");
    XBT_INFO ("\tclock_time: %f", MSG_get_clock());
    XBT_INFO ("\ttotal_task_time: %f(%f)", total_task_time, total_task_time / MSG_get_clock());
    XBT_INFO ("\ttotal_cpu_time: %f(%f)", total_cpu_time, total_cpu_time / MSG_get_clock());

    return 0;
}
Example #28
0
/** Emitter function  */
int master(int argc, char *argv[])
{
  int slaves_count = 0;
  msg_host_t *slaves = NULL;
  int number_of_tasks = 0;
  double task_comp_size = 0;
  double task_comm_size = 0;
  int i;

  number_of_tasks = 3*argc;
  task_comp_size = 2400000*argc;
  task_comm_size = 1000000;

  {                             /* Process organization */
    slaves_count = argc;
    slaves = xbt_new0(msg_host_t, slaves_count);

    for (i = 0; i < argc; i++) {
      slaves[i] = MSG_host_by_name(argv[i]);
      if (slaves[i] == NULL) {
        XBT_INFO("Unknown host %s. Stopping Now! ", argv[i]);
        abort();
      }
    }
  }

  XBT_INFO("Got %d slave(s) :", slaves_count);
  for (i = 0; i < slaves_count; i++)
    XBT_INFO("%s", MSG_host_get_name(slaves[i]));

  XBT_INFO("Got %d task to process :", number_of_tasks);

  for (i = 0; i < number_of_tasks; i++) {
    msg_task_t task = MSG_task_create("Task", task_comp_size, task_comm_size,
                                    xbt_new0(double, 1));
    int a;
    *((double *) task->data) = MSG_get_clock();

    a = MSG_task_send(task,MSG_host_get_name(slaves[i % slaves_count]));

    if (a == MSG_OK) {
      XBT_INFO("Send completed");
    } else {
      XBT_INFO("Hey ?! What's up ? ");
      xbt_die( "Unexpected behavior");
    }
  }

  XBT_INFO
      ("All tasks have been dispatched. Let's tell everybody the computation is over.");
  for (i = 0; i < slaves_count; i++) {
    msg_task_t task = MSG_task_create("finalize", 0, 0, FINALIZE);
    int a = MSG_task_send(task,MSG_host_get_name(slaves[i]));
    if (a != MSG_OK) {
      XBT_INFO("Hey ?! What's up ? ");
      xbt_die("Unexpected behavior with '%s': %d", MSG_host_get_name(slaves[i]), a);
    }
  }

  XBT_INFO("Goodbye now!");
  free(slaves);
  return 0;
}                               /* end_of_master */
Example #29
0
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Msg_getClock(JNIEnv * env, jclass cls)
{
  return (jdouble) MSG_get_clock();
}
Example #30
0
int main(int argc, char *argv[]){
 msg_error_t res;
  const char *platform_file;
  const char *application_file;
  const char *description_file;

  MSG_init(&argc, argv);

  if (argc < 4) {
    printf("Usage: %s description_file platform_file deployment_file\n", argv[0]);
    printf("example: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0]);
    exit(1);
  }
  description_file = argv[1];
  platform_file = argv[2];
  application_file = argv[3];


  {                             /*  Simulation setting */
    MSG_create_environment(platform_file);
  }
  {                             /*   Application deployment */
    //read the description file in order to identify instances to launch
    FILE* fp = fopen(description_file, "r");
    if (fp == NULL)
      xbt_die("Cannot open %s", description_file);
    ssize_t read;
    char *line = NULL;
    size_t n = 0;
    int instance_size = 0;
    const char* instance_id = NULL;
    while ((read = xbt_getline(&line, &n, fp)) != -1 ){
      xbt_dynar_t elems = xbt_str_split_quoted_in_place(line);
      if(xbt_dynar_length(elems)<3){
        xbt_die ("Not enough elements in the line");
      }
      
      const char** line_char= xbt_dynar_to_array(elems); 
      instance_id = line_char[0];
      instance_size = atoi(line_char[2]);
      
      XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size);
      SMPI_app_instance_register(instance_id, smpi_replay,instance_size);

      xbt_free(line_char);
    }

    MSG_launch_application(application_file);
    SMPI_init();
  }
  res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());


  SMPI_finalize();
  if (res == MSG_OK)
    return 0;
  else
    return 1;

}