Beispiel #1
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;
}
Beispiel #2
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;
}
Beispiel #3
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;
}
Beispiel #4
0
static int receiver(int argc, char *argv[])
{
  msg_task_t task = NULL;

  MSG_task_receive(&task, BOX_NAME);
  MC_assert(strcmp(MSG_task_get_name(task), "X") == 0);
  MSG_task_destroy(task);

  MSG_task_receive(&task, BOX_NAME);
  MC_assert(strcmp(MSG_task_get_name(task), "Y") == 0);
  MSG_task_destroy(task);

  return 0;
}
Beispiel #5
0
/** Receiver function  */
int receiver(int argc, char *argv[])
{
  double time, time1, sender_time;
  msg_task_t task_la = NULL;
  msg_task_t task_bw = NULL;
  int a;
  double communication_time = 0;

  XBT_INFO("receiver");

  time = MSG_get_clock();

  /* Get Latency */
  a = MSG_task_receive(&task_la,MSG_host_get_name(MSG_host_self()));
  if (a == MSG_OK) {
    time1 = MSG_get_clock();
    sender_time = *((double *) (task_la->data));
    time = sender_time;
    communication_time = time1 - time;
    XBT_INFO("Task received : %s", task_la->name);
    xbt_free(task_la->data);
    MSG_task_destroy(task_la);
    XBT_INFO("Communic. time %le", communication_time);
    XBT_INFO("--- la %f ----", communication_time);
  } else {
    xbt_die("Unexpected behavior");
  }


  /* Get Bandwidth */
  a = MSG_task_receive(&task_bw,MSG_host_get_name(MSG_host_self()));
  if (a == MSG_OK) {
    time1 = MSG_get_clock();
    sender_time = *((double *) (task_bw->data));
    time = sender_time;
    communication_time = time1 - time;
    XBT_INFO("Task received : %s", task_bw->name);
    xbt_free(task_bw->data);
    MSG_task_destroy(task_bw);
    XBT_INFO("Communic. time %le", communication_time);
    XBT_INFO("--- bw %f ----", task_comm_size_bw / communication_time);
  } else {
    xbt_die("Unexpected behavior");
  }


  return 0;
}                               /* end_of_receiver */
Beispiel #6
0
static int ponger(int argc, char *argv[])
{
  XBT_INFO("Pong -> %s", argv[1]);
  xbt_assert(MSG_host_by_name(argv[1]) != NULL, "Unknown host %s. Stopping Now! ", argv[1]);

  /* - Receive the (small) ping first ....*/
  msg_task_t ping_task = NULL;
  int a = MSG_task_receive(&ping_task, MSG_host_get_name(MSG_host_self()));
  xbt_assert(a == MSG_OK, "Unexpected behavior");

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

  /*  - ... Then send a 1GB pong back (bandwidth bound) */
  double time = MSG_get_clock();
  msg_task_t pong_task = MSG_task_create("large communication (bandwidth bound)", 0.0, 1e9, NULL);
  pong_task->data = xbt_new(double, 1);
  *(double *) pong_task->data = time;
  XBT_INFO("task_bw->data = %e", *((double *) pong_task->data));
  MSG_task_send(pong_task, argv[1]);

  return 0;
}
Beispiel #7
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;
}
/** 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 */
Beispiel #9
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;
}
/** Receiver function  */
int slave(int argc, char *argv[])
{
  m_task_t task = NULL;
  int res;
  int id = -1;
  char mailbox[80];

  xbt_assert1(sscanf(argv[1],"%d", &id),
	 "Invalid argument %s\n",argv[1]);

  sprintf(mailbox,"slave-%d",id);

  while(1) {
    res = MSG_task_receive(&(task), mailbox);
    xbt_assert0(res == MSG_OK, "MSG_task_get failed");

//  INFO1("Received \"%s\"", MSG_task_get_name(task));
    if (!strcmp(MSG_task_get_name(task),"finalize")) {
	MSG_task_destroy(task);
	break;
    }

//    INFO1("Processing \"%s\"", MSG_task_get_name(task));
    MSG_task_execute(task);
//    INFO1("\"%s\" done", MSG_task_get_name(task));
    MSG_task_destroy(task);
    task = NULL;
  }
  INFO0("I'm done. See you!");
  return 0;
} /* end_of_slave */
Beispiel #11
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;
}
Beispiel #12
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;
}
Beispiel #13
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;
}
Beispiel #14
0
/** Receiver function  */
int worker(int argc, char *argv[])
{
  msg_task_t task = NULL;
  _XBT_GNUC_UNUSED int res;
  char channel[1024];

  build_channel_name(channel,MSG_process_get_data(MSG_process_self()),
		     MSG_host_get_name(MSG_host_self()));

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

  while (1) {
    res = MSG_task_receive(&(task),channel);
    xbt_assert(res == MSG_OK, "MSG_task_get 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 */
Beispiel #15
0
static int slave(int argc, char *argv[])
{
  msg_task_t task = NULL;
  XBT_ATTRIB_UNUSED int res;
  int id = -1;
  char mailbox[80];

  sprintf(mailbox, "jupi");

  while (1) {
    res = MSG_task_receive(&(task), mailbox);
    xbt_assert(res == MSG_OK, "MSG_task_get failed");

    if (!strcmp(MSG_task_get_name(task), "finalize")) {
      MSG_task_destroy(task);
      break;
    }
    MSG_task_execute(task);
    XBT_INFO("Task \"%s\" done", MSG_task_get_name(task));

    MSG_task_destroy(task);
    task = NULL;
    id--;
  }
  XBT_INFO("I'm done. See you!");
  return 0;
}
static int worker(int argc, char *argv[])
{
  while (1) {
    msg_task_t task = NULL;
    XBT_ATTRIB_UNUSED int res = MSG_task_receive(&(task), "worker_mailbox");
    xbt_assert(res == MSG_OK, "MSG_task_get failed");
    XBT_INFO("Handling task \"%s\"", MSG_task_get_name(task));

    if (!strcmp(MSG_task_get_name(task), "finalize")) {
      XBT_INFO("Destroying task \"%s\"", task->name);
      MSG_task_destroy(task);
      break;
    }

    if (!strcmp(MSG_task_get_name(task), "cancel")) {
      MSG_process_create("worker1", worker_main, task, MSG_host_self());
      MSG_process_sleep(0.1);
      XBT_INFO("Canceling task \"%s\"", task->name);
      MSG_task_cancel(task);
      continue;
    }

    double start = MSG_get_clock();
    MSG_task_execute(task);
    double end = MSG_get_clock();
    XBT_INFO("Task \"%s\" done in %f (amount %f)", MSG_task_get_name(task), end - start,
             MSG_task_get_flops_amount(task));

    MSG_task_destroy(task);
  }
  XBT_INFO("I'm done. See you!");
  return 0;
}
Beispiel #17
0
static int receiver(int argc, char *argv[])
{
  ensure_other_tid();

  msg_task_t task_la = NULL;
  xbt_assert(MSG_task_receive(&task_la,"some mailbox") == MSG_OK);
  XBT_INFO("Task received");
  MSG_task_destroy(task_la);

  return 0;
}
Beispiel #18
0
msg_error_t receive (msg_task_t* msg, const char* mailbox)
{
    msg_error_t  status;
 
    status = MSG_task_receive (msg, mailbox);

#ifdef VERBOSE
    if (status != MSG_OK)
	XBT_INFO ("ERROR %d MRSG_RECEIVING MESSAGE", status);
#endif

    return status;
}
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;
}
Beispiel #20
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;
}
Beispiel #21
0
/* Main function of all processes used in this example */
static int relay_runner(int argc, char* argv[])
{
  xbt_assert(argc == 0, "The relay_runner function does not accept any parameter from the XML deployment file");
  int rank = xbt_str_parse_int(MSG_process_get_name(MSG_process_self()),
                               "Any process of this example must have a numerical name, not %s");
  char mailbox[256];

  if (rank == 0) {
    /* The root process (rank 0) first sends the token then waits to receive it back */
    snprintf(mailbox, 255, "%d", rank + 1);
    unsigned int task_comm_size = 1000000; /* The token is 1MB long*/
    msg_task_t task             = MSG_task_create("Token", 0, task_comm_size, NULL);
    XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"", rank, task->name, mailbox);
    MSG_task_send(task, mailbox);
    task    = NULL;
    int 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\"", rank, MSG_task_get_name(task));
    MSG_task_destroy(task);

  } else {
    /* The others processes receive from their left neighbor (rank-1) and send to their right neighbor (rank+1) */
    msg_task_t task = NULL;
    int 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\"", rank, MSG_task_get_name(task));

    if (rank + 1 == MSG_get_host_number())
      /* But the last process, which sends the token back to rank 0 */
      snprintf(mailbox, 255, "0");
    else
      snprintf(mailbox, 255, "%d", rank + 1);
    XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"", rank, task->name, mailbox);
    MSG_task_send(task, mailbox);
  }
  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 */
