Beispiel #1
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 #2
0
static int process_code(int argc, char *argv[])
{
  msg_task_t task1 = NULL;
  double cpu_task = 0;
  double task_time = MSG_get_clock();

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

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


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

  task_time = MSG_get_clock() - task_time;
  XBT_INFO("Process %s executed task cpu=%f, duration = %f",
		  MSG_process_get_name(MSG_process_self()), cpu_task, task_time);
  XBT_INFO("==================================================");
  return 0;
}
/*
 * Instrumentation functions to trace MSG processes (msg_process_t)
 */
void TRACE_msg_process_change_host(msg_process_t process, msg_host_t old_host, msg_host_t new_host)
{
  if (TRACE_msg_process_is_enabled()){
    static long long int counter = 0;

    char key[INSTR_DEFAULT_STR_SIZE];
    snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);

    int len = INSTR_DEFAULT_STR_SIZE;
    char str[INSTR_DEFAULT_STR_SIZE];

    //start link
    container_t msg = PJ_container_get (instr_process_id(process, str, len));
    type_t type = PJ_type_get ("MSG_PROCESS_LINK", PJ_type_get_root());
    new_pajeStartLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);

    //destroy existing container of this process
    TRACE_msg_process_destroy (MSG_process_get_name (process), MSG_process_get_PID (process));

    //create new container on the new_host location
    TRACE_msg_process_create (MSG_process_get_name (process), MSG_process_get_PID (process), new_host);

    //end link
    msg = PJ_container_get(instr_process_id(process, str, len));
    type = PJ_type_get ("MSG_PROCESS_LINK", PJ_type_get_root());
    new_pajeEndLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
  }
}
static void simopen(const char *const *action) {
  const char *processid = action[0];
  const char *worktime = action[3];
  double sleeptime;
  const char *index = action[4];
  char full_name[1024];
  msg_file_t file = NULL;
  double clock = MSG_get_clock();       /* this "call" is free thanks to inlining */
  //Because the action open is too fast ,to catch up with the clock of the simulator, we let it to sleep for a while.
  sleeptime = atof(worktime);
  MSG_process_sleep(sleeptime);
  //open slow filename
  const char *file_name = action[2];
  char fn[200];
   strcpy(fn,file_name);
  ReplaceStr(fn,"/home","/slow");
  sprintf(full_name, "%s:%s:%s:%s","slow",file_name,MSG_process_get_name(MSG_process_self()),index);
  ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name);
  file = MSG_file_open(fn, NULL);
  xbt_dict_set(opened_files, full_name, file, NULL);
  //open fast filename
   strcpy(fn,file_name);
  ReplaceStr(fn,"/home","/fast");
  sprintf(full_name, "%s:%s:%s:%s","fast",file_name,MSG_process_get_name(MSG_process_self()),index);
  ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name);
  file = MSG_file_open(fn, NULL);
  xbt_dict_set(opened_files, full_name, file, NULL);
 
  log_action(action, MSG_get_clock() - clock);
  XBT_INFO("open worker %s%s is done",processid,index);
}
static void simcreat(const char *const *action) {
  const char *processid = action[0];
  const char *worktime = action[3];
  double sleeptime;
  const char *index = action[4];
  char full_name[1024];
  msg_file_t file = NULL;
  double clock = MSG_get_clock();       /* this "call" is free thanks to inlining */
  sleeptime = atof(worktime);
  MSG_process_sleep(sleeptime);
  //open slow file
  const char *file_name = action[2];
  char fn[200];
   strcpy(fn,file_name);
  ReplaceStr(fn,"/home","/slow");
  sprintf(full_name, "%s:%s:%s:%s","slow",file_name,MSG_process_get_name(MSG_process_self()), index);
  ACT_DEBUG("Entering Creat: %s (filename: %s)", NAME, file_name);
  file = MSG_file_open(fn, NULL);
  xbt_dict_set(opened_files, full_name, file, NULL);
  //open fast version of file
  strcpy(fn,file_name);
  ReplaceStr(fn,"/home","/fast");
  sprintf(full_name, "%s:%s:%s:%s","fast",file_name,MSG_process_get_name(MSG_process_self()), index);
  ACT_DEBUG("Entering Creat: %s (filename: %s)", NAME, file_name);
  file = MSG_file_open(fn, NULL);
  xbt_dict_set(opened_files, full_name, file, NULL);
  
  log_action(action, MSG_get_clock() - clock);
  XBT_INFO("creat worker %s %s is done",processid,index);
}
int computation_fun(int argc, char *argv[])
{
  const char *pr_name = MSG_process_get_name(MSG_process_self());
  const char *host_name = MSG_host_get_name(MSG_host_self());
  double clock_sta, clock_end;
  atask = MSG_task_create("Task1", 1e9, 1e9, NULL);
  clock_sta = MSG_get_clock();
  XBT_INFO("%s:%s task 1 created %g", host_name, pr_name, clock_sta);
  MSG_task_execute(atask);
  clock_end = MSG_get_clock();

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

  MSG_task_destroy(atask);
  atask = NULL;

  MSG_process_sleep(1);

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

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

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

  MSG_task_destroy(atask);
  atask = NULL;

  return 0;
}
Beispiel #7
0
void TRACE_msg_process_kill(msg_process_t process)
{
  if (TRACE_msg_process_is_enabled()){
    //kill means that this process no longer exists, let's destroy it
    TRACE_msg_process_destroy (MSG_process_get_name (process), MSG_process_get_PID (process), MSG_process_get_host (process));
  }
}
Beispiel #8
0
msg_file_t get_file_descriptor(const char *file_name,const char *index){//get file with the file full_name
  char full_name[1024];
  msg_file_t file = NULL;
  sprintf(full_name, "%s:%s:%s", file_name,MSG_process_get_name(MSG_process_self()),index);
  file = (msg_file_t) xbt_dict_get_or_null(opened_files, full_name);
 return file;
}
Beispiel #9
0
static void action_Isend(const char *const *action)
{
  char to[250];
  const char *size = action[3];
  double clock = MSG_get_clock();
  process_globals_t globals =
      (process_globals_t) MSG_process_get_data(MSG_process_self());

  sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()), action[2]);
  msg_comm_t comm =
      MSG_task_isend(MSG_task_create(to, 0, parse_double(size), NULL), to);
  xbt_dynar_push(globals->isends, &comm);

  XBT_DEBUG("Isend on %s", MSG_process_get_name(MSG_process_self()));
  log_action(action, MSG_get_clock() - clock);
  asynchronous_cleanup();
}
Beispiel #10
0
static msg_file_t get_file_descriptor(const char *file_name){
  char full_name[1024];
  msg_file_t file = NULL;

  snprintf(full_name,1023, "%s:%s", MSG_process_get_name(MSG_process_self()), file_name);

  file = (msg_file_t) xbt_dict_get_or_null(opened_files, full_name);
  return file;
}
Beispiel #11
0
static int receiver_fun(int argc, char *argv[])
{
  XBT_INFO("Receiving");
  msg_task_t task = NULL;
  MSG_task_receive_with_timeout(&task, MSG_host_get_name(MSG_host_self()), DBL_MAX);
  xbt_assert(MSG_task_get_sender(task), "No sender received");
  XBT_INFO("Got a message sent by '%s'", MSG_process_get_name(MSG_task_get_sender(task)));
  MSG_task_destroy(task);
  return 0;
}
Beispiel #12
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);
}
Beispiel #13
0
static int master(int argc, char *argv[])
{
    xbt_swag_t process_list = MSG_host_get_process_list(MSG_host_self());
    msg_process_t process = NULL;
    MSG_process_sleep(1);
    xbt_swag_foreach(process, process_list) {
        XBT_INFO("Process(pid=%d, ppid=%d, name=%s)", MSG_process_get_PID(process), MSG_process_get_PPID(process),
                 MSG_process_get_name(process));
        if (MSG_process_self_PID() != MSG_process_get_PID(process))
            MSG_process_kill(process);
    }
Beispiel #14
0
static void action_Irecv(const char *const *action)
{
  char mailbox[250];
  double clock = MSG_get_clock();
  process_globals_t globals =
      (process_globals_t) MSG_process_get_data(MSG_process_self());

  XBT_DEBUG("Irecv on %s", MSG_process_get_name(MSG_process_self()));

  sprintf(mailbox, "%s_%s", action[2],
          MSG_process_get_name(MSG_process_self()));
  msg_task_t t = NULL;
  xbt_dynar_push(globals->tasks, &t);
  msg_comm_t c =
      MSG_task_irecv(xbt_dynar_get_ptr
                     (globals->tasks, xbt_dynar_length(globals->tasks) - 1),
                     mailbox);
  xbt_dynar_push(globals->irecvs, &c);

  log_action(action, MSG_get_clock() - clock);
  asynchronous_cleanup();
}
Beispiel #15
0
static void simopen(const char *const *action) {
  const char *processid = action[0];
  const char *file_name = action[2];
  const char *index = action[4];
  char full_name[1024];
  msg_file_t file = NULL;
  double clock = MSG_get_clock();       /* this "call" is free thanks to inlining */
  sprintf(full_name, "%s:%s:%s", file_name,MSG_process_get_name(MSG_process_self()),index);
  ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name);
  file = MSG_file_open(full_name, NULL);
  xbt_dict_set(opened_files, full_name, file, NULL);
  log_action(action, MSG_get_clock() - clock);
  XBT_INFO("open worker %s%s is done",processid,index);
}
Beispiel #16
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;
}
Beispiel #17
0
/** Receiver function  */
int slave(int argc, char *argv[])
{
  msg_task_t task = NULL;
  _XBT_GNUC_UNUSED int res;

  XBT_DEBUG("mailbox: %s",MSG_process_get_name(MSG_process_self()));
  while (1) {
    res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self()));
    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_slave */                              /* end_of_test_all */
