示例#1
0
/** Emitter function  */
int master(int argc, char *argv[])
{
  double task_comp_size = 5E7;
  double task_comm_size = 1E6;

  char mailbox[256];
  msg_task_t task = NULL;
  msg_host_t jupiter = MSG_get_host_by_name("Jupiter");
  sprintf(mailbox, "jupi");

  task = MSG_task_create("task on", task_comp_size, task_comm_size, NULL);
  XBT_INFO("Sending \"%s\"", task->name);
  if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
    MSG_task_destroy(task);

  MSG_process_sleep(1);
  MSG_host_off(jupiter);

  task = MSG_task_create("task off", task_comp_size, task_comm_size, NULL);
  XBT_INFO("Sending \"%s\"", task->name);
  if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
    MSG_task_destroy(task);

  MSG_host_on(jupiter);
  xbt_swag_t jupi_processes = MSG_host_get_process_list(jupiter);
  void *process;
  xbt_swag_foreach(process, jupi_processes) {
    MSG_process_kill(process);
  }
示例#2
0
int master(int argc, char *argv[])
{
  const char *hostname = MSG_host_get_name(MSG_host_self());
  int i;

  //the hostname has an empty HDD with a capacity of 100000 (bytes)
  TRACE_host_variable_set(hostname, "HDD_capacity", 100000);
  TRACE_host_variable_set(hostname, "HDD_utilization", 0);

  for (i = 0; i < 10; i++) {
    //create and execute a task just to make the simulated time advance
    msg_task_t task = MSG_task_create("task", 10000, 0, NULL);
    MSG_task_execute (task);
    MSG_task_destroy (task);

    //ADD: after the execution of this task, the HDD utilization increases by 100 (bytes)
    TRACE_host_variable_add(hostname, "HDD_utilization", 100);
  }

  for (i = 0; i < 10; i++) {
    //create and execute a task just to make the simulated time advance
    msg_task_t task = MSG_task_create("task", 10000, 0, NULL);
    MSG_task_execute (task);
    MSG_task_destroy (task);

    //SUB: after the execution of this task, the HDD utilization decreases by 100 (bytes)
    TRACE_host_variable_sub(hostname, "HDD_utilization", 100);
  }
  return 0;
}
示例#3
0
/** Emitter function  */
int master(int argc, char *argv[])
{
  long number_of_tasks = atol(argv[1]);
  long slaves_count = atol(argv[4]);

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

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

  for (i = 0; i < slaves_count; i++) {
    m_task_t finalize = MSG_task_create("finalize", 0, 1000, 0);
    TRACE_msg_set_task_category(finalize, "finalize");
    MSG_task_send(finalize, "master_mailbox");
  }

  return 0;
}
示例#4
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;
}
示例#5
0
static int execute_load_test(int argc, char* argv[])
{
  msg_host_t host = MSG_host_by_name("MyHost1");

  XBT_INFO("Initial peak speed: %.0E flop/s; number of flops computed so far: %.0E (should be 0)",
           MSG_host_get_speed(host), sg_host_get_computed_flops(host));

  double start = MSG_get_clock();
  XBT_INFO("Sleep for 10 seconds");
  MSG_process_sleep(10);

  XBT_INFO("Done sleeping %.2fs; peak speed: %.0E flop/s; number of flops computed so far: %.0E (nothing should have "
           "changed)",
           MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));

  // Run a task
  start            = MSG_get_clock();
  msg_task_t task1 = MSG_task_create("t1", 100E6, 0, NULL);
  XBT_INFO("Run a task of %.0E flops", MSG_task_get_flops_amount(task1));
  MSG_task_execute(task1);
  MSG_task_destroy(task1);

  XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
           "far: %.0E",
           MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));

  // ========= Change power peak =========
  int pstate = 2;
  sg_host_set_pstate(host, pstate);
  XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate,
           MSG_host_get_power_peak_at(host, pstate), MSG_host_get_speed(host));

  // Run a second task
  start = MSG_get_clock();
  task1 = MSG_task_create("t2", 100E6, 0, NULL);
  XBT_INFO("Run a task of %.0E flops", MSG_task_get_flops_amount(task1));
  MSG_task_execute(task1);
  MSG_task_destroy(task1);
  XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
           "far: %.0E",
           MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));

  start = MSG_get_clock();
  XBT_INFO("========= Requesting a reset of the computation counter");
  sg_host_load_reset(host);
  XBT_INFO("Sleep for 4 seconds");
  MSG_process_sleep(4);
  XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
           MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));

  // =========== Turn the other host off ==========
  XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed %.0f flops so far.",
           MSG_host_get_computed_flops(MSG_host_by_name("MyHost2")));
  MSG_host_off(MSG_host_by_name("MyHost2"));
  start = MSG_get_clock();
  MSG_process_sleep(10);
  XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
           MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_computed_flops(host));
  return 0;
}
int computation_fun(int argc, char *argv[])
{
  const char *pr_name = MSG_process_get_name(MSG_process_self());
  const char *host_name = MSG_host_get_name(MSG_host_self());
  double clock_sta, clock_end;
  atask = MSG_task_create("Task1", 1e9, 1e9, NULL);
  clock_sta = MSG_get_clock();
  XBT_INFO("%s:%s task 1 created %g", host_name, pr_name, clock_sta);
  MSG_task_execute(atask);
  clock_end = MSG_get_clock();

  XBT_INFO("%s:%s task 1 executed %g", host_name, pr_name, clock_end - clock_sta);

  MSG_task_destroy(atask);
  atask = NULL;

  MSG_process_sleep(1);

  atask = MSG_task_create("Task2", 1e10, 1e10, NULL);

  clock_sta = MSG_get_clock();
  XBT_INFO("%s:%s task 2 created %g", host_name, pr_name, clock_sta);
  MSG_task_execute(atask);
  clock_end = MSG_get_clock();

  XBT_INFO("%s:%s task 2 executed %g", host_name, pr_name, clock_end - clock_sta);

  MSG_task_destroy(atask);
  atask = NULL;

  return 0;
}
示例#7
0
文件: tasks.c 项目: rosacris/simgrid
/** Emitter function  */
int master(int argc, char *argv[])
{
  long number_of_tasks = atol(argv[1]);
  double task_comp_size = atof(argv[2]);
  double task_comm_size = atof(argv[3]);
  long slaves_count = atol(argv[4]);
  XBT_INFO("master %ld %f %f %ld", number_of_tasks, task_comp_size,
        task_comm_size, slaves_count);

  int i;
  for (i = 0; i < number_of_tasks; i++) {
    char task_name[100];
    snprintf (task_name, 100, "task-%d", i);
    m_task_t task = NULL;
    task = MSG_task_create(task_name, task_comp_size, task_comm_size, NULL);

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

  for (i = 0; i < slaves_count; i++) {
    char task_name[100];
    snprintf (task_name, 100, "task-%d", i);
    m_task_t finalize = MSG_task_create(task_name, 0, 0, xbt_strdup("finalize"));
    TRACE_msg_set_task_category(finalize, "finalize");
    MSG_task_send(finalize, "master_mailbox");
  }

  return 0;
}
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;
}
示例#9
0
static void send_mrsg_data (msg_task_t msg)
{
    char         mailbox[MAILBOX_ALIAS_SIZE];
    double       data_size;
    size_t       my_id;
    mrsg_task_info_t  ti;

    my_id = get_mrsg_worker_id (MSG_host_self ());

    sprintf (mailbox, TASK_MRSG_MAILBOX,
	    get_mrsg_worker_id (MSG_task_get_source (msg)),
	    MSG_process_get_PID (MSG_task_get_sender (msg)));

    if (mrsg_message_is (msg, SMS_GET_MRSG_CHUNK))
    {
	MSG_task_dsend (MSG_task_create ("DATA-C", 0.0, config_mrsg.mrsg_chunk_size, NULL), mailbox, NULL);
    }
    else if (mrsg_message_is (msg, SMS_GET_INTER_MRSG_PAIRS))
    {
	ti = (mrsg_task_info_t) MSG_task_get_data (msg);
	data_size = job_mrsg.map_output[my_id][ti->mrsg_tid] - ti->map_output_copied[my_id];
	MSG_task_dsend (MSG_task_create ("DATA-IP", 0.0, data_size, NULL), mailbox, NULL);
    }

    MSG_task_destroy (msg);
}
示例#10
0
文件: ms.c 项目: rosacris/simgrid
/** Emitter function  */
int master(int argc, char *argv[])
{
  long number_of_tasks = atol(argv[1]);
  double task_comp_size = atof(argv[2]);
  double task_comm_size = atof(argv[3]);
  long slaves_count = atol(argv[4]);

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

  TRACE_mark("msmark", "start_send_tasks");
  int i;
  for (i = 0; i < number_of_tasks; i++) {
    m_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("task_creation", i);

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

  for (i = 0; i < slaves_count; i++) {
    m_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
    TRACE_msg_set_task_category(finalize, "finalize");
    MSG_task_send(finalize, "master_mailbox");
  }

  return 0;
}
示例#11
0
static int coordinator(int argc, char *argv[])
{
  int CS_used = 0;              // initially the CS is idle

  while (1) {
    msg_task_t task = NULL;
    MSG_task_receive(&task, "coordinator");
    const char *kind = MSG_task_get_name(task); //is it a request or a release?
    if (!strcmp(kind, "request")) {     // that's a request
      char *req = MSG_task_get_data(task);
      if (CS_used) {
        XBT_INFO("CS already used.");
        msg_task_t answer = MSG_task_create("not grant", 0, 1000, NULL);
        MSG_task_send(answer, req);
      } else {                  // can serve it immediately
        XBT_INFO("CS idle. Grant immediately");
        msg_task_t answer = MSG_task_create("grant", 0, 1000, NULL);
        MSG_task_send(answer, req);
        CS_used = 1;
      }
    } else {                    // that's a release. Check if someone was waiting for the lock
      XBT_INFO("CS release. resource now idle");
      CS_used = 0;
    }
    MSG_task_destroy(task);
    kind = NULL;
  }

  return 0;
}
示例#12
0
/** Emitter function  */
int master(int argc, char *argv[])
{
  int i;

  for (i = 1; i <= number_of_jobs; i++) {
    char mailbox[256];
    char sprintf_buffer[256];
    msg_task_t task = NULL;

    sprintf(mailbox, "slave-%ld", i % number_of_slaves);
    sprintf(sprintf_buffer, "Task_%d", i);
    task =
        MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size,
                        NULL);
    XBT_DEBUG("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name,
          number_of_jobs, mailbox);

    MSG_task_send(task, mailbox);
  }

  XBT_DEBUG
      ("All tasks have been dispatched. Let's tell everybody the computation is over.");
  for (i = 0; i < number_of_slaves; i++) {
    char mailbox[80];

    sprintf(mailbox, "slave-%ld", i % number_of_slaves);
    msg_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
    MSG_task_send(finalize, mailbox);
  }

  XBT_DEBUG("Goodbye now!");
  return 0;
}                               /* end_of_master */
示例#13
0
static int server(int argc, char *argv[])
{
   msg_task_t task =  MSG_task_create("a", 0, 0, (char*)"Some data");
   MSG_task_isend(task, "mailbox");

   xbt_assert(MSG_task_listen("mailbox")); // True (1)
   XBT_INFO("Task listen works on regular mailboxes");
   task = NULL;
   MSG_task_receive(&task, "mailbox");
   xbt_assert(!strcmp("Some data", MSG_task_get_data(task)), "Data received: %s", (char*)MSG_task_get_data(task));
   MSG_task_destroy(task);
   XBT_INFO("Data successfully received from regular mailbox");

   MSG_mailbox_set_async("mailbox2");
   task = MSG_task_create("b", 0, 0, (char*)"More data");
   MSG_task_isend(task, "mailbox2");

   xbt_assert(MSG_task_listen("mailbox2")); // used to break.
   XBT_INFO("Task listen works on asynchronous mailboxes");
   task = NULL;
   MSG_task_receive(&task, "mailbox2");
   xbt_assert(!strcmp("More data", MSG_task_get_data(task)));
   MSG_task_destroy(task);
   XBT_INFO("Data successfully received from asynchronous mailbox");

   return 0;
}
示例#14
0
文件: peer.c 项目: rosacris/simgrid
/** Sender function  */
int sender(int argc, char *argv[])
{
  long number_of_tasks = atol(argv[1]);
  double task_comp_size = atof(argv[2]);
  double task_comm_size = atof(argv[3]);
  long receivers_count = atol(argv[4]);
  double sleep_start_time = atof(argv[5]);
  double sleep_test_time = atof(argv[6]);

  XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time,
        sleep_test_time);

  msg_comm_t comm = NULL;
  int i;
  m_task_t task = NULL;
  MSG_process_sleep(sleep_start_time);
  for (i = 0; i < number_of_tasks; i++) {
    char mailbox[256];
    char sprintf_buffer[256];

    sprintf(mailbox, "receiver-%ld", i % receivers_count);
    sprintf(sprintf_buffer, "Task_%d", i);

    task =
        MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size,
                        NULL);
    comm = MSG_task_isend(task, mailbox);
    XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i);

    if (sleep_test_time == 0) {
      MSG_comm_wait(comm, -1);
    } else {
      while (MSG_comm_test(comm) == 0) {
        MSG_process_sleep(sleep_test_time);
      };
      MSG_comm_destroy(comm);
    }

  }

  for (i = 0; i < receivers_count; i++) {
    char mailbox[80];
    sprintf(mailbox, "receiver-%ld", i % receivers_count);
    task = MSG_task_create("finalize", 0, 0, 0);
    comm = MSG_task_isend(task, mailbox);
    XBT_INFO("Send to receiver-%ld finalize", i % receivers_count);
    if (sleep_test_time == 0) {
      MSG_comm_wait(comm, -1);
    } else {
      while (MSG_comm_test(comm) == 0) {
        MSG_process_sleep(sleep_test_time);
      };
      MSG_comm_destroy(comm);
    }

  }

  XBT_INFO("Goodbye now!");
  return 0;
}                               /* end_of_sender */
示例#15
0
/* Sender process expects 6 arguments: */
static int sender(int argc, char *argv[])
{
  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");        /* - number of tasks */
  double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s"); /* - computational cost */
  double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s"); /* - communication cost */
  long receivers_count = xbt_str_parse_int(argv[4], "Invalid amount of receivers: %s");    /* - number of receivers */
  double sleep_start_time = xbt_str_parse_double(argv[5], "Invalid sleep start time: %s"); /* - start time */
  double sleep_test_time = xbt_str_parse_double(argv[6], "Invalid test time: %s");         /* - test time */

  XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);

  int i;
  msg_task_t task = NULL;
  msg_comm_t comm = NULL;
  MSG_process_sleep(sleep_start_time);
  for (i = 0; i < number_of_tasks; i++) {
    char mailbox[256];
    char snprintf_buffer[256];

    snprintf(mailbox,255, "receiver-%ld", i % receivers_count);
    snprintf(snprintf_buffer,255, "Task_%d", i);

    /* This process first creates a task and send it asynchronously with @ref MSG_task_isend. Then, if: */
    task = MSG_task_create(snprintf_buffer, task_comp_size, task_comm_size, NULL);
    comm = MSG_task_isend(task, mailbox);
    XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i);

    if (sleep_test_time > 0) { /* - "test_time" is set to 0, wait on @ref MSG_comm_wait */
      while (MSG_comm_test(comm) == 0) { /* - Call @ref MSG_comm_test every "test_time" otherwise */
        MSG_process_sleep(sleep_test_time);
      };
    } else {
      MSG_comm_wait(comm, -1);
    }
    MSG_comm_destroy(comm);
  }

  for (i = 0; i < receivers_count; i++) {
    char mailbox[80];
    snprintf(mailbox,79, "receiver-%ld", i % receivers_count);
    task = MSG_task_create("finalize", 0, 0, 0);
    comm = MSG_task_isend(task, mailbox);
    XBT_INFO("Send to receiver-%ld finalize", i % receivers_count);
    if (sleep_test_time > 0) {
      while (MSG_comm_test(comm) == 0) {
        MSG_process_sleep(sleep_test_time);
      }
    } else {
      MSG_comm_wait(comm, -1);
    }
    MSG_comm_destroy(comm);
  }

  XBT_INFO("Goodbye now!");
  return 0;
}
示例#16
0
static void action_reduce(const char *const *action)
{
  int i;
  char *reduce_identifier;
  char mailbox[80];
  double comm_size = parse_double(action[2]);
  double comp_size = parse_double(action[3]);
  msg_task_t comp_task = NULL;
  const char *process_name;
  double clock = MSG_get_clock();

  process_globals_t counters =
      (process_globals_t) MSG_process_get_data(MSG_process_self());

  xbt_assert(communicator_size, "Size of Communicator is not defined, "
             "can't use collective operations");

  process_name = MSG_process_get_name(MSG_process_self());

  reduce_identifier = bprintf("reduce_%d", counters->reduce_counter++);

  if (!strcmp(process_name, "p0")) {
    XBT_DEBUG("%s: %s is the Root", reduce_identifier, process_name);

    msg_comm_t *comms = xbt_new0(msg_comm_t, communicator_size - 1);
    msg_task_t *tasks = xbt_new0(msg_task_t, communicator_size - 1);
    for (i = 1; i < communicator_size; i++) {
      sprintf(mailbox, "%s_p%d_p0", reduce_identifier, i);
      comms[i - 1] = MSG_task_irecv(&(tasks[i - 1]), mailbox);
    }
    MSG_comm_waitall(comms, communicator_size - 1, -1);
    for (i = 1; i < communicator_size; i++) {
      MSG_comm_destroy(comms[i - 1]);
      MSG_task_destroy(tasks[i - 1]);
    }
    xbt_free(comms);
    xbt_free(tasks);

    comp_task = MSG_task_create("reduce_comp", comp_size, 0, NULL);
    XBT_DEBUG("%s: computing 'reduce_comp'", reduce_identifier);
    MSG_task_execute(comp_task);
    MSG_task_destroy(comp_task);
    XBT_DEBUG("%s: computed", reduce_identifier);

  } else {
    XBT_DEBUG("%s: %s sends", reduce_identifier, process_name);
    sprintf(mailbox, "%s_%s_p0", reduce_identifier, process_name);
    XBT_DEBUG("put on %s", mailbox);
    MSG_task_send(MSG_task_create(reduce_identifier, 0, comm_size, NULL),
                  mailbox);
  }

  log_action(action, MSG_get_clock() - clock);
  xbt_free(reduce_identifier);
}
示例#17
0
文件: e2.c 项目: cemsbr/simgrid
int dvfs(int argc, char *argv[])
{
  msg_host_t host = NULL;
  msg_task_t task1 = NULL;
  double task_time = 0;
  host = MSG_get_host_by_name("MyHost1");


  double current_peak = MSG_get_host_current_power_peak(host);
  XBT_INFO("Current power peak=%lf", current_peak);

  double consumed_energy = MSG_get_host_consumed_energy(host);
  XBT_INFO("Total energy (Joules): %lf", consumed_energy);

  // Run a task
  task1 = MSG_task_create ("t1", 100E6, 0, NULL);
  MSG_task_execute (task1);
  MSG_task_destroy(task1);

  task_time = MSG_get_clock();
  XBT_INFO("Task1 simulation time: %le", task_time);
  consumed_energy = MSG_get_host_consumed_energy(host);
  XBT_INFO("Total energy (Joules): %lf", consumed_energy);

  // ========= Change power peak =========
  int peak_index=2;
  double peak_at = MSG_get_host_power_peak_at(host, peak_index);
  XBT_INFO("=========Changing power peak value to %lf (at index %d)", peak_at, peak_index);

  MSG_set_host_power_peak_at(host, peak_index);

  // Run a second task
  task1 = MSG_task_create ("t2", 100E6, 0, NULL);
  MSG_task_execute (task1);
  MSG_task_destroy(task1);

  task_time = MSG_get_clock() - task_time;
  XBT_INFO("Task2 simulation time: %le", task_time);

  consumed_energy = MSG_get_host_consumed_energy(host);
  XBT_INFO("Total energy (Joules): %lf", consumed_energy);


  MSG_process_sleep(3);

  task_time = MSG_get_clock() - task_time;
  XBT_INFO("Task3 (sleep) simulation time: %le", task_time);
  consumed_energy = MSG_get_host_consumed_energy(host);
  XBT_INFO("Total energy (Joules): %lf", consumed_energy);


  return 0;
}
示例#18
0
static int client(int argc, char *argv[])
{
  int my_pid = MSG_process_get_PID(MSG_process_self());

  char *my_mailbox = xbt_strdup(argv[1]);
  msg_task_t grant = NULL, release = NULL;

  while(1){
    XBT_INFO("Ask the request");
    MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");

    if(strcmp(my_mailbox, "1") == 0){
      r = 1;
      cs = 0;
      XBT_INFO("Propositions changed : r=1, cs=0");
    }

    MSG_task_receive(&grant, my_mailbox);
    const char *kind = MSG_task_get_name(grant);

    if((strcmp(my_mailbox, "1") == 0) && (strcmp("grant", kind) == 0)){
      cs = 1;
      r = 0;
      XBT_INFO("Propositions changed : r=0, cs=1");
    }

    MSG_task_destroy(grant);
    grant = NULL;
    kind = NULL;

    XBT_INFO("%s got the answer. Sleep a bit and release it", argv[1]);

    MSG_process_sleep(1);

    release = MSG_task_create("release", 0, 1000, NULL);
    MSG_task_send(release, "coordinator");

    release = NULL;

    MSG_process_sleep(my_pid);

    if(strcmp(my_mailbox, "1") == 0){
      cs=0;
      r=0;
      XBT_INFO("Propositions changed : r=0, cs=0");
    }
    
  }
  return 0;
}
示例#19
0
static int dvfs(int argc, char* argv[])
{
  double workload = 100E6;
  msg_host_t host = MSG_host_self();

  int nb = MSG_host_get_nb_pstates(host);
  XBT_INFO("Count of Processor states=%d", nb);

  double current_peak = MSG_host_get_speed(host);
  XBT_INFO("Current power peak=%f", current_peak);

  // Run a task
  msg_task_t task1 = MSG_task_create("t1", workload, 0, NULL);
  MSG_task_execute(task1);
  MSG_task_destroy(task1);

  double task_time = MSG_get_clock();
  XBT_INFO("Task1 simulation time: %e", task_time);

  // Change power peak
  int new_pstate = 2;
  xbt_assert(new_pstate < nb, "Cannot set the host %s at pstate %d because it only provides %d pstates.",
             MSG_host_get_name(host), new_pstate, nb);

  double peak_at = MSG_host_get_power_peak_at(host, new_pstate);
  XBT_INFO("Changing power peak value to %f (at index %d)", peak_at, new_pstate);

  MSG_host_set_pstate(host, new_pstate);

  current_peak = MSG_host_get_speed(host);
  XBT_INFO("Current power peak=%f", current_peak);

  // Run a second task
  task1 = MSG_task_create("t1", workload, 0, NULL);
  MSG_task_execute(task1);
  MSG_task_destroy(task1);

  task_time = MSG_get_clock() - task_time;
  XBT_INFO("Task2 simulation time: %e", task_time);

  // Verify the default pstate is set to 0
  host    = MSG_host_by_name("MyHost2");
  int nb2 = MSG_host_get_nb_pstates(host);
  XBT_INFO("Count of Processor states=%d", nb2);

  double current_peak2 = MSG_host_get_speed(host);
  XBT_INFO("Current power peak=%f", current_peak2);
  return 0;
}
示例#20
0
int client(int argc, char *argv[])
{
  msg_task_t task1 =
      MSG_task_create("task", 0, 10000, (void *) atol(argv[1]));
  msg_task_t task2 =
      MSG_task_create("task", 0, 10000, (void *) atol(argv[1]));

  XBT_INFO("Send %d!", atoi(argv[1]));
  MSG_task_send(task1, "mymailbox");

  XBT_INFO("Send %d!", atoi(argv[1]));
  MSG_task_send(task2, "mymailbox");

  return 0;
}
示例#21
0
// this function permit to send to the node "mailbox" the task number i
void send_task(int i, char * mailbox, char * myMailbox) {
	msg_task_t task = NULL;
	char task_name[TASK_NAME_SIZE];
	struct clientDataTask * data = (struct clientDataTask *) malloc(sizeof(struct clientDataTask));

	//printf("%s: I send a request to %s\n", myMailbox, mailbox);

	sprintf(task_name, "task-%d", i);
	strcpy(data->mailbox, myMailbox); 

	if (random_target_LOC == NOT_RANDOM) {
		if (simulator == ARANTES) {
			data->target_LOC = value_target_LOC_stationary;
			data->rangeReputationPrimaryToRequest = 0.1;
		}
		else {
			data->target_LOC = value_target_LOC_stationary;
			data->rangeReputationPrimaryToRequest = 0.90;
		}
	}
	else {
		if (simulator == ARANTES) {
			data->target_LOC = (double)(rand() % 51) / 100.0;
			data->rangeReputationPrimaryToRequest = 0.1;
		}
		else {
			data->target_LOC = (50.0 + ((double)(rand() % 51))) / 100.0;
			data->rangeReputationPrimaryToRequest = 0.1;
		}
	}

	data->start_time = MSG_get_clock();
	task = MSG_task_create (task_name, task_compute_duration, task_message_size, data);
	MSG_task_send(task, mailbox);
}
示例#22
0
/** Receiver function  */
int worker(int argc, char *argv[])
{
  msg_task_t task = NULL;
  _XBT_GNUC_UNUSED int res;
  char channel[1024];

  const char *my_master = MSG_process_get_data(MSG_process_self());
  build_channel_name(channel, my_master, MSG_host_get_name(MSG_host_self()));

  XBT_DEBUG("Receiving on channel \"%s\"", channel);

  while (1) {
    /* Send a request */
    msg_task_t request = MSG_task_create("request", 0, 0, MSG_host_self());
    MSG_task_send(request, my_master);

    res = MSG_task_receive(&(task),channel);
    xbt_assert(res == MSG_OK, "MSG_task_receive failed");
    
    XBT_DEBUG("Received \"%s\"", MSG_task_get_name(task));
    if (!strcmp(MSG_task_get_name(task), "finalize")) {
      MSG_task_destroy(task);
      break;
    }

    XBT_DEBUG("Processing \"%s\"", MSG_task_get_name(task));
    MSG_task_execute(task);
    XBT_DEBUG("\"%s\" done", MSG_task_get_name(task));
    MSG_task_destroy(task);
    task = NULL;
  }
  XBT_DEBUG("I'm done. See you!");
  return 0;
}                               /* end_of_worker */
示例#23
0
static int pinger(int argc, char *argv[])
{
  xbt_assert(argc==2, "The pinger function one argument from the XML deployment file");
  XBT_INFO("Ping -> %s", argv[1]);
  xbt_assert(MSG_host_by_name(argv[1]) != NULL, "Unknown host %s. Stopping Now! ", argv[1]);

  /* - Do the ping with a 1-Byte task (latency bound) ... */
  double now = MSG_get_clock();
  msg_task_t ping_task = MSG_task_create("small communication (latency bound)", 0.0, 1, NULL);
  ping_task->data = xbt_new(double, 1);
  *(double *) ping_task->data = now;
  MSG_task_send(ping_task, argv[1]);

  /* - ... then wait for the (large) pong */
  msg_task_t pong_task = NULL;
  int a = MSG_task_receive(&pong_task,MSG_host_get_name(MSG_host_self()));
  xbt_assert(a == MSG_OK, "Unexpected behavior");

  double sender_time = *((double *) (pong_task->data));
  double communication_time =  MSG_get_clock() - sender_time;
  XBT_INFO("Task received : %s", pong_task->name);
  xbt_free(pong_task->data);
  MSG_task_destroy(pong_task);
  XBT_INFO("Pong time (bandwidth bound): %e", communication_time);

  return 0;
}
示例#24
0
int slave(int argc, char *argv[])
{
	m_task_t task_s = NULL;
	m_task_t task_r = NULL;
	unsigned int task_comp_size = 50000000;
	unsigned int task_comm_size = 1000000;
	char mailbox[80];
	char buffer[20];
	int num = atoi(argv[1]);

	sprintf(mailbox, "host%d", num);
	MSG_task_receive(&(task_r), mailbox);
	XBT_INFO("Received \"%s\"", MSG_task_get_name(task_r));
	sprintf(mailbox, "host%d", num+1);
	if(num == totalHosts-1)
		sprintf(mailbox, "host%d", 0);
	sprintf(buffer, "Token");
	task_s = MSG_task_create(buffer,
							task_comp_size,
							task_comm_size,
							NULL);
	MSG_task_send(task_s, mailbox);
	XBT_INFO("Send Data to \"%s\"", mailbox);

	return 0;
}
示例#25
0
/** The guy we will move from host to host. It move alone and then is moved by policeman back  */
static int emigrant(int argc, char *argv[])
{
    msg_task_t task;
    XBT_INFO
    ("I'll look for a new job on another machine where the grass is greener.");
    MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin"));

    XBT_INFO("Yeah, found something to do");
    task = MSG_task_create("job", 98095000, 0, NULL);
    MSG_task_execute(task);
    MSG_task_destroy(task);
    MSG_process_sleep(2);
    XBT_INFO("Moving back home after work");
    MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Jacquelin"));
    MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin"));
    MSG_process_sleep(4);
    xbt_mutex_acquire(mutex);
    process_to_migrate = MSG_process_self();
    xbt_cond_broadcast(cond);
    xbt_mutex_release(mutex);
    MSG_process_suspend(MSG_process_self());
    msg_host_t h = MSG_process_get_host(MSG_process_self());
    XBT_INFO("I've been moved on this new host: %s", MSG_host_get_name(h));
    XBT_INFO("Uh, nothing to do here. Stopping now");
    return 0;
}                               /* end_of_emigrant */
示例#26
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;
  }
