Exemple #1
0
/** 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 */
Exemple #2
0
/** 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]);
  int diff_com = atol(argv[5]);
  double coef = 0;
  xbt_dynar_t d = xbt_dynar_new(sizeof(msg_comm_t), NULL);
  int i;
  msg_task_t task;
  char mailbox[256];
  char sprintf_buffer[256];
  msg_comm_t comm;

  for (i = 0; i < number_of_tasks; i++) {
    if (diff_com == 0)
      coef = 1;
    else
      coef = (i + 1);

    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 / coef, NULL);
    comm = MSG_task_isend(task, mailbox);
    xbt_dynar_push_as(d, msg_comm_t, comm);
    XBT_INFO("Send to receiver-%ld %s comm_size %f", i % receivers_count,
          sprintf_buffer, task_comm_size / coef);
  }
  /* Here we are waiting for the completion of all communications */

  while (!xbt_dynar_is_empty(d)) {
    xbt_dynar_remove_at(d, MSG_comm_waitany(d), &comm);
    MSG_comm_destroy(comm);
  }
  xbt_dynar_free(&d);

  /* Here we are waiting for the completion of all tasks */
  sprintf(mailbox, "finalize");

  msg_comm_t res_irecv;
  _XBT_GNUC_UNUSED msg_error_t res_wait;
  for (i = 0; i < receivers_count; i++) {
    task = NULL;
    res_irecv = MSG_task_irecv(&(task), mailbox);
    res_wait = MSG_comm_wait(res_irecv, -1);
    xbt_assert(res_wait == MSG_OK, "MSG_comm_wait failed");
    MSG_comm_destroy(res_irecv);
    MSG_task_destroy(task);
  }

  XBT_INFO("Goodbye now!");
  return 0;
}                               /* end_of_sender */
Exemple #3
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;
}
static int master(int argc, char *argv[])
{
  double task_comp_size = 5E7;
  double task_comm_size = 1E6;
  double timeout = 1;

  const char * mailbox = "jupi";

  msg_task_t task = MSG_task_create("normal", task_comp_size, task_comm_size, NULL);
  XBT_INFO("Sending task: \"%s\"", task->name);
  MSG_task_send_with_timeout(task, mailbox, timeout);

  task = MSG_task_create("cancel directly", task_comp_size, task_comm_size, NULL);
  XBT_INFO("Canceling task \"%s\" directly", task->name);
  MSG_task_cancel(task);
  MSG_task_destroy(task);

  task = MSG_task_create("destroy directly", task_comp_size, task_comm_size, NULL);
  XBT_INFO("Destroying task \"%s\" directly", task->name);
  MSG_task_destroy(task);

  task = MSG_task_create("cancel", task_comp_size, task_comm_size, NULL);
  msg_comm_t comm = MSG_task_isend(task, mailbox);
  XBT_INFO("Canceling task \"%s\" during comm", task->name);
  MSG_task_cancel(task);
  try {
    MSG_comm_wait(comm, -1);
  }
  catch (xbt_ex& ex) {;
    MSG_comm_destroy(comm);
  }
  MSG_task_destroy(task);

  task = MSG_task_create("finalize", task_comp_size, task_comm_size, NULL);
  comm = MSG_task_isend(task, mailbox);
  XBT_INFO("Destroying task \"%s\" during comm", task->name);
  MSG_task_destroy(task);
  try {
    MSG_comm_wait(comm, -1);
  }
  catch (xbt_ex& ex) {;
    MSG_comm_destroy(comm);
  }

  task = MSG_task_create("cancel", task_comp_size, task_comm_size, NULL);
  MSG_task_send_with_timeout(task, mailbox, timeout);

  task = MSG_task_create("finalize", task_comp_size, task_comm_size, NULL);
  MSG_task_send_with_timeout(task, mailbox, timeout);

  XBT_INFO("Goodbye now!");
  return 0;
}
Exemple #5
0
msg_error_t peer_wait_for_message(peer_t peer)
{
  msg_error_t status;
  msg_comm_t comm = NULL;
  msg_task_t task = NULL;
  int idx = -1;
  int done = 0;

  while (!done) {
    comm = MSG_task_irecv(&task, peer->me);
    queue_pending_connection(comm, peer->pending_recvs);

    if ((idx = MSG_comm_waitany(peer->pending_recvs)) != -1) {
      comm = xbt_dynar_get_as(peer->pending_recvs, idx, msg_comm_t);
      status = MSG_comm_get_status(comm);
      XBT_DEBUG("peer_wait_for_message: error code = %d", status);
      xbt_assert(status == MSG_OK, "peer_wait_for_message() failed");

      task = MSG_comm_get_task(comm);
      MSG_comm_destroy(comm);
      xbt_dynar_cursor_rm(peer->pending_recvs, (unsigned int*)&idx);
      done = peer_execute_task(peer, task);

      task_message_delete(task);
      task = NULL;
    }
    process_pending_connections(peer->pending_sends);
  }

  return status;
}
Exemple #6
0
/** Receiver function  */
int receiver(int argc, char *argv[])
{
  msg_task_t task = NULL;
  _XBT_GNUC_UNUSED msg_error_t res;
  int id = -1;
  char mailbox[80];
  msg_comm_t res_irecv;
  _XBT_GNUC_UNUSED int read;
  read = sscanf(argv[1], "%d", &id);
  xbt_assert(read, "Invalid argument %s\n", argv[1]);
  MSG_process_sleep(10);
  sprintf(mailbox, "receiver-%d", id);
  while (1) {
    res_irecv = MSG_task_irecv(&(task), mailbox);
    XBT_INFO("Wait to receive a task");
    res = MSG_comm_wait(res_irecv, -1);
    MSG_comm_destroy(res_irecv);
    xbt_assert(res == MSG_OK, "MSG_task_get failed");
    XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
    if (!strcmp(MSG_task_get_name(task), "finalize")) {
      MSG_task_destroy(task);
      break;
    }

    XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
    MSG_task_execute(task);
    XBT_INFO("\"%s\" done", MSG_task_get_name(task));
    MSG_task_destroy(task);
    task = NULL;
  }
  XBT_INFO("I'm done. See you!");
  return 0;
}                               /* end_of_receiver */
Exemple #7
0
/**
 * \brief Finalizes a comm userdata.
 * \param L a Lua state
 * \return number of values returned to Lua
 *
 * - Argument 1 (userdata): a comm
 */