Beispiel #18
0
static void action_open(const char *const *action) {
  const char *file_name = action[2];
  char full_name[1024];
  msg_file_t file = NULL;
  double clock = MSG_get_clock();

  snprintf(full_name,1023, "%s:%s", MSG_process_get_name(MSG_process_self()), file_name);

  ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name);
  file = MSG_file_open(file_name, NULL);

  xbt_dict_set(opened_files, full_name, file, NULL);

  log_action(action, MSG_get_clock() - clock);
}
Beispiel #19
0
    xbt_dynar_foreach (process_list, cursor, process)
    {
	process_name = MSG_process_get_name (process);
	host = MSG_process_get_host (process);
	if ( strcmp (process_name, "worker") == 0 )
	{
	    config.workers[wid] = host;
	    /* Set the worker ID as its data. */
	    wi = xbt_new (struct w_info_s, 1);
	    wi->wid = wid;
	    MSG_host_set_data (host, (void*)wi);
	    /* Add the worker's cpu power to the grid total. */
	    config.grid_cpu_power += MSG_get_host_speed (host);
	    wid++;
	}
Beispiel #20
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 #21
0
static int computation_fun(int argc, char *argv[])
{
  const char *pr_name = MSG_process_get_name(MSG_process_self());
  const char *host_name = MSG_host_get_name(MSG_host_self());

  msg_task_t task = MSG_task_create("Task", 1000000, 1000000, NULL);

  double clock_sta = MSG_get_clock();
  MSG_task_execute(task);
  double clock_end = MSG_get_clock();

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

  MSG_task_destroy(task);

  return 0;
}
Beispiel #22
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();
}
Beispiel #23
0
/* My actions */
static void action_send(const char *const *action)
{
  char to[250];
  const char *size_str = action[3];
  double size = parse_double(size_str);
  double clock = MSG_get_clock();       /* this "call" is free thanks to inlining */

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

  ACT_DEBUG("Entering Send: %s (size: %g)", NAME, size);
  if (size < 65536) {
    action_Isend(action);
  } else {
    MSG_task_send(MSG_task_create(to, 0, size, NULL), to);
  }

  log_action(action, MSG_get_clock() - clock);
  asynchronous_cleanup();
}
Beispiel #24
0
/**
 * @brief  Initialize the config structure.
 */
