Esempio n. 1
0
int server(int argc, char *argv[])
{
  msg_task_t task1 = NULL;
  msg_task_t task2 = NULL;
  long val1, val2;

  MSG_task_receive(&task1, "mymailbox");
  val1 = (long) MSG_task_get_data(task1);
  MSG_task_destroy(task1);
  task1 = NULL;
  XBT_INFO("Received %lu", val1);

  MSG_task_receive(&task2, "mymailbox");
  val2 = (long) MSG_task_get_data(task2);
  MSG_task_destroy(task2);
  task2 = NULL;
  XBT_INFO("Received %lu", val2);

  MC_assert(min(val1, val2) == 1);

  MSG_task_receive(&task1, "mymailbox");
  val1 = (long) MSG_task_get_data(task1);
  MSG_task_destroy(task1);
  XBT_INFO("Received %lu", val1);

  MSG_task_receive(&task2, "mymailbox");
  val2 = (long) MSG_task_get_data(task2);
  MSG_task_destroy(task2);
  XBT_INFO("Received %lu", val2);

  XBT_INFO("OK");
  return 0;
}
Esempio n. 2
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;
}
Esempio n. 3
0
File: peer.c Progetto: R7R8/simgrid
int peer_execute_task(peer_t peer, msg_task_t task)
{
  int done = 0;
  message_t msg = MSG_task_get_data(task);
  
  XBT_DEBUG("Peer %s got message of type %d\n", peer->me, msg->type);
  switch (msg->type) {
    case MESSAGE_BUILD_CHAIN:
      peer_init_chain(peer, msg);
      break;
    case MESSAGE_SEND_DATA:
      xbt_assert(peer->init, "peer_execute_task() failed: got msg_type %d before initialization", msg->type);
      if (peer->next != NULL)
        peer_forward_msg(peer, msg);
      peer->pieces++;
      peer->bytes += msg->data_length;
      if (peer->pieces >= peer->total_pieces) {
        XBT_DEBUG("%d pieces receieved", peer->pieces);
        done = 1;
      }
      break;
  }

  MSG_task_execute(task);

  return done;
}
Esempio n. 4
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);
}
Esempio n. 5
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;
}
Esempio n. 6
0
/** Receiver function  */
int slave(int argc, char *argv[])
{
  m_task_t task = NULL;
  int res;

  while (1) {
    res = MSG_task_receive(&(task), "master_mailbox");
    if (res != MSG_OK) {
      XBT_INFO("error");
      break;
    }

    char *data = MSG_task_get_data(task);
    if (data && !strcmp(data, "finalize")) {
      MSG_task_destroy(task);
      break;
    }

    XBT_INFO("Executing task %f", MSG_task_get_compute_duration(task));
    MSG_task_execute(task);
    XBT_INFO("End of execution");
    MSG_task_destroy(task);
    task = NULL;
  }
  return 0;
}
Esempio n. 7
0
/** Receiver function  */
int slave(int argc, char *argv[])
{
  XBT_INFO("I'm a slave");
  while (1) {
    msg_task_t task = NULL;
    int a;
    a = MSG_task_receive(&(task), MSG_host_get_name(MSG_host_self()));
    if (a == MSG_OK) {
      XBT_INFO("Received \"%s\" ", MSG_task_get_name(task));
      if (MSG_task_get_data(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);
    } else {
      XBT_INFO("Hey ?! What's up ? ");
      xbt_die("Unexpected behavior");
            }
  }
  XBT_INFO("I'm done. See you!");
  return 0;
}                               /* end_of_slave */
Esempio n. 8
0
/* Frees the memory used by a task and destroy it */
static void task_free(void* task)
{
  if(task != NULL){
    s_task_data_t* data = (s_task_data_t*)MSG_task_get_data(task);
    xbt_free(data->state);
    xbt_free(data);
    MSG_task_destroy(task);
  }
}
Esempio n. 9
0
msg_task_t task_message_chain_new(const char *issuer_hostname, const char *mailbox, const char* prev, const char *next)
{
  msg_task_t task = task_message_new(MESSAGE_BUILD_CHAIN, MESSAGE_BUILD_CHAIN_SIZE, issuer_hostname, mailbox);
  message_t msg = MSG_task_get_data(task);
  msg->prev_hostname = prev;
  msg->next_hostname = next;

  return task;
}
Esempio n. 10
0
/**
 * @brief  Returns for how long a task is running.
 * @param  task  The task to be probed.
 * @return The amount of seconds since the beginning of the computation.
 */
static int task_time_elapsed (msg_task_t task)
{
    task_info_t  ti;

    ti = (task_info_t) MSG_task_get_data (task);

    return (MSG_task_get_compute_duration (task) - MSG_task_get_remaining_computation (task))
	/ MSG_get_host_speed (config.workers[ti->wid]);
}
Esempio n. 11
0
msg_task_t task_message_data_new(const char *issuer_hostname, const char *mailbox, const char *block, unsigned int len)
{
  msg_task_t task = task_message_new(MESSAGE_SEND_DATA, MESSAGE_SEND_DATA_HEADER_SIZE + len, issuer_hostname, mailbox);
  //if (strcmp(mailbox, "host4") == 0) 
  //MSG_task_set_category(task, mailbox);
  message_t msg = MSG_task_get_data(task);
  msg->data_block = block;
  msg->data_length = len;

  return task;
}
Esempio n. 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 {
Esempio n. 13
0
/** @brief Destroys a task and its data
  * @param task the task that'll be destroyed
  */
void task_free(msg_task_t task)
{
  xbt_assert((task != NULL), "Tried to free a NULL task");

  task_data_t data = MSG_task_get_data(task);

  if (data->answer) {
    answer_free(data->answer);
  }
  xbt_free(data);

  MSG_task_destroy(task);
}
Esempio n. 14
0
/**
 * @brief  Mark the tasks of a straggler as possible speculative tasks.
 * @param  worker  The straggler worker.
 */
static void set_speculative_tasks (msg_host_t worker)
{
    size_t       tid;
    size_t       wid;
    task_info_t  ti;

    wid = get_worker_id (worker);

    if (job.heartbeats[wid].slots_av[MAP] < config.slots[MAP])
    {
	for (tid = 0; tid < config.amount_of_tasks[MAP]; tid++)
	{
	    if (job.task_list[MAP][tid][0] != NULL)
	    {
		ti = (task_info_t) MSG_task_get_data (job.task_list[MAP][tid][0]);
		if (ti->wid == wid && task_time_elapsed (job.task_list[MAP][tid][0]) > 60)
		{
		    job.task_status[MAP][tid] = T_STATUS_TIP_SLOW;
		}
	    }
	}
    }

    if (job.heartbeats[wid].slots_av[REDUCE] < config.slots[REDUCE])
    {
	for (tid = 0; tid < config.amount_of_tasks[REDUCE]; tid++)
	{
	    if (job.task_list[REDUCE][tid][0] != NULL)
	    {
		ti = (task_info_t) MSG_task_get_data (job.task_list[REDUCE][tid][0]);
		if (ti->wid == wid && task_time_elapsed (job.task_list[REDUCE][tid][0]) > 60)
		{
		    job.task_status[REDUCE][tid] = T_STATUS_TIP_SLOW;
		}
	    }
	}
    }
}
Esempio n. 15
0
static int worker(int argc, char *argv[])
{
  msg_task_t task = NULL;
  char mailbox[80];

  long id= xbt_str_parse_int(argv[1], "Invalid argument %s");

  snprintf(mailbox, 79,"worker-%ld", id);

  while (1) {
    double time1 = MSG_get_clock();
    int retcode = MSG_task_receive( &(task), mailbox);
    double time2 = MSG_get_clock();
    if (retcode == MSG_OK) {
      XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
      if (MSG_task_get_data(task) == FINALIZE) {
        MSG_task_destroy(task);
        task = NULL;
        break;
      }
      if (time1 < *((double *) task->data))
        time1 = *((double *) task->data);
      XBT_INFO("Communication time : \"%f\"", time2 - time1);
      XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
      retcode = MSG_task_execute(task);
      if (retcode == MSG_OK) {
        XBT_INFO("\"%s\" done", MSG_task_get_name(task));
        MSG_task_destroy(task);
        task = NULL;
      } else if (retcode == MSG_HOST_FAILURE) {
        XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
        MSG_task_destroy(task);
        task = NULL;
        return 0;
      } else {
        XBT_INFO("Hey ?! What's up ? ");
        xbt_die("Unexpected behavior");
      }
    } else if (retcode == MSG_HOST_FAILURE) {
      XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
      return 0;
    } else if (retcode == MSG_TRANSFER_FAILURE) {
      XBT_INFO("Mmh. Something went wrong. Nevermind. Let's keep going!");
    } else {
      xbt_die("Unexpected behavior");
    }
  }
  XBT_INFO("I'm done. See you!");
  return 0;
}
int slave(int argc, char *argv[])
{
  while (1) {
    msg_task_t task = NULL;
    int a;
    double time1, time2;

    time1 = MSG_get_clock();
    a = MSG_task_receive( &(task), MSG_host_get_name(MSG_host_self()) );
    time2 = MSG_get_clock();
    if (a == MSG_OK) {
      XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
      if (MSG_task_get_data(task) == FINALIZE) {
        MSG_task_destroy(task);
        break;
      }
      if (time1 < *((double *) task->data))
        time1 = *((double *) task->data);
      XBT_INFO("Communication time : \"%f\"", time2 - time1);
      XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
      a = MSG_task_execute(task);
      if (a == MSG_OK) {
        XBT_INFO("\"%s\" done", MSG_task_get_name(task));
        free(task->data);
        MSG_task_destroy(task);
      } else if (a == MSG_HOST_FAILURE) {
        XBT_INFO
            ("Gloups. The cpu on which I'm running just turned off!. See you!");
        return 0;
      } else {
        XBT_INFO("Hey ?! What's up ? ");
        xbt_die("Unexpected behavior");
      }
    } else if (a == MSG_HOST_FAILURE) {
      XBT_INFO
          ("Gloups. The cpu on which I'm running just turned off!. See you!");
      return 0;
    } else if (a == MSG_TRANSFER_FAILURE) {
      XBT_INFO("Mmh. Something went wrong. Nevermind. Let's keep going!");
    } else if (a == MSG_TIMEOUT) {
      XBT_INFO("Mmh. Got a timeout. Nevermind. Let's keep going!");
    } else {
      XBT_INFO("Hey ?! What's up ? ");
      xbt_die("Unexpected behavior");
    }
  }
  XBT_INFO("I'm done. See you!");
  return 0;
}                               /* end_of_slave */
Esempio n. 17
0
static void get_sub_matrix(xbt_matrix_t *sM, int selfid)
{
    msg_task_t task = NULL;
    char node_mbox[MAILBOX_NAME_SIZE];
    msg_error_t err;

    XBT_VERB("Get sub-matrix");

    snprintf(node_mbox, MAILBOX_NAME_SIZE - 1, "%d", selfid);
    err = MSG_task_receive(&task, node_mbox);
    if (err != MSG_OK)
        xbt_die("Error while receiving from %s (%d)", node_mbox, (int)err);
    *sM = (xbt_matrix_t)MSG_task_get_data(task);
    MSG_task_destroy(task);
}
Esempio n. 18
0
static node_job_t wait_job(int selfid)
{
    msg_task_t task = NULL;
    char self_mbox[MAILBOX_NAME_SIZE];
    node_job_t job;
    msg_error_t err;
    snprintf(self_mbox, MAILBOX_NAME_SIZE - 1, "%d", selfid);
    err = MSG_task_receive(&task, self_mbox);
    if (err != MSG_OK)
        xbt_die("Error while receiving from %s (%d)", self_mbox, (int)err);
    job = (node_job_t)MSG_task_get_data(task);
    MSG_task_destroy(task);
    XBT_VERB("Got Job (%d,%d)", job->row, job->col);

    return job;
}
Esempio n. 19
0
static int coordinator(int argc, char *argv[])
{
  int CS_used = 0;   
  msg_task_t task = NULL, answer = NULL; 
  xbt_dynar_t requests = xbt_dynar_new(sizeof(char *), NULL);
  char *req;

  while(1){  
    MSG_task_receive(&task, "coordinator");
    const char *kind = MSG_task_get_name(task); 
    if (!strcmp(kind, "request")) {    
      req = MSG_task_get_data(task);
      if (CS_used) {           
        XBT_INFO("CS already used. Queue the request.");
        xbt_dynar_push(requests, &req);
      } else {               
        if(strcmp(req, "1") != 0){
          XBT_INFO("CS idle. Grant immediatly");
          answer = MSG_task_create("grant", 0, 1000, NULL);
          MSG_task_send(answer, req);
          CS_used = 1;
          answer = NULL;
        }
      }
    } else {
      if (!xbt_dynar_is_empty(requests)) {
        XBT_INFO("CS release. Grant to queued requests (queue size: %lu)", xbt_dynar_length(requests));
        xbt_dynar_shift(requests, &req);
        if(strcmp(req, "1") != 0){
          MSG_task_send(MSG_task_create("grant", 0, 1000, NULL), req);
        }else{
          xbt_dynar_push(requests, &req);
          CS_used = 0;
        }
      }else{
        XBT_INFO("CS release. resource now idle");
        CS_used = 0;
      }
    }
    MSG_task_destroy(task);
    task = NULL;
    kind = NULL;
    req = NULL;
  }
  return 0;
}
Esempio n. 20
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 = NULL;
  char *destination = NULL;

  MSG_process_sleep(2);

  while (1){ // I am an eternal emigrant
    MSG_task_receive(&(task), "master_mailbox");
    destination = (char*)MSG_task_get_data (task);
    MSG_task_destroy (task);
    if (!destination) break; //there is no destination, die
    MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name(destination));
    MSG_process_sleep(2); // I am tired, have to sleep for 2 seconds
    free (destination);
    task = NULL;
  }
  return 0;
}
Esempio n. 21
0
int server(int argc, char *argv[])
{
  msg_task_t task1;
  long val1;
  msg_comm_t comm1, comm2;

  comm1 = MSG_task_irecv(&task1, "mymailbox1");
  comm2 = MSG_task_irecv(&task1, "mymailbox2");
  MSG_comm_wait(comm1, -1);
  MSG_comm_wait(comm2, -1);

  val1 = (long) MSG_task_get_data(task1);
  XBT_INFO("Received %lu", val1);

  MC_assert(val1 == 2);

  XBT_INFO("OK");
  return 0;
}
Esempio n. 22
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) {
Esempio n. 23
0
int coordinator(int argc, char *argv[])
{
  xbt_dynar_t requests = xbt_dynar_new(sizeof(char *), NULL);   // dynamic vector storing requests (which are char*)
  int CS_used = 0;              // initially the CS is idle
  int todo = AMOUNT_OF_CLIENTS * CS_PER_PROCESS;        // amount of releases we are expecting
  while (todo > 0) {
    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) {            // need to push the request in the vector
        XBT_INFO("CS already used. Queue the request");
        xbt_dynar_push(requests, &req);
      } else {                  // can serve it immediatly
        XBT_INFO("CS idle. Grant immediatly");
        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
      if (!xbt_dynar_is_empty(requests)) {
        XBT_INFO("CS release. Grant to queued requests (queue size: %lu)",
              xbt_dynar_length(requests));
        char *req;
        xbt_dynar_pop(requests, &req);
        MSG_task_send(MSG_task_create("grant", 0, 1000, NULL), req);
        todo--;
      } else {                  // nobody wants it
        XBT_INFO("CS release. resource now idle");
        CS_used = 0;
        todo--;
      }
    }
    MSG_task_destroy(task);
  }
  XBT_INFO("Received all releases, quit now");
  return 0;
}
Esempio n. 24
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]);
    }
}
Esempio n. 25
0
void jcomm_bind_task(JNIEnv *env, jobject jcomm) {
  msg_comm_t comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
  //test if we are receiving or sending a task.
  jboolean jreceiving = env->GetBooleanField(jcomm, jcomm_field_Comm_receiving);
  if (jreceiving == JNI_TRUE) {
    //bind the task object.
    msg_task_t task = MSG_comm_get_task(comm);
    xbt_assert(task != nullptr, "Task is nullptr");
    jobject jtask_global = static_cast<jobject>(MSG_task_get_data(task));
    //case where the data has already been retrieved
    if (jtask_global == nullptr) {
      return;
    }

    //Make sure the data will be correctly gc.
    jobject jtask_local = env->NewLocalRef(jtask_global);
    env->DeleteGlobalRef(jtask_global);

    env->SetObjectField(jcomm, jtask_field_Comm_task, jtask_local);

    MSG_task_set_data(task, nullptr);
  }
}
Esempio n. 26
0
/** Receiver function  */
int slave(int argc, char *argv[])
{
  while (1) {
    msg_task_t task = NULL;
    int a;
    double time1, time2;

    time1 = MSG_get_clock();
    a = MSG_task_receive( &(task), MSG_host_get_name(MSG_host_self()) );
    time2 = MSG_get_clock();
    if (a == MSG_OK) {
      XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
      if (MSG_task_get_data(task) == FINALIZE) {
        MSG_task_destroy(task);
        break;
      }
      if (time1 < *((double *) task->data))
        time1 = *((double *) task->data);
      XBT_INFO("Communication time : \"%f\"", time2 - time1);
      XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
      a = MSG_task_execute(task);
      if (a == MSG_OK) {
        XBT_INFO("\"%s\" done", MSG_task_get_name(task));
        free(task->data);
        MSG_task_destroy(task);
      } else {
        XBT_INFO("Hey ?! What's up ? ");
        xbt_die("Unexpected behavior");
      }
    } else {
      XBT_INFO("Hey ?! What's up ? error %d", a);
      xbt_die("Unexpected behavior");
    }
  }
  XBT_INFO("I'm done. See you!");
  return 0;
}
Esempio n. 27
0
/** @brief  Main master function. */
int master (int argc, char* argv[])
{
    heartbeat_t  heartbeat;
    msg_error_t  status;
    msg_host_t   worker;
    msg_task_t   msg = NULL;
    size_t       wid;
    task_info_t  ti;
    double total_cpu_time = 0.0;
    double total_task_time = 0.0;

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

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

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

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

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

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

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

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

    fclose (tasks_log);

    job.finished = 1;

    print_config ();
    print_stats ();

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

    return 0;
}
Esempio n. 28
0
void task_message_delete(void *task)
{
  message_t msg = MSG_task_get_data(task);
  xbt_free(msg);
  MSG_task_destroy(task);
}
Esempio n. 29
0
/*
 * Handle a given task
 */
