示例#1
0
/**
 * \brief Returns the workstation list
 *
 * Use SD_workstation_get_number() to know the array size.
 * 
 * \return an array of \ref SD_workstation_t containing all workstations
 * \remark The workstation order in the returned array is generally different from the workstation creation/declaration order in the XML platform (we use a hash table internally).
 * \see SD_workstation_get_number()
 */
const SD_workstation_t *SD_workstation_get_list(void) {
  xbt_assert(SD_workstation_get_number() > 0, "There is no workstation!");

  if (sd_global->workstation_list == NULL)     /* this is the first time the function is called */
    sd_global->workstation_list = xbt_dynar_to_array(sg_hosts_as_dynar());

  return sd_global->workstation_list;
}
示例#2
0
/** Main function */
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;
  long i;

  MSG_init(&argc, argv);
  if (argc < 4) {
    printf("Usage: %s platform_file number_of_jobs number_of_slaves\n", argv[0]);
    printf("example: %s msg_platform.xml 10 5\n", argv[0]);
    exit(1);
  }

  MSG_function_register("master", master);
  MSG_function_register("slave", slave);

  MSG_create_environment(argv[1]);

  number_of_jobs = atol(argv[2]);
  number_of_slaves = atol(argv[3]);
  xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
  long number_max = xbt_dynar_length(host_dynar);
  XBT_INFO("Got %ld slaves, %ld tasks to process, and %ld hosts", number_of_slaves, number_of_jobs,number_max);

  msg_host_t *host_table =  xbt_dynar_to_array(host_dynar);
  //xbt_dynar_free(&host_dynar);

  MSG_process_create( "master",
                      master,
                      NULL,
                      host_table[my_random(number_max)]
                      );

  for(i = 0 ; i<number_of_slaves; i++)
  {
    char* name_host = bprintf("slave-%ld",i);
      MSG_process_create( name_host,
                          slave,
                          NULL,
                          host_table[my_random(number_max)]
                          );
      free(name_host);
  }
  xbt_free(host_table);

  res = MSG_main();

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

  if (res == MSG_OK)
    return 0;
  else
    return 1;
}                               /* end_of_main */
示例#3
0
static int runner(int argc, char *argv[])
{
  /* Retrieve the list of all hosts as an array of hosts */
  int hosts_count = MSG_get_host_number();
  msg_host_t *hosts = xbt_dynar_to_array(MSG_hosts_as_dynar());

  XBT_INFO("First, build a classical parallel task, with 1 Gflop to execute on each node, "
           "and 10MB to exchange between each pair");
  double *computation_amounts = xbt_new0(double, hosts_count);
  double *communication_amounts = xbt_new0(double, hosts_count * hosts_count);

  for (int i = 0; i < hosts_count; i++)
    computation_amounts[i] = 1e9; // 1 Gflop

  for (int i = 0; i < hosts_count; i++)
    for (int j = i + 1; j < hosts_count; j++)
      communication_amounts[i * hosts_count + j] = 1e7; // 10 MB

  msg_task_t ptask =
    MSG_parallel_task_create("parallel task", hosts_count, hosts, computation_amounts, communication_amounts, NULL);
  MSG_parallel_task_execute(ptask);
  MSG_task_destroy(ptask);
  /* The arrays communication_amounts and computation_amounts are not to be freed manually */

  XBT_INFO("Then, build a parallel task involving only computations and no communication (1 Gflop per node)");
  computation_amounts = xbt_new0(double, hosts_count);
  for (int i = 0; i < hosts_count; i++)
    computation_amounts[i] = 1e9; // 1 Gflop
  ptask = MSG_parallel_task_create("parallel exec", hosts_count, hosts, computation_amounts, NULL/* no comm */, NULL);
  MSG_parallel_task_execute(ptask);
  MSG_task_destroy(ptask);

  XBT_INFO("Then, build a parallel task with no computation nor communication (synchro only)");
  computation_amounts = xbt_new0(double, hosts_count);
  communication_amounts = xbt_new0(double, hosts_count * hosts_count); /* memset to 0 by xbt_new0 */
  ptask = MSG_parallel_task_create("parallel sync", hosts_count, hosts, computation_amounts, communication_amounts, NULL);
  MSG_parallel_task_execute(ptask);
  MSG_task_destroy(ptask);

   XBT_INFO("Finally, trick the ptask to do a 'remote execution', on host %s", MSG_host_get_name(hosts[1]));
  computation_amounts = xbt_new0(double, 1);
  computation_amounts[0] = 1e9; // 1 Gflop
  msg_host_t *remote = xbt_new(msg_host_t,1);
  remote[0] = hosts[1];
  ptask = MSG_parallel_task_create("remote exec", 1, remote, computation_amounts, NULL/* no comm */, NULL);
  MSG_parallel_task_execute(ptask);
  MSG_task_destroy(ptask);
  free(remote);

  XBT_INFO("Goodbye now!");
  free(hosts);
  return 0;
}
示例#4
0
int main(int argc, char *argv[]){
  msg_error_t res;

  MSG_init(&argc, argv);

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

  /*  Simulation setting */
  MSG_create_environment(argv[2]);

  /*   Application deployment: read the description file in order to identify instances to launch */
  FILE* fp = fopen(argv[1], "r");
  if (fp == NULL)
    xbt_die("Cannot open %s", argv[1]);
  char *line = NULL;
  size_t n   = 0;
  int instance_size = 0;
  const char* instance_id = NULL;
  while (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 = xbt_str_parse_int(line_char[2], "Invalid size: %s");

    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);
  }

  fclose(fp);

  MSG_launch_application(argv[3]);
  SMPI_init();

  res = MSG_main();

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

  SMPI_finalize();
  return res != MSG_OK;
}
示例#5
0
/** Emitter function  */
int test(int argc, char *argv[])
{
  xbt_dynar_t slaves_dynar;
  int slaves_count = 0;
  msg_host_t *slaves = NULL;
  double task_comp_size = 100000;
  double task_comm_size = 10000;
  double *computation_amount = NULL;
  double *communication_amount = NULL;
  msg_task_t ptask = NULL;
  int i, j;

  slaves_dynar = MSG_hosts_as_dynar();
  slaves_count = xbt_dynar_length(slaves_dynar);
  slaves = xbt_dynar_to_array(slaves_dynar);

  computation_amount = xbt_new0(double, slaves_count);
  communication_amount = xbt_new0(double, slaves_count * slaves_count);

  for (i = 0; i < slaves_count; i++)
    computation_amount[i] = task_comp_size;

  for (i = 0; i < slaves_count; i++)
    for (j = i + 1; j < slaves_count; j++)
      communication_amount[i * slaves_count + j] = task_comm_size;

  ptask = MSG_parallel_task_create("parallel task",
                                   slaves_count, slaves,
                                   computation_amount,
                                   communication_amount, NULL);
  MSG_parallel_task_execute(ptask);

  MSG_task_destroy(ptask);
  /* There is no need to free that! */
/*   free(communication_amount); */
/*   free(computation_amount); */

  XBT_INFO("Goodbye now!");
  free(slaves);
  return 0;
}
示例#6
0
/** @brief Returns the host list
 *
 * Uses sg_host_count() to know the array size.
 *
 * \return an array of \ref sg_host_t containing all the hosts in the platform.
 * \remark The host order in this array is generally different from the
 * creation/declaration order in the XML platform (we use a hash table
 * internally).
 * \see sg_host_count()
 */