static void init_config (void)
{
    const char*    process_name = NULL;
    msg_host_t     host;
    msg_process_t  process;
    size_t         wid;
    unsigned int   cursor;
    w_info_t       wi;
    xbt_dynar_t    process_list;

    /* Initialize hosts information. */

    config.number_of_workers = 0;

    process_list = MSG_processes_as_dynar ();
    xbt_dynar_foreach (process_list, cursor, process)
    {
	process_name = MSG_process_get_name (process);
	if ( strcmp (process_name, "worker") == 0 )
	    config.number_of_workers++;
    }
Beispiel #25
0
int host(int argc, char *argv[])
{
  msg_file_t file = NULL;
  sg_size_t read,write;
  msg_storage_t st;
  const char* st_name;

  if(!strcmp(MSG_process_get_name(MSG_process_self()),"0")){
    file = MSG_file_open(FILENAME1, NULL);
    MSG_file_dump(file);
    st_name = "Disk4";
  } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"1")) {
    file = MSG_file_open(FILENAME2, NULL);
    st_name = "Disk2";
  } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"2")){
    file = MSG_file_open(FILENAME3, NULL);
    st_name = "Disk3";
  } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"3")){
    file = MSG_file_open(FILENAME4, NULL);
    st_name = "Disk1";
  }
  else xbt_die("FILENAME NOT DEFINED %s",MSG_process_get_name(MSG_process_self()));

  const char* filename = MSG_file_get_name(file);
  XBT_INFO("\tOpen file '%s'",filename);
  st = MSG_storage_get_by_name(st_name);

  XBT_INFO("\tCapacity of the storage element '%s' is stored on: %llu / %llu",
            filename, MSG_storage_get_used_size(st), MSG_storage_get_size(st));

  /* Try to read for 10MB */
  read = MSG_file_read(file, 10000000);
  XBT_INFO("\tHave read %llu from '%s'",read,filename);

  /* Write 100KB in file from the current position, i.e, end of file or 10MB */
  write = MSG_file_write(file, 100000);
  XBT_INFO("\tHave written %llu in '%s'. Size now is: %llu",write,filename,
           MSG_file_get_size(file));


  XBT_INFO("\tCapacity of the storage element '%s' is stored on: %llu / %llu",
            filename, MSG_storage_get_used_size(st), MSG_storage_get_size(st));

  /* rewind to the beginning of the file */
  XBT_INFO("\tComing back to the beginning of the stream for file '%s'",
           filename);
  MSG_file_seek(file, 0, SEEK_SET);

  /* Try to read 110KB */
  read = MSG_file_read(file, 110000);
  XBT_INFO("\tHave read %llu from '%s' (of size %llu)",read,filename,
      MSG_file_get_size(file));

  /* rewind once again to the beginning of the file */
  XBT_INFO("\tComing back to the beginning of the stream for file '%s'",
           filename);
  MSG_file_seek(file, 0, SEEK_SET);

  /* Write 110KB in file from the current position, i.e, end of file or 10MB */
  write = MSG_file_write(file, 110000);
  XBT_INFO("\tHave written %llu in '%s'. Size now is: %llu", write,filename,
      MSG_file_get_size(file));

  XBT_INFO("\tCapacity of the storage element '%s' is stored on: %llu / %llu",
            filename, MSG_storage_get_used_size(st), MSG_storage_get_size(st));

  XBT_INFO("\tClose file '%s'",filename);
  MSG_file_close(file);


  return 0;
}
Beispiel #26
0
/** \ingroup msg_task_usage
 * \brief Executes a parallel task and waits for its termination.
 *
 * \param task a #msg_task_t to execute on the location on which the process is running.
 *
 * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
 * or #MSG_HOST_FAILURE otherwise
 */