Beispiel #23
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);
}
Beispiel #24
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);
}
Beispiel #25
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;
}
Beispiel #26
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;
}
Beispiel #27
0
int server(int argc, char *argv[])
{
  msg_task_t task = NULL;
  int count = 0;
  while (count < N) {
    if (task) {
      MSG_task_destroy(task);
      task = NULL;
    }
    MSG_task_receive(&task, "mymailbox");
    count++;
  }
  MC_assert(atoi(MSG_task_get_name(task)) == 3);

  XBT_INFO("OK");
  return 0;
}
Beispiel #28
0
static int server(int argc, char *argv[])
{
  msg_task_t task = NULL;
  int count = 0;
  while (count < N) {
    if (task) {
      MSG_task_destroy(task);
      task = NULL;
    }
    MSG_task_receive(&task, "mymailbox");
    count++;
  }
  MC_assert(xbt_str_parse_int(MSG_task_get_name(task), "Task names must be integers, not '%s'") == 3);

  XBT_INFO("OK");
  return 0;
}
Beispiel #29
0
static int worker(int argc, char *argv[])
{
  msg_task_t task = NULL;

  while (1) {
    MSG_task_receive(&(task), "master_mailbox");

    if (strcmp(MSG_task_get_name(task), "finalize") == 0) {
      MSG_task_destroy(task);
      break;
    }

    MSG_task_execute(task);
    MSG_task_destroy(task);
    task = NULL;
  }
  return 0;
}
Beispiel #30
0
static void action_recv(const char *const *action)
{
  char mailbox_name[250];
  msg_task_t task = NULL;
  double clock = MSG_get_clock();

  sprintf(mailbox_name, "%s_%s", action[2],
          MSG_process_get_name(MSG_process_self()));

  ACT_DEBUG("Receiving: %s", NAME);
  msg_error_t res = MSG_task_receive(&task, mailbox_name);
  log_action(action, MSG_get_clock() - clock);

  if (res == MSG_OK) {
    MSG_task_destroy(task);
  }
  asynchronous_cleanup();
}