Beispiel #1
0
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, jobject jcomm, jdouble timeout) {
  msg_comm_t comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
  if (!comm) {
    jxbt_throw_native(env,bprintf("comm is null"));
    return;
  }

  jboolean finished = env->GetBooleanField(jcomm, jcomm_field_Comm_finished);
  if (finished == JNI_TRUE) {
    return;
  }

  msg_error_t status;
  status = MSG_comm_wait(comm,(double)timeout);
  env->SetBooleanField(jcomm, jcomm_field_Comm_finished, JNI_TRUE);
  if (status == MSG_OK) {
    jcomm_bind_task(env,jcomm);
    return;
  }
  else {
    jmsg_throw_status(env,status);
  }

}
Beispiel #2
0
int server(int argc, char *argv[])
{
  msg_task_t task1,task2;

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

  long val1 = xbt_str_parse_int(MSG_task_get_name(task1), "Task name is not a numerical ID: %s");
  XBT_INFO("Received %lu", val1);

  MC_assert(val1 == 2);

  XBT_INFO("OK");
  return 0;
}
Beispiel #3
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 */
Beispiel #4
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;
}
Beispiel #5
0
task_data receive_task(char mailbox[]){
    m_task_t task = NULL;
    msg_comm_t res = NULL;
    res = MSG_task_irecv(&(task),mailbox);
    MSG_comm_wait(res,-1);
    task_data data = *(task_data *) task->data;
    XBT_INFO("received response task %s",MSG_task_get_name(task));
    //MSG_comm_destroy(res);
    //MSG_task_destroy(task);
    return data;
}
Beispiel #6
0
int client(int argc, char *argv[])
{
  msg_task_t task1 = MSG_task_create(argv[1], 0, 10000, NULL);

  char *mbox = bprintf("mymailbox%s", argv[1]);

  XBT_INFO("Send %s!", argv[1]);
  msg_comm_t comm = MSG_task_isend(task1, mbox);
  MSG_comm_wait(comm, -1);

  xbt_free(mbox);

  return 0;
}
Beispiel #7
0
/** Receiver function  */
int receiver(int argc, char *argv[])
{
  m_task_t task = NULL;
  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]);
  XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time,
        sleep_test_time);

  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");

    if (sleep_test_time == 0) {
      res = MSG_comm_wait(res_irecv, -1);
      xbt_assert(res == MSG_OK, "MSG_task_get failed");
    } else {
      while (MSG_comm_test(res_irecv) == 0) {
        MSG_process_sleep(sleep_test_time);
      };
      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);
      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 */
Beispiel #8
0
int client(int argc, char *argv[])
{
  msg_comm_t comm;
  char *mbox;
  msg_task_t task1 =
      MSG_task_create("task", 0, 10000, (void *) atol(argv[1]));

  mbox = bprintf("mymailbox%s", argv[1]);

  XBT_INFO("Send %d!", atoi(argv[1]));
  comm = MSG_task_isend(task1, mbox);
  MSG_comm_wait(comm, -1);

  xbt_free(mbox);

  return 0;
}
Beispiel #9
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 */
Beispiel #10
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;
}
Beispiel #11
0
void run_service_cordel(int list_methods_len,chor_method_data list_methods[],char mailbox[]){
    m_task_t received_task = NULL;
    MSG_error_t res = MSG_OK;
    msg_comm_t msg_recv = NULL;
    static int id_sender = 0;
    char sender_name[50];
    sprintf(sender_name,"%s_%d",mailbox,id_sender++);
    int waiting_count = 0;
    while(1){
	msg_recv = MSG_task_irecv(&(received_task),mailbox);
	res = MSG_comm_wait(msg_recv,-1);
	if(res == MSG_OK){
	    char task_name[100];
	    strcpy(task_name,MSG_task_get_name(received_task));
	    task_data *received_task_data = (task_data *) received_task->data;
	    XBT_INFO("received task %lf",received_task_data->id);
	   // double endtime = MSG_get_clock();
	   // write_log(received_task_data->starttime,endtime,"waiting time");
	   //received_task_data->starttime = endtime;
	   int index_method = find_method(list_methods_len,list_methods,task_name);
	    chor_method_data method_data = list_methods[index_method];
	    int i;
	    for(i = 0;i<method_data.instructions_len;i++){
		method_instruction instruction = method_data.instructions[i];
		if(instruction.type == INVOKE){
		    service_invoke(instruction.role,instruction.method_name,instruction.input_size,sender_name);
		    waiting_count++;
		}else if(instruction.type == INVOKE_A){
		    service_invoke_cordel(instruction.role,instruction.method_name,instruction.input_size,received_task_data);
		}else if(instruction.type == EXEC){
		    run_chor_task(task_name,method_data);
		    }
		else if(instruction.type == WAIT){
		    wait_task(sender_name,waiting_count);
		    waiting_count = 0;
		    }
		else if(instruction.type == RETURN){
		    return_task(task_name,received_task,method_data.output_size);
		}
	    }
	}
	received_task = NULL;
    }
}
Beispiel #12
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;
}
Beispiel #13
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) {
Beispiel #14
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);
}
Beispiel #15
0
int service(int argc, char *argv[]){
    //init list_methods
    method_data list_methods[50];
    int list_methods_len = 0; 
    
    //set mailbox
    char mailbox[50];
    strcpy(mailbox,argv[1]);

    //create the list of methods 
    int i;
    for(i = 2;i<argc;i = i+3){
	make_method(&list_methods[list_methods_len++],argv[i],argv[i+1],argv[i+2]);
    }
   
    m_task_t received_task = NULL;
    MSG_error_t res = MSG_OK;
    msg_comm_t msg_recv = NULL;
    //receive request
    while(1){
	msg_recv = MSG_task_irecv(&(received_task),mailbox);
	res = MSG_comm_wait(msg_recv,-1);
	if(res == MSG_OK){
	    char task_name[100];
	    strcpy(task_name,MSG_task_get_name(received_task));
	    task_data *received_task_data = (task_data *) received_task->data;
	    //received_task_data->starttime = MSG_get_clock();
	    //double endtime = MSG_get_clock();
	    //write_log(received_task_data->starttime,endtime,"waiting time");
	    //received_task_data->starttime = endtime;
	    XBT_INFO("received task %lf",received_task_data->id);
	    run_task(task_name,list_methods_len,list_methods,received_task);
	}
	MSG_task_destroy(received_task);
	received_task = NULL;
    }
}
Beispiel #16
0
Datei: peer2.c Projekt: tof25/DST
/** 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]);
  int id = atoi(argv[7]);
  int num_task = 0;

  XBT_INFO("Node %d: sleep_start_time : %f , sleep_test_time : %f",
          id,
          sleep_start_time,
          sleep_test_time);

  msg_comm_t comm = NULL;
  int i;
  msg_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-%d", id, num_task);

    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-%d",
            i % receivers_count,
            id,
            num_task++);

    MSG_process_sleep(sleep_test_time * 2);
    MSG_comm_destroy(comm);
    /*
    if (sleep_test_time == 0) {
        MSG_comm_wait(comm, -1);
    } else {
      while (MSG_comm_test(comm) == 0) {
        XBT_INFO("Node %d: sleep", id);
        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 */
Beispiel #17
0
Datei: peer2.c Projekt: tof25/DST
/** 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 */