msg_error_t MSG_parallel_task_execute(msg_task_t task)
{
  xbt_ex_t e;
  simdata_task_t simdata = task->simdata;
  msg_process_t self = SIMIX_process_self();
  simdata_process_t p_simdata = SIMIX_process_self_get_data(self);
  e_smx_state_t comp_state;
  msg_error_t status = MSG_OK;

#ifdef HAVE_TRACING
  TRACE_msg_task_execute_start(task);
#endif

  xbt_assert((!simdata->compute) && (task->simdata->isused == 0),
             "This task is executed somewhere else. Go fix your code! %d",
             task->simdata->isused);

  XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));

  if (simdata->computation_amount == 0 && !simdata->host_nb) {
#ifdef HAVE_TRACING
    TRACE_msg_task_execute_end(task);
#endif
    return MSG_OK;
  }


  TRY {

    simdata->isused=1;

    if (simdata->host_nb > 0) {
      simdata->compute = simcall_host_parallel_execute(task->name,
                                                       simdata->host_nb,
                                                       simdata->host_list,
                                                       simdata->comp_amount,
                                                       simdata->comm_amount,
                                                       1.0, -1.0);
      XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
    } else {
      simdata->compute = simcall_host_execute(task->name,
                                              p_simdata->m_host,
                                              simdata->computation_amount,
                                              simdata->priority);

    }
#ifdef HAVE_TRACING
    simcall_set_category(simdata->compute, task->category);
#endif
    p_simdata->waiting_action = simdata->compute;
    comp_state = simcall_host_execution_wait(simdata->compute);

    p_simdata->waiting_action = NULL;

    simdata->isused=0;

    XBT_DEBUG("Execution task '%s' finished in state %d",
              task->name, (int)comp_state);
  }
  CATCH(e) {
    switch (e.category) {
    case cancel_error:
      status = MSG_TASK_CANCELED;
      break;
    default:
      RETHROW;
    }
    xbt_ex_free(e);
  }
  /* action ended, set comm and compute = NULL, the actions is already destroyed
   * in the main function */
  simdata->computation_amount = 0.0;
  simdata->comm = NULL;
  simdata->compute = NULL;