sg_host_t *sg_host_list(void) {
  xbt_assert(sg_host_count() > 0, "There is no host!");
  return (sg_host_t*)xbt_dynar_to_array(sg_hosts_as_dynar());
}
示例#7
0
  }

  /* load the DOT file */
  dot = SD_dotload(argv[1]);

  /* Display all the tasks */
  XBT_INFO
      ("------------------- Display all tasks of the loaded DAG ---------------------------");
  xbt_dynar_foreach(dot, cursor, task) {
      SD_task_dump(task);
    }

  XBT_INFO
      ("--------------------- Transform the dynar into an array ---------------------------");
  cursor=0;
  dot_as_array = (SD_task_t*) xbt_dynar_to_array(dot);
  XBT_INFO
      ("----------------------------- dump tasks again ------------------------------------");
  while ((task=dot_as_array[cursor++])){
    SD_task_dump(task);
  }

  cursor=0;
  while ((task=dot_as_array[cursor++])){
    SD_task_destroy(task);
  }

  free(dot_as_array);

  /* exit */
  SD_exit();
示例#8
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 */
示例#9
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;

}
示例#10
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);
  xbt_dynar_t idle_hosts = xbt_dynar_new(sizeof(msg_host_t), NULL);
  msg_host_t request_host = NULL;

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

    msg_task_t request = NULL;
    while(MSG_task_listen(master_name)) {
      res = MSG_task_receive(&(request),master_name);
      xbt_assert(res == MSG_OK, "MSG_task_receive failed");
      request_host = MSG_task_get_data(request);
      xbt_dynar_push(idle_hosts, &request_host);
      MSG_task_destroy(request);
      request = NULL;
    }

    if(MSG_get_clock()>timeout) {
      if(xbt_dynar_length(idle_hosts) == workers_count) break;
      else {
	MSG_process_sleep(.1);
	continue;
      }
    }
    
    if(xbt_dynar_length(idle_hosts)<=0) {
      /* No request. Let's wait... */
      MSG_process_sleep(.1);
      continue;
    }

    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);

    xbt_dynar_shift(idle_hosts, &request_host);

    build_channel_name(channel,master_name, MSG_host_get_name(request_host));
    
    XBT_DEBUG("Sending \"%s\" to channel \"%s\"", task->name, channel);
    MSG_task_send(task, channel);
    XBT_DEBUG("Sent");
    i++;
  }

  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 */