static void handle_task(node_t node, msg_task_t task) {
  XBT_DEBUG("Handling task %p", task);
  char mailbox[MAILBOX_NAME_SIZE];
  int i, j, min, max, d;
  msg_task_t task_sent;
  task_data_t req_data;
  task_data_t task_data = (task_data_t) MSG_task_get_data(task);
  e_task_type_t type = task_data->type;
  // If the node is not ready keep the task for later
  if (node->ready != 0 && !(type==TASK_JOIN_LAST_REPLY || type==TASK_JOIN_REPLY)) {
    XBT_DEBUG("Task pending %i", type);
    xbt_fifo_push(node->pending_tasks, task);
    return;
  }
  switch (type) {
    /*
     * Try to join the ring
     */
    case TASK_JOIN: {
      int next = routing_next(node, task_data->answer_id);
      XBT_DEBUG("Join request from %08x forwarding to %08x", task_data->answer_id, next);      
      type = TASK_JOIN_LAST_REPLY;

      req_data = xbt_new0(s_task_data_t,1);
      req_data->answer_id = task_data->sender_id;
      req_data->steps = task_data->steps + 1;
      
      // if next different from current node forward the join
      if (next!=node->id) {
        get_mailbox(next, mailbox);
        task_data->sender_id = node->id;
  task_data->steps++;
        task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, task_data);
        MSG_task_send_with_timeout(task_sent, mailbox, timeout);
        type = TASK_JOIN_REPLY;
      } 
      
      // send back the current node state to the joining node
      req_data->type = type;
      req_data->sender_id = node->id;
      get_mailbox(node->id, req_data->answer_to);
      req_data->state = node_get_state(node);
      task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
      MSG_task_send_with_timeout(task_sent, task_data->answer_to, timeout);
      break;
    }
    /*
     * Join reply from all the node touched by the join
     */
    case TASK_JOIN_LAST_REPLY:
      // if last node touched reply, copy its namespace set
      // TODO: it's work only if the two nodes are side to side (is it really the case ?)
      j = (task_data->sender_id < node->id) ? -1 : 0;
      for (i=0; i<NAMESPACE_SIZE/2; i++) {
        node->namespace_set[i] = task_data->state->namespace_set[i-j];
        node->namespace_set[NAMESPACE_SIZE-1-i] = task_data->state->namespace_set[NAMESPACE_SIZE-1-i-j-1];
      }
      node->namespace_set[NAMESPACE_SIZE/2+j] = task_data->sender_id;
      node->ready += task_data->steps + 1;
    case TASK_JOIN_REPLY:
      XBT_DEBUG("Joining Reply");

      // if first node touched reply, copy its neighborood set
      if (task_data->sender_id == node->known_id) {
  node->neighborhood_set[0] = task_data->sender_id;
        for (i=1; i<NEIGHBORHOOD_SIZE; i++)
            node->neighborhood_set[i] = task_data->state->neighborhood_set[i-1]; 
      }
      
      // copy the corresponding routing table levels
      min = (node->id==task_data->answer_id) ? 0 : shl(node->id, task_data->answer_id);      
      max = shl(node->id, task_data->sender_id)+1;
      for (i=min;i<max;i++) {
        d = domain(node->id, i); 
        for (j=0; j<LEVEL_SIZE; j++)
    if (d!=j)
            node->routing_table[i][j] =  task_data->state->routing_table[i][j];
      }

      node->ready--;
      // if the node is ready, do all the pending tasks and send update to known nodes
      if (node->ready==0) {
        XBT_DEBUG("Node %i is ready!!!", node->id);

        while(xbt_fifo_size(node->pending_tasks))
    handle_task(node, xbt_fifo_pop(node->pending_tasks));

  for (i=0; i<NAMESPACE_SIZE; i++) {
          j = node->namespace_set[i];
          if (j!=-1) {
            XBT_DEBUG("Send update to %i", j);
            get_mailbox(j, mailbox);
      
      req_data = xbt_new0(s_task_data_t,1);
            req_data->answer_id = node->id;
            req_data->steps = 0;
            req_data->type = TASK_UPDATE;
            req_data->sender_id = node->id;
            get_mailbox(node->id, req_data->answer_to);
            req_data->state = node_get_state(node);
            task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
            MSG_task_send_with_timeout(task_sent, mailbox, timeout);
          }
        }
      }
      break;
      
    /*
     * Recieved an update of state
     */
    case TASK_UPDATE:
      XBT_DEBUG("Task update %i !!!", node->id);

      /* Update namespace ses */
      printf("Task update from %i !!!\n", task_data->sender_id);
      print_node_id(node);
      print_node_namespace_set(node);
      int curr_namespace_set[NAMESPACE_SIZE];
      int task_namespace_set[NAMESPACE_SIZE+1];
      
      // Copy the current namedspace
      // and the task state namespace with state->id in the middle
      i=0;
      for (; i<NAMESPACE_SIZE/2; i++){
        curr_namespace_set[i] = node->namespace_set[i];
  task_namespace_set[i] = task_data->state->namespace_set[i];
      }
      task_namespace_set[i] = task_data->state->id;
      for (; i<NAMESPACE_SIZE; i++){
        curr_namespace_set[i] = node->namespace_set[i];  
  task_namespace_set[i+1] = task_data->state->namespace_set[i];  
      }

      // get the index of values before and after node->id in task_namespace
      min = -1;
      max = -1;
      for (i=0; i<=NAMESPACE_SIZE; i++) {
  j = task_namespace_set[i];
        if (i<NAMESPACE_SIZE)
    printf("%08x %08x | ", j, curr_namespace_set[i]);
  if (j != -1 && j < node->id) min = i;
  if (j != -1 && max == -1 && j > node->id) max = i;
      }
      printf("\n");

      // add lower elements
      j = NAMESPACE_SIZE/2-1;
      for (i=NAMESPACE_SIZE/2-1; i>=0; i--) {
  printf("i:%i, j:%i, min:%i, currj:%08x, taskmin:%08x\n", i, j, min, curr_namespace_set[j], task_namespace_set[min]);
        if (min<0) {
    node->namespace_set[i] = curr_namespace_set[j];
    j--; 
  } else if (curr_namespace_set[j] == task_namespace_set[min]) {
    node->namespace_set[i] = curr_namespace_set[j];
    j--; min--;
  } else if (curr_namespace_set[j] > task_namespace_set[min]) {
          node->namespace_set[i] = curr_namespace_set[j];
    j--;
  } else {
          node->namespace_set[i] = task_namespace_set[min];
    min--;
  }
      }

      // add greater elements
      j = NAMESPACE_SIZE/2;
      for (i=NAMESPACE_SIZE/2; i<NAMESPACE_SIZE; i++) {
  printf("i:%i, j:%i, max:%i, currj:%08x, taskmax:%08x\n", i, j, max, curr_namespace_set[j], task_namespace_set[max]);        
        if (min<0 || max>=NAMESPACE_SIZE) {
    node->namespace_set[i] = curr_namespace_set[j];
    j++;
  } else if (curr_namespace_set[j] == -1) {
    node->namespace_set[i] = task_namespace_set[max];
    max++;
  } else if (curr_namespace_set[j] == task_namespace_set[max]) {
    node->namespace_set[i] = curr_namespace_set[j];
    j++; max++;
  } else if (curr_namespace_set[j] < task_namespace_set[max]) {
          node->namespace_set[i] = curr_namespace_set[j];
    j++;
  } else {
          node->namespace_set[i] = task_namespace_set[max];
    max++;
  }
      }
      print_node_namespace_set(node);

      /* Update routing table */
      for (i=shl(node->id, task_data->state->id); i<LEVELS_COUNT; i++) {
        for (j=0; j<LEVEL_SIZE; j++) {
          if (node->routing_table[i][j]==-1 && task_data->state->routing_table[i][j]==-1)
            node->routing_table[i][j] = task_data->state->routing_table[i][j];
        }
      }
  }         
}
Esempio n. 30
0
/** Handle a given task */
static void handle_task(node_t node, msg_task_t task) {
  XBT_DEBUG("Handling task %p", task);
  char mailbox[MAILBOX_NAME_SIZE];
  int i;
  int j;
  int min;
  int max;
  int next;
  msg_task_t task_sent;
  task_data_t req_data;
  task_data_t task_data = (task_data_t) MSG_task_get_data(task);
  e_task_type_t type = task_data->type;
  // If the node is not ready keep the task for later
  if (node->ready != 0 && !(type==TASK_JOIN_LAST_REPLY || type==TASK_JOIN_REPLY)) {
    XBT_DEBUG("Task pending %u", type);
    xbt_dynar_push(node->pending_tasks, &task);
    return;
  }
  switch (type) {
    /* Try to join the ring */
    case TASK_JOIN:
      next = routing_next(node, task_data->answer_id);
      XBT_DEBUG("Join request from %08x forwarding to %08x", (unsigned)task_data->answer_id, (unsigned)next);
      type = TASK_JOIN_LAST_REPLY;

      req_data = xbt_new0(s_task_data_t,1);
      req_data->answer_id = task_data->sender_id;
      req_data->steps = task_data->steps + 1;

      // if next different from current node forward the join
      if (next!=node->id) {
        get_mailbox(next, mailbox);
        task_data->sender_id = node->id;
        task_data->steps++;
        task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, task_data);
        if (MSG_task_send_with_timeout(task_sent, mailbox, timeout)== MSG_TIMEOUT) {
          XBT_DEBUG("Timeout expired when forwarding join to next %d", next);
          task_free(task_sent);
        }
        type = TASK_JOIN_REPLY;
      }

      // send back the current node state to the joining node
      req_data->type = type;
      req_data->sender_id = node->id;
      get_mailbox(node->id, req_data->answer_to);
      req_data->state = node_get_state(node);
      task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
      if (MSG_task_send_with_timeout(task_sent, task_data->answer_to, timeout)== MSG_TIMEOUT) {
        XBT_DEBUG("Timeout expired when sending back the current node state to the joining node to %d", node->id);
        task_free(task_sent);
      }
      break;
    /* Join reply from all the node touched by the join  */
    case TASK_JOIN_LAST_REPLY:
      // if last node touched reply, copy its namespace set
      // TODO: it works only if the two nodes are side to side (is it really the case ?)
      j = (task_data->sender_id < node->id) ? -1 : 0;
      for (i=0; i<NAMESPACE_SIZE/2; i++) {
        node->namespace_set[i] = task_data->state->namespace_set[i-j];
        node->namespace_set[NAMESPACE_SIZE-1-i] = task_data->state->namespace_set[NAMESPACE_SIZE-1-i-j-1];
      }
      node->namespace_set[NAMESPACE_SIZE/2+j] = task_data->sender_id;
      node->ready += task_data->steps + 1;
      /* no break */
    case TASK_JOIN_REPLY:
      XBT_DEBUG("Joining Reply");

      // if first node touched reply, copy its neighborhood set
      if (task_data->sender_id == node->known_id) {
        node->neighborhood_set[0] = task_data->sender_id;
        for (i=1; i<NEIGHBORHOOD_SIZE; i++)
          node->neighborhood_set[i] = task_data->state->neighborhood_set[i-1];
      }

      // copy the corresponding routing table levels
      min = (node->id==task_data->answer_id) ? 0 : shl(node->id, task_data->answer_id);
      max = shl(node->id, task_data->sender_id)+1;
      for (i=min;i<max;i++) {
        int d = domain(node->id, i);
        for (j=0; j<LEVEL_SIZE; j++)
          if (d!=j)
            node->routing_table[i][j] =  task_data->state->routing_table[i][j];
      }

      node->ready--;
      // if the node is ready, do all the pending tasks and send update to known nodes
      if (node->ready==0) {
        XBT_DEBUG("Node %i is ready!!!", node->id);
        while (!xbt_dynar_is_empty(node->pending_tasks)) {
          msg_task_t task;
          xbt_dynar_shift(node->pending_tasks, &task);
          handle_task(node, task);
        }

        for (i=0; i<NAMESPACE_SIZE; i++) {
          j = node->namespace_set[i];
          if (j!=-1) {
            XBT_DEBUG("Send update to %i", j);
            get_mailbox(j, mailbox);

            req_data = xbt_new0(s_task_data_t,1);
            req_data->answer_id = node->id;
            req_data->steps = 0;
            req_data->type = TASK_UPDATE;
            req_data->sender_id = node->id;
            get_mailbox(node->id, req_data->answer_to);
            req_data->state = node_get_state(node);
            task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
            if (MSG_task_send_with_timeout(task_sent, mailbox, timeout)== MSG_TIMEOUT) {
              XBT_DEBUG("Timeout expired when sending update to %d", j);
              task_free(task_sent);
            }
          }
        }
        }
      break;
    /* Received an update of state */
    case TASK_UPDATE:
      XBT_DEBUG("Task update %i !!!", node->id);

      /* Update namespace ses */
      XBT_INFO("Task update from %i !!!", task_data->sender_id);
      XBT_INFO("Node:");
      print_node_id(node);
      print_node_namespace_set(node);
      int curr_namespace_set[NAMESPACE_SIZE];
      int task_namespace_set[NAMESPACE_SIZE+1];

      // Copy the current namespace and the task state namespace with state->id in the middle
      i=0;
      for (; i<NAMESPACE_SIZE/2; i++){
        curr_namespace_set[i] = node->namespace_set[i];
        task_namespace_set[i] = task_data->state->namespace_set[i];
      }
      task_namespace_set[i] = task_data->state->id;
      for (; i<NAMESPACE_SIZE; i++){
        curr_namespace_set[i] = node->namespace_set[i];
        task_namespace_set[i+1] = task_data->state->namespace_set[i];
      }

      // get the index of values before and after node->id in task_namespace
      min = -1;
      max = -1;
      for (i=0; i<=NAMESPACE_SIZE; i++) {
        j = task_namespace_set[i];
        if (j != -1 && j < node->id)
          min = i;
        if (j != -1 && max == -1 && j > node->id)
          max = i;
      }

      // add lower elements
      j = NAMESPACE_SIZE/2-1;
      for (i=NAMESPACE_SIZE/2-1; i>=0; i--) {
        if (min < 0 || curr_namespace_set[j] > task_namespace_set[min]) {
          node->namespace_set[i] = curr_namespace_set[j];
          j--;
        } else if (curr_namespace_set[j] == task_namespace_set[min]) {
          node->namespace_set[i] = curr_namespace_set[j];
          j--;
          min--;
        } else {
          node->namespace_set[i] = task_namespace_set[min];
          min--;
        }
      }

      // add greater elements
      j = NAMESPACE_SIZE/2;
      for (i=NAMESPACE_SIZE/2; i<NAMESPACE_SIZE; i++) {
        if (min<0 || max>=NAMESPACE_SIZE) {
         node->namespace_set[i] = curr_namespace_set[j];
         j++;
        } else if (max >= 0){
          if (curr_namespace_set[j] == -1 || curr_namespace_set[j] > task_namespace_set[max]) {
            node->namespace_set[i] = task_namespace_set[max];
            max++;
          } else if (curr_namespace_set[j] == task_namespace_set[max]) {
            node->namespace_set[i] = curr_namespace_set[j];
            j++;
            max++;
          } else {
            node->namespace_set[i] = curr_namespace_set[j];
            j++;
          }
        }
      }

      /* Update routing table */
      for (i=shl(node->id, task_data->state->id); i<LEVELS_COUNT; i++) {
        for (j=0; j<LEVEL_SIZE; j++) {
          if (node->routing_table[i][j]==-1 && task_data->state->routing_table[i][j]==-1)
            node->routing_table[i][j] = task_data->state->routing_table[i][j];
        }
      }
      break;
    default:
      THROW_IMPOSSIBLE;
  }
  task_free(task);
}