#ifdef HAVE_TRACING
  TRACE_msg_task_execute_end(task);
#endif

  MSG_RETURN(status);
}
Beispiel #27
0
/** \ingroup msg_task_usage
 * \brief Executes a parallel task and waits for its termination.
 *
 * \param task a #msg_task_t to execute on the location on which the process is running.
 *
 * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
 * or #MSG_HOST_FAILURE otherwise
 */
msg_error_t MSG_parallel_task_execute(msg_task_t task)
{
  simdata_task_t simdata = task->simdata;
  simdata_process_t p_simdata = (simdata_process_t) SIMIX_process_self_get_data();
  e_smx_state_t comp_state;
  msg_error_t status = MSG_OK;

  TRACE_msg_task_execute_start(task);

  xbt_assert((!simdata->compute) && !task->simdata->isused,
             "This task is executed somewhere else. Go fix your code!");

  XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));

  if (simdata->flops_amount == 0 && !simdata->host_nb) {
    TRACE_msg_task_execute_end(task);
    return MSG_OK;
  }

  try {
    simdata->setUsed();

    if (simdata->host_nb > 0) {
      simdata->compute = static_cast<simgrid::simix::Exec*>(
          simcall_execution_parallel_start(task->name, simdata->host_nb,simdata->host_list,
                                                       simdata->flops_parallel_amount, simdata->bytes_parallel_amount,
                                                       1.0, -1.0));
      XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
    } else {
      unsigned long affinity_mask =
         (unsigned long)(uintptr_t) xbt_dict_get_or_null_ext(simdata->affinity_mask_db, (char *) p_simdata->m_host,
                                                             sizeof(msg_host_t));
      XBT_DEBUG("execute %s@%s with affinity(0x%04lx)",
                MSG_task_get_name(task), MSG_host_get_name(p_simdata->m_host), affinity_mask);

          simdata->compute = static_cast<simgrid::simix::Exec*>(
              simcall_execution_start(task->name, simdata->flops_amount, simdata->priority,
                                                 simdata->bound, affinity_mask));
    }
    simcall_set_category(simdata->compute, task->category);
    p_simdata->waiting_action = simdata->compute;
    comp_state = simcall_execution_wait(simdata->compute);

    p_simdata->waiting_action = nullptr;
    simdata->setNotUsed();

    XBT_DEBUG("Execution task '%s' finished in state %d", task->name, (int)comp_state);
  }
  catch (xbt_ex& e) {
    switch (e.category) {
    case cancel_error:
      status = MSG_TASK_CANCELED;
      break;
    case host_error:
      status = MSG_HOST_FAILURE;
      break;
    default:
      throw;
    }
  }

  /* action ended, set comm and compute = nullptr, the actions is already destroyed in the main function */
  simdata->flops_amount = 0.0;
  simdata->comm = nullptr;
  simdata->compute = nullptr;
  TRACE_msg_task_execute_end(task);

  MSG_RETURN(status);
}
Beispiel #28
0
/** \ingroup msg_task_usage
 * \brief Executes a parallel task and waits for its termination.
 *
 * \param task a #msg_task_t to execute on the location on which the process is running.
 *
 * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
 * or #MSG_HOST_FAILURE otherwise
 */