static int l_comm_gc(lua_State* L)
{
                                  /* ctask */
  msg_comm_t comm = *((msg_comm_t*) luaL_checkudata(L, 1, COMM_MODULE_NAME));
  MSG_comm_destroy(comm);
  return 0;
}
Exemple #8
0
/** Receiver function  */
int receiver(int argc, char *argv[])
{
  int id = -1;
  int i;
  char mailbox[80];
  xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);
  int tasks = atof(argv[2]);
  msg_task_t *task = xbt_new(msg_task_t, tasks);

  _XBT_GNUC_UNUSED int read;
  read = sscanf(argv[1], "%d", &id);
  xbt_assert(read, "Invalid argument %s\n", argv[1]);
  sprintf(mailbox, "receiver-%d", id);
  MSG_process_sleep(10);
  msg_comm_t res_irecv;
  for (i = 0; i < tasks; i++) {
    XBT_INFO("Wait to receive task %d", i);
    task[i] = NULL;
    res_irecv = MSG_task_irecv(&task[i], mailbox);
    xbt_dynar_push_as(comms, msg_comm_t, res_irecv);
  }

  /* Here we are waiting for the receiving of all communications */
  msg_task_t task_com;
  while (!xbt_dynar_is_empty(comms)) {
    _XBT_GNUC_UNUSED msg_error_t err;
    xbt_dynar_remove_at(comms, MSG_comm_waitany(comms), &res_irecv);
    task_com = MSG_comm_get_task(res_irecv);
    MSG_comm_destroy(res_irecv);
    XBT_INFO("Processing \"%s\"", MSG_task_get_name(task_com));
    MSG_task_execute(task_com);
    XBT_INFO("\"%s\" done", MSG_task_get_name(task_com));
    err = MSG_task_destroy(task_com);
    xbt_assert(err == MSG_OK, "MSG_task_destroy failed");
  }
  xbt_dynar_free(&comms);
  xbt_free(task);

  /* Here we tell to sender that all tasks are done */
  sprintf(mailbox, "finalize");
  res_irecv = MSG_task_isend(MSG_task_create(NULL, 0, 0, NULL), mailbox);
  MSG_comm_wait(res_irecv, -1);
  MSG_comm_destroy(res_irecv);
  XBT_INFO("I'm done. See you!");
  return 0;
}                               /* end_of_receiver */
Exemple #9
0
static int sender(int argc, char *argv[])
{
  xbt_assert(argc==6, "This function expects 5 parameters from the XML deployment file");
  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 receivers_count = xbt_str_parse_int(argv[4], "Invalid amount of receivers: %s");
  int diff_com = xbt_str_parse_int(argv[5], "Invalid value for diff_comm: %s");

  xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);
  /* First pack the communications in the dynar */
  for (int i = 0; i < number_of_tasks; i++) {
    double coef = (diff_com == 0) ? 1 : (i + 1);

    char mailbox[80];
    char taskname[80];
    snprintf(mailbox,79, "receiver-%ld", (i % receivers_count));
    snprintf(taskname,79, "Task_%d", i);
    msg_task_t task = MSG_task_create(taskname, task_comp_size, task_comm_size / coef, NULL);
    msg_comm_t comm = MSG_task_isend(task, mailbox);
    xbt_dynar_push_as(comms, msg_comm_t, comm);
    XBT_INFO("Send to receiver-%ld %s comm_size %f", i % receivers_count, taskname, task_comm_size / coef);
  }
   
  /* Here we are waiting for the completion of all communications */
  while (xbt_dynar_is_empty(comms) == 0) {
    msg_comm_t comm;
    xbt_dynar_remove_at(comms, MSG_comm_waitany(comms), &comm);
    MSG_comm_destroy(comm);
  }
  xbt_dynar_free(&comms);

  /* Here we are waiting for the completion of all tasks */
  for (int i = 0; i < receivers_count; i++) {
    msg_task_t task = NULL;
    msg_comm_t comm = MSG_task_irecv(&task, "finalize");
    msg_error_t res_wait = MSG_comm_wait(comm, -1);
    xbt_assert(res_wait == MSG_OK, "MSG_comm_wait failed");
    MSG_comm_destroy(comm);
    MSG_task_destroy(task);
  }

  XBT_INFO("Goodbye now!");
  return 0;
}
Exemple #10
0
JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_nativeFinalize(JNIEnv *env, jobject jcomm) {
  msg_comm_t comm;
  msg_task_t *task_received;

  task_received = (msg_task_t*)  (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_taskBind);
  delete task_received;

  comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
  MSG_comm_destroy(comm);
}
Exemple #11
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);
}
Exemple #12
0
/**
 * Tracker main function
 * @param argc number of arguments
 * @param argv arguments
 */
