static int master(int argc, char *argv[])
{
  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");

  //setting the variable "is_master" (previously declared) to value 1
  TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "is_master", 1);

  TRACE_mark("msmark", "start_send_tasks");
  for (int i = 0; i < number_of_tasks; i++) {
    msg_task_t task = NULL;
    task = MSG_task_create("task", task_comp_size, task_comm_size, NULL);

    //setting the variable "task_creation" to value i
    TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "task_creation", i);

    //setting the category of task to "compute"
    //the category of a task must be defined before it is sent or executed
    MSG_task_set_category(task, "compute");
    MSG_task_send(task, "master_mailbox");
  }
  TRACE_mark("msmark", "finish_send_tasks");

  for (int i = 0; i < workers_count; i++) {
    msg_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
    MSG_task_set_category(finalize, "finalize");
    MSG_task_send(finalize, "master_mailbox");
  }

  return 0;
}
Example #2
0
static int master(int argc, char *argv[])
{
  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
  long workers_count = xbt_str_parse_int(argv[4], "Invalid amount of workers: %s");

  for (int i = 0; i < number_of_tasks; i++) {
    msg_task_t task = NULL;

    /* creating task and setting its category */
    if (i % 2) {
      task = MSG_task_create("task_compute", 10000000, 0, NULL);
      MSG_task_set_category(task, "compute");
    } else if (i % 3) {
      task = MSG_task_create("task_request", 10, 10, NULL);
      MSG_task_set_category(task, "request");
    } else {
      task = MSG_task_create("task_data", 10, 10000000, NULL);
      MSG_task_set_category(task, "data");
    }
    MSG_task_send(task, "master_mailbox");
  }

  for (int i = 0; i < workers_count; i++) {
    msg_task_t finalize = MSG_task_create("finalize", 0, 1000, 0);
    MSG_task_set_category(finalize, "finalize");
    MSG_task_send(finalize, "master_mailbox");
  }

  return 0;
}
Example #3
0
static int master(int argc, char *argv[])
{
  msg_task_t task = NULL;

  // I am the master of emigrant process,
  // I tell it where it must emigrate to.
  xbt_dynar_t destinations = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
  xbt_dynar_push_as (destinations, char*, xbt_strdup ("Tremblay"));
  xbt_dynar_push_as (destinations, char*, xbt_strdup ("Jupiter"));
  xbt_dynar_push_as (destinations, char*, xbt_strdup ("Fafard"));
  xbt_dynar_push_as (destinations, char*, xbt_strdup ("Ginette"));
  xbt_dynar_push_as (destinations, char*, xbt_strdup ("Bourassa"));
  xbt_dynar_push_as (destinations, char*, xbt_strdup ("Fafard"));
  xbt_dynar_push_as (destinations, char*, xbt_strdup ("Tremblay"));
  xbt_dynar_push_as (destinations, char*, xbt_strdup ("Ginette"));
  xbt_dynar_push_as (destinations, char*, NULL);

  char *destination;
  unsigned int i;
  xbt_dynar_foreach(destinations, i, destination){
    task = MSG_task_create("task", 0, 0, NULL);
    if (destination){
      MSG_task_set_data(task, xbt_strdup (destination));
    }
    MSG_task_set_category(task, "migration_order");
    MSG_task_send (task, "master_mailbox");
    task = NULL;
  }
Example #4
0
/** master */
int master(int argc, char *argv[])
{
  char *slavename = NULL;
  double task_comm_size = 0;
  msg_task_t todo;
  char id_alias[10];
  //unique id to control statistics
  int id = -1;

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

  XBT_DEBUG ("Master started");

  /* data size */
  int read;
  read = sscanf(argv[1], "%lg", &task_comm_size);
  xbt_assert(read, "Invalid argument %s\n", argv[1]);

  /* slave name */
  slavename = argv[2];
  id = atoi(argv[3]);
  sprintf(id_alias, "flow_%d", id);
  slavenames[id] = slavename;
  TRACE_category(id_alias);

  masternames[id] = MSG_host_get_name(MSG_host_self());

  {                             /*  Task creation.  */
    char sprintf_buffer[64] = "Task_0";
    todo = MSG_task_create(sprintf_buffer, 100*task_comm_size, task_comm_size, NULL);
    MSG_task_set_category(todo, id_alias);
    //keep track of running tasks
    gl_task_array[id] = todo;
    gl_data_size[id] = task_comm_size;
  }

  {                             /* Process organisation */
    MSG_get_host_by_name(slavename);
  }

  count_finished++;
  timer_start = 1 ;

  /* time measurement */
  sprintf(id_alias, "%d", id);
  start_time = MSG_get_clock();
  //MSG_task_execute(todo);
  MSG_task_send(todo, id_alias);
  end_time = MSG_get_clock();

  XBT_DEBUG ("Finished");
  return 0;
}                               /* end_of_master */
Example #5
0
/**
 * @brief  Send a task to a worker.
 * @param  phase     The current job phase.
 * @param  tid       The task ID.
 * @param  data_src  The ID of the DataNode that owns the task data.
 * @param  wid       The destination worker id.
 */
static void send_task (enum phase_e phase, size_t tid, size_t data_src, size_t wid)
{
    char         mailbox[MAILBOX_ALIAS_SIZE];
    int          i;
    double       cpu_required = 0.0;
    msg_task_t   task = NULL;
    task_info_t  task_info;

    cpu_required = user.task_cost_f (phase, tid, wid);

    task_info = xbt_new (struct task_info_s, 1);
    task = MSG_task_create (SMS_TASK, cpu_required, 0.0, (void*) task_info);

    task_info->phase = phase;
    task_info->id = tid;
    task_info->src = data_src;
    task_info->wid = wid;
    task_info->task = task;
    task_info->shuffle_end = 0.0;
    task_info->start_time = MSG_get_clock();
    task_info->finished_time = 0.0;
    task_info->elapsed_time = 0.0;
    task_info->cpu_time = 0.0;

    // for tracing purposes...
    MSG_task_set_category (task, (phase==MAP?"MAP":"REDUCE"));

    if (job.task_status[phase][tid] != T_STATUS_TIP_SLOW)
	job.task_status[phase][tid] = T_STATUS_TIP;

    job.heartbeats[wid].slots_av[phase]--;

    for (i = 0; i < MAX_SPECULATIVE_COPIES; i++)
    {
	if (job.task_list[phase][tid][i] == NULL)
	{
	    job.task_list[phase][tid][i] = task;
	    break;
	}
    }

    fprintf (tasks_log, "%d_%zu_%d,%s,%zu,%.3f,START,\n", phase, tid, i, (phase==MAP?"MAP":"REDUCE"), wid, MSG_get_clock ());

#ifdef VERBOSE
    XBT_INFO ("TX: %s > %s", SMS_TASK, MSG_host_get_name (config.workers[wid]));
#endif

    sprintf (mailbox, TASKTRACKER_MAILBOX, wid);
    xbt_assert (MSG_task_send (task, mailbox) == MSG_OK, "ERROR SENDING MESSAGE");

    job.task_instances[phase][tid]++;
}
Example #6
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 #7
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 */