示例#27
0
static int worker_main(int argc, char *argv[])
{
  double computation_amount = xbt_str_parse_double(argv[1], "Invalid computation amount: %s");
  int use_bound = xbt_str_parse_int(argv[2], "Second parameter (use_bound) should be 0 or 1 but is: %s");
  double bound = xbt_str_parse_double(argv[3], "Invalid bound: %s");

  double clock_sta = MSG_get_clock();

  msg_task_t task = MSG_task_create("Task", computation_amount, 0, NULL);
  if (use_bound)
     MSG_task_set_bound(task, bound);
  MSG_task_execute(task);
  MSG_task_destroy(task);

  double clock_end = MSG_get_clock();
  double duration = clock_end - clock_sta;
  double flops_per_sec = computation_amount / duration;

  if (use_bound)
    XBT_INFO("bound to %f => duration %f (%f flops/s)", bound, duration, flops_per_sec);
  else
    XBT_INFO("not bound => duration %f (%f flops/s)", duration, flops_per_sec);

  return 0;
}
示例#28
0
static int client(int argc, char *argv[])
{
  int my_pid = MSG_process_get_PID(MSG_process_self());
  char *my_mailbox = xbt_strdup(argv[1]);

  while(1){
    XBT_INFO("Client (%s) asks the request", my_mailbox);
    MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");

    msg_task_t answer = NULL;
    MSG_task_receive(&answer, my_mailbox);

    const char* kind = MSG_task_get_name(answer);

    if (!strcmp(kind, "grant")) {
      XBT_INFO("Client (%s) got the answer (grant). Sleep a bit and release it", my_mailbox);
      if(!strcmp(my_mailbox, "1"))
        cs = 1;
    }else{
      XBT_INFO("Client (%s) got the answer (not grant). Try again", my_mailbox);
    }

    MSG_task_destroy(answer);
    kind = NULL;

    MSG_process_sleep(my_pid);
  }
  return 0;
}
示例#29
0
int host(int argc, char *argv[])
{
    int host_number = atoi(MSG_process_get_name(MSG_process_self()));
    char mailbox[256];
    msg_task_t task = NULL;
    XBT_ATTRIB_UNUSED int res;
    if (host_number == 0) { //master  send then receive
        sprintf(mailbox, "%d", host_number+1);
        task = MSG_task_create("Token", task_comp_size, task_comm_size, NULL);
        XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",host_number,task->name,mailbox);
        MSG_task_send(task, mailbox);
        task = NULL;
        res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self()));
        xbt_assert(res == MSG_OK, "MSG_task_get failed");
        XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task));
        MSG_task_destroy(task);
    }
    else { //slave receive then send
        res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self()));
        xbt_assert(res == MSG_OK, "MSG_task_get failed");
        XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task));

        if(host_number+1 == nb_hosts)
            sprintf(mailbox, "0");
        else
            sprintf(mailbox, "%d", host_number+1);
        XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",host_number,task->name,mailbox);
        MSG_task_send(task, mailbox);
    }
    return 0;
}
示例#30
0
文件: e3.c 项目: Julio-Anjos/simgrid
static int process_code(int argc, char *argv[])
{
  msg_task_t task1 = NULL;
  double cpu_task = 0;
  double task_time = MSG_get_clock();

  if (argc == 2)
  {
	  /* Run a sleep task */
	  double sleep_task = atof(argv[1]);

	  MSG_process_sleep(sleep_task);
	  task_time = MSG_get_clock() - task_time;
	  XBT_INFO("Process %s executed task sleep cpu=%f, duration = %f",
			  MSG_process_get_name(MSG_process_self()), 0.0, task_time);
	  XBT_INFO("==================================================");
 }


  // Run a task
  cpu_task = atof(argv[0]);
  task1 = MSG_task_create ("task", cpu_task, 0, NULL);
  MSG_task_execute (task1);
  MSG_task_destroy(task1);

  task_time = MSG_get_clock() - task_time;
  XBT_INFO("Process %s executed task cpu=%f, duration = %f",
		  MSG_process_get_name(MSG_process_self()), cpu_task, task_time);
  XBT_INFO("==================================================");
  return 0;
}