msg_error_t MSG_parallel_task_execute(msg_task_t task)
{
  xbt_ex_t e;
  simdata_task_t simdata = task->simdata;
  msg_process_t self = SIMIX_process_self();
  simdata_process_t p_simdata = SIMIX_process_self_get_data(self);
  e_smx_state_t comp_state;
  msg_error_t status = MSG_OK;

  TRACE_msg_task_execute_start(task);

  xbt_assert((!simdata->compute) && (task->simdata->isused == 0),
             "This task is executed somewhere else. Go fix your code! %d",
             task->simdata->isused!=NULL);

  XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));

  if (simdata->flops_amount == 0 && !simdata->host_nb) {
    TRACE_msg_task_execute_end(task);
    return MSG_OK;
  }


  TRY {
    if (msg_global->debug_multiple_use)
      MSG_BT(simdata->isused, "Using Backtrace");
    else
      simdata->isused = (void*)1;

    if (simdata->host_nb > 0) {
      simdata->compute = simcall_process_parallel_execute(task->name,
                                                       simdata->host_nb,
                                                       simdata->host_list,
                                                       simdata->flops_parallel_amount,
                                                       simdata->bytes_parallel_amount,
                                                       1.0, -1.0);
      XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
    } else {
      unsigned long affinity_mask = (unsigned long) xbt_dict_get_or_null_ext(simdata->affinity_mask_db, (char *) p_simdata->m_host, sizeof(msg_host_t));
      XBT_DEBUG("execute %s@%s with affinity(0x%04lx)", MSG_task_get_name(task), MSG_host_get_name(p_simdata->m_host), affinity_mask);

      simdata->compute = simcall_process_execute(task->name,
                                              simdata->flops_amount,
                                              simdata->priority,
                                              simdata->bound,
                                              affinity_mask
                                              );

    }
    simcall_set_category(simdata->compute, task->category);
    p_simdata->waiting_action = simdata->compute;
    comp_state = simcall_process_execution_wait(simdata->compute);

    p_simdata->waiting_action = NULL;

    if (msg_global->debug_multiple_use && simdata->isused!=0)
      xbt_ex_free(*(xbt_ex_t*)simdata->isused);
    simdata->isused = 0;

    XBT_DEBUG("Execution task '%s' finished in state %d",
              task->name, (int)comp_state);
  }
  CATCH(e) {
    switch (e.category) {
    case cancel_error:
      status = MSG_TASK_CANCELED;
      break;
    case host_error:
      status = MSG_HOST_FAILURE;
      break;
    default:
      RETHROW;
    }
    xbt_ex_free(e);
  }
  /* action ended, set comm and compute = NULL, the actions is already destroyed
   * in the main function */
  simdata->flops_amount = 0.0;
  simdata->comm = NULL;
  simdata->compute = NULL;
  TRACE_msg_task_execute_end(task);

  MSG_RETURN(status);
}