int tracker(int argc, char *argv[])
{
    int i;

    RngStream stream = (RngStream) MSG_host_get_property_value(MSG_host_self(), "stream");
    //Checking arguments
    xbt_assert(argc == 2, "Wrong number of arguments for the tracker.");
    //Retrieving end time
    double deadline = atof(argv[1]);
    xbt_assert(deadline > 0, "Wrong deadline supplied");
    //Building peers array
    xbt_dynar_t peers_list = xbt_dynar_new(sizeof(int), NULL);

    XBT_INFO("Tracker launched.");

    msg_comm_t comm_received = NULL;
    msg_task_t task_received = NULL;

    while (MSG_get_clock() < deadline) {
        if (comm_received == NULL) {
            comm_received = MSG_task_irecv(&task_received, TRACKER_MAILBOX);
        }
        if (MSG_comm_test(comm_received)) {
            //Check for correct status
            if (MSG_comm_get_status(comm_received) == MSG_OK) {
                //Retrieve the data sent by the peer.
                tracker_task_data_t data = MSG_task_get_data(task_received);
                //Add the peer to our peer list.
                if (!is_in_list(peers_list, data->peer_id)) {
                    xbt_dynar_push_as(peers_list, int, data->peer_id);
                }
                //Sending peers to the peer
                int next_peer;
                int peers_length = xbt_dynar_length(peers_list);
                for (i = 0; i < MAXIMUM_PAIRS && i < peers_length; i++) {
                    do {
                        next_peer =
                            xbt_dynar_get_as(peers_list,
                                             RngStream_RandInt(stream, 0, peers_length - 1),
                                             int);
                    } while (is_in_list(data->peers, next_peer));
                    xbt_dynar_push_as(data->peers, int, next_peer);
                }
                //setting the interval
                data->interval = TRACKER_QUERY_INTERVAL;
                //sending the task back to the peer.
                MSG_task_dsend(task_received, data->mailbox, task_free);
                //destroy the communication.
            }
            MSG_comm_destroy(comm_received);
            comm_received = NULL;
            task_received = NULL;
        } else {
Exemple #13
0
static void asynchronous_cleanup(void)
{
  process_globals_t globals =
      (process_globals_t) MSG_process_get_data(MSG_process_self());

  /* Destroy any isend which correspond to completed communications */
  int found;
  msg_comm_t comm;
  while ((found = MSG_comm_testany(globals->isends)) != -1) {
    xbt_dynar_remove_at(globals->isends, found, &comm);
    MSG_comm_destroy(comm);
  }
}
Exemple #14
0
static void action_bcast(const char *const *action)
{
  int i;
  char *bcast_identifier;
  char mailbox[80];
  double comm_size = parse_double(action[2]);
  msg_task_t 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());

  bcast_identifier = bprintf("bcast_%d", counters->bcast_counter++);

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

    msg_comm_t *comms = xbt_new0(msg_comm_t, communicator_size - 1);

    for (i = 1; i < communicator_size; i++) {
      sprintf(mailbox, "%s_p0_p%d", bcast_identifier, i);
      comms[i - 1] =
          MSG_task_isend(MSG_task_create(mailbox, 0, comm_size, NULL), mailbox);
    }
    MSG_comm_waitall(comms, communicator_size - 1, -1);
    for (i = 1; i < communicator_size; i++)
      MSG_comm_destroy(comms[i - 1]);
    xbt_free(comms);

    XBT_DEBUG("%s: all messages sent by %s have been received",
              bcast_identifier, process_name);

  } else {
    sprintf(mailbox, "%s_p0_%s", bcast_identifier, process_name);
    MSG_task_receive(&task, mailbox);
    MSG_task_destroy(task);
    XBT_DEBUG("%s: %s has received", bcast_identifier, process_name);
  }

  log_action(action, MSG_get_clock() - clock);
  xbt_free(bcast_identifier);
}
Exemple #15
0
int process_pending_connections(xbt_dynar_t q)
{
  unsigned int iter;
  int status;
  int empty = 0;
  msg_comm_t comm;

  xbt_dynar_foreach(q, iter, comm) {
    empty = 1;
    if (MSG_comm_test(comm)) {
      MSG_comm_destroy(comm);
      status = MSG_comm_get_status(comm);
      xbt_assert(status == MSG_OK, "process_pending_connections() failed");
      xbt_dynar_cursor_rm(q, &iter);
      empty = 0;
    }
  }
Exemple #16
0
/*
 * Broadcast the jobs to the nodes of the grid (except to node 0)
 */
static void broadcast_jobs(node_job_t *jobs)
{
    int node;
    char node_mbox[MAILBOX_NAME_SIZE];
    msg_task_t task;
    msg_comm_t comms[GRID_NUM_NODES - 1] = {0};

    XBT_VERB("Broadcast Jobs");
    for (node = 1; node < GRID_NUM_NODES; node++) {
        task = MSG_task_create("Job", 100, 100, jobs[node-1]);
        snprintf(node_mbox, MAILBOX_NAME_SIZE - 1, "%d", node);
        comms[node-1] = MSG_task_isend(task, node_mbox);
    }

    MSG_comm_waitall(comms, GRID_NUM_NODES-1, -1);
    for (node = 1; node < GRID_NUM_NODES; node++)
        MSG_comm_destroy(comms[node - 1]);
}
Exemple #17
0
/* Receiver process expects 3 arguments: */
static int receiver(int argc, char *argv[])
{
  msg_task_t task = NULL;
  XBT_ATTRIB_UNUSED msg_error_t res;
  char mailbox[80];
  msg_comm_t res_irecv;
  int id = xbt_str_parse_int(argv[1], "Invalid id: %s");                                        /* - unique id */
  double sleep_start_time = xbt_str_parse_double(argv[2], "Invalid sleep start parameter: %s"); /* - start time */
  double sleep_test_time = xbt_str_parse_double(argv[3], "Invalid sleep test parameter: %s");   /* - test time */
  XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);

  MSG_process_sleep(sleep_start_time); /* This process first sleeps for "start time" seconds.  */

  snprintf(mailbox,79, "receiver-%d", id);
  while (1) {
    res_irecv = MSG_task_irecv(&(task), mailbox); /* Then it posts asynchronous receives (@ref MSG_task_irecv) and*/
    XBT_INFO("Wait to receive a task");

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

    XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
    if (strcmp(MSG_task_get_name(task), "finalize") == 0) { /* If the received task is "finalize", the process ends */
      MSG_task_destroy(task);
      break;
    }

    XBT_INFO("Processing \"%s\"", MSG_task_get_name(task)); /* Otherwise, the task is processed */
    MSG_task_execute(task);
    XBT_INFO("\"%s\" done", MSG_task_get_name(task));
    MSG_task_destroy(task);
    task = NULL;
  }
  XBT_INFO("I'm done. See you!");
  return 0;
}
Exemple #18
0
void peer_shutdown(peer_t p)
{
  unsigned int size = xbt_dynar_length(p->pending_sends);
  unsigned int idx;
  msg_comm_t *comms = xbt_new(msg_comm_t, size);

  for (idx = 0; idx < size; idx++) {
    comms[idx] = xbt_dynar_get_as(p->pending_sends, idx, msg_comm_t);
  }

  XBT_DEBUG("Waiting for sends to finish before shutdown...");
  MSG_comm_waitall(comms, size, PEER_SHUTDOWN_DEADLINE);

  for (idx = 0; idx < size; idx++) {
    MSG_comm_destroy(comms[idx]);
  }

  xbt_free(comms);
}
Exemple #19
0
void worker(){
  worker_t p_me = MSG_host_get_data(MSG_host_self());

  while(1){
    m_task_t p_task = MSG_TASK_UNINITIALIZED;
    
    
    msg_comm_t comm =	MSG_task_irecv (&p_task, p_me->channel);
    MSG_comm_wait(comm, -1);
    MSG_comm_destroy(comm);
    
    task_t p_todo_task = MSG_task_get_data(p_task);
    if(p_todo_task!=FINALIZE){
    
      
      MSG_task_destroy(p_task);
      double delay = 1.0 + p_me->lf_delay*(double)rand()/(double)(RAND_MAX);
      if(delay<0){
        delay=0;
      }
      
      if (p_me->ps_ms_args->uc_coarse) {
        p_task = MSG_task_create(p_todo_task->name, delay*p_todo_task->f_unit_cost*MSG_get_host_speed(MSG_host_self()), 0, NULL);
      }
      else{
        //p_task = MSG_task_create(p_todo_task->name, delay*p_todo_task->f_unit_cost*pow(p_todo_task->ui_tile_size,3)/3.0, 0, NULL);
        p_task = MSG_task_create(p_todo_task->name, delay*p_todo_task->f_unit_cost*MSG_get_host_speed(MSG_host_self()), 0, NULL);
      }
      MSG_task_execute(p_task);

      xbt_fifo_shift(p_me->a_workqueue);
      p_me->p_last_task = p_todo_task;
      
    p_todo_task->uc_done = 1; 
    
      
    if(p_todo_task->e_type == Z || p_todo_task->e_type == ZS ){
        /*put the topmost line again in the triangles*/
        xbt_dynar_push_as(p_me->ps_ms_args->a_NT[p_todo_task->task.Z.ui_j],unsigned int,p_todo_task->task.Z.ui_ii);
    }
    else if (p_todo_task->e_type == F) {
Exemple #20
0
static void action_wait(const char *const *action)
{
  msg_task_t task = NULL;
  msg_comm_t comm;
  double clock = MSG_get_clock();
  process_globals_t globals =
      (process_globals_t) MSG_process_get_data(MSG_process_self());

  xbt_assert(xbt_dynar_length(globals->irecvs),
             "action wait not preceded by any irecv: %s",
             xbt_str_join_array(action, " "));

  ACT_DEBUG("Entering %s", NAME);
  comm = xbt_dynar_pop_as(globals->irecvs, msg_comm_t);
  MSG_comm_wait(comm, -1);
  task = xbt_dynar_pop_as(globals->tasks, msg_task_t);
  MSG_comm_destroy(comm);
  MSG_task_destroy(task);

  log_action(action, MSG_get_clock() - clock);
}
Exemple #21
0
static int receiver(int argc, char *argv[])
{
  xbt_assert(argc==3, "This function expects 2 parameters from the XML deployment file");
  int id = xbt_str_parse_int(argv[1], "ID should be numerical, not %s");
  int task_amount = xbt_str_parse_int(argv[2], "Invalid amount of tasks: %s");
  msg_task_t *tasks = xbt_new(msg_task_t, task_amount);
  xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);

  char mailbox[80];
  snprintf(mailbox,79, "receiver-%d", id);
   
  MSG_process_sleep(10);
  for (int i = 0; i < task_amount; i++) {
    XBT_INFO("Wait to receive task %d", i);
    tasks[i] = NULL;
    msg_comm_t comm = MSG_task_irecv(&tasks[i], mailbox);
    xbt_dynar_push_as(comms, msg_comm_t, comm);
  }

  /* Here we are waiting for the receiving of all communications */
  while (!xbt_dynar_is_empty(comms)) {
    msg_comm_t comm;
    // MSG_comm_waitany returns the rank of the comm that just ended. Remove it.
    xbt_dynar_remove_at(comms, MSG_comm_waitany(comms), &comm);
    msg_task_t task = MSG_comm_get_task(comm);
    MSG_comm_destroy(comm);
    XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
    MSG_task_execute(task);
    XBT_INFO("\"%s\" done", MSG_task_get_name(task));
    msg_error_t err = MSG_task_destroy(task);
    xbt_assert(err == MSG_OK, "MSG_task_destroy failed");
  }
  xbt_dynar_free(&comms);
  xbt_free(tasks);

  /* Here we tell to sender that all tasks are done */
  MSG_task_send(MSG_task_create(NULL, 0, 0, NULL), "finalize");
  XBT_INFO("I'm done. See you!");
  return 0;
}
Exemple #22
0
static void receive_results(result_t *results) {
    int node;
    msg_comm_t comms[GRID_NUM_NODES-1] = {0};
    msg_task_t tasks[GRID_NUM_NODES-1] = {0};

    XBT_VERB("Receive Results.");

    /* Get the result from the nodes in the GRID */
    for (node = 1; node < GRID_NUM_NODES; node++) {
        comms[node-1] = MSG_task_irecv(&tasks[node-1], "0");
    }

    MSG_comm_waitall(comms, GRID_NUM_NODES - 1, -1);
    for (node = 1; node < GRID_NUM_NODES; node++)
        MSG_comm_destroy(comms[node - 1]);

    /* Reconstruct the result matrix */
    for (node = 1; node < GRID_NUM_NODES; node++) {
        results[node] = (result_t)MSG_task_get_data(tasks[node-1]);
        MSG_task_destroy(tasks[node-1]);
    }
}
Exemple #23
0
/** 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]);

  msg_comm_t *comm = xbt_new(msg_comm_t, number_of_tasks + receivers_count);
  int i;
  msg_task_t task = NULL;
  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[i] = MSG_task_isend(task, mailbox);
    XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i);
  }
  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[i + number_of_tasks] = MSG_task_isend(task, mailbox);
    XBT_INFO("Send to receiver-%ld finalize", i % receivers_count);

  }
  /* Here we are waiting for the completion of all communications */
  MSG_comm_waitall(comm, (number_of_tasks + receivers_count), -1);
  for (i = 0; i < number_of_tasks + receivers_count; i++)
    MSG_comm_destroy(comm[i]);

  XBT_INFO("Goodbye now!");
  xbt_free(comm);
  return 0;
}                               /* end_of_sender */
Exemple #24
0
/** Receiver function  */
int receiver(int argc, char *argv[])
{
  msg_task_t task = NULL;
  _XBT_GNUC_UNUSED msg_error_t res;
  int id = -1;
  char mailbox[80];
  msg_comm_t res_irecv;
  double sleep_start_time = atof(argv[2]);
  double sleep_test_time = atof(argv[3]);
  long senders_count = atol(argv[4]);
  XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time,
        sleep_test_time);
  int timeout = -1;
  int timeflag = 1;         // set to 1 for no timeout

  _XBT_GNUC_UNUSED int read;
  read = sscanf(argv[1], "%d", &id);
  xbt_assert(read,
              "Invalid argument %s\n", argv[1]);

  MSG_process_sleep(sleep_start_time);

  sprintf(mailbox, "receiver-%d", id);
  while (1) {
    res_irecv = MSG_task_irecv(&(task), mailbox);
    XBT_INFO("Wait to receive a task - sleep_test = %f", sleep_test_time);

    if (sleep_test_time == 0) {
        if (MSG_get_clock() >= 3.9 && timeflag == 0) {
            timeflag = 1;
            timeout = 0.05;
        }
        res = MSG_comm_wait(res_irecv, timeout);
        //xbt_assert(res == MSG_OK, "MSG_task_get failed");
        if (res != MSG_OK) {
            XBT_INFO("Timeout !!");
            timeout = -1;
            MSG_comm_destroy(res_irecv);
            continue;
        }
    } else {
      while (MSG_comm_test(res_irecv) == 0) {
        XBT_INFO("Attente ...");
        MSG_process_sleep(sleep_test_time);
      };
      XBT_INFO("comm destroy");
      MSG_comm_destroy(res_irecv);
    }

    XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
    if (!strcmp(MSG_task_get_name(task), "finalize")) {

        //MSG_task_destroy(task);
        //task = NULL;
        senders_count--;
        if (senders_count == 0) {
            break;
        }
    } else {

        XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
        MSG_task_execute(task);
        XBT_INFO("\"%s\" done", MSG_task_get_name(task));
        //MSG_task_destroy(task);
        //task = NULL;
    }
    MSG_task_destroy(task);
    task = NULL;
  }
  XBT_INFO("I'm done. See you!");
  return 0;
}                               /* end_of_receiver */
Exemple #25
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;
}