示例#11
0
/** Emitter function  */
static 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);
  char channel[1024];

  int i;

  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");    /** - Number of tasks      */
  double comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");  /** - Task compute cost    */
  double comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");  /** - Task communication size */

  {                             /*  Task creation */
    char sprintf_buffer[64];

    todo = xbt_new0(msg_task_t, number_of_tasks);

    for (i = 0; i < number_of_tasks; i++) {
      sprintf(sprintf_buffer, "Task_%d", i);
      todo[i] = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
    }
  }

  {                             /* Process organization */
    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 %Ld tasks to process", workers_count, number_of_tasks);

  for (i = 0; i < number_of_tasks; i++) {
    build_channel_name(channel,master_name, MSG_host_get_name(workers[i % workers_count]));

    XBT_INFO("Sending \"%s\" to channel \"%s\"", todo[i]->name, channel);

    MSG_task_send(todo[i], channel);
    XBT_INFO("Sent");
  }

  XBT_INFO ("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("Goodbye now!");
  free(workers);
  free(todo);
  return 0;
}                               /* end_of_master */
示例#12
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);
    int number_of_tasks = 0;
    double task_comp_size = 0;
    double task_comm_size = 0;
    char channel[1024];

    int i;

    _XBT_GNUC_UNUSED int res = sscanf(argv[1], "%d", &number_of_tasks);
    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]);

    {   /*  Task creation */
        char sprintf_buffer[64];

        todo = xbt_new0(msg_task_t, number_of_tasks);

        for (i = 0; i < number_of_tasks; i++) {
            sprintf(sprintf_buffer, "Task_%d", i);
            todo[i] =
                MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size,
                                NULL);
        }
    }

    {   /* 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 %d tasks to process", workers_count,
             number_of_tasks);

    for (i = 0; i < number_of_tasks; i++) {
        build_channel_name(channel,master_name,
                           MSG_host_get_name(workers[i % workers_count]));

        XBT_INFO("Sending \"%s\" to channel \"%s\"", todo[i]->name, channel);

        MSG_task_send(todo[i], channel);
        XBT_INFO("Sent");
    }

    XBT_INFO
    ("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("Goodbye now!");
    free(workers);
    free(todo);
    return 0;
}                               /* end_of_master */