Пример #1
0
static int runner(int argc, char *argv[])
{
  /* Retrieve the list of all hosts as an array of hosts */
  int hosts_count = MSG_get_host_number();
  msg_host_t *hosts = xbt_dynar_to_array(MSG_hosts_as_dynar());

  XBT_INFO("First, build a classical parallel task, with 1 Gflop to execute on each node, "
           "and 10MB to exchange between each pair");
  double *computation_amounts = xbt_new0(double, hosts_count);
  double *communication_amounts = xbt_new0(double, hosts_count * hosts_count);

  for (int i = 0; i < hosts_count; i++)
    computation_amounts[i] = 1e9; // 1 Gflop

  for (int i = 0; i < hosts_count; i++)
    for (int j = i + 1; j < hosts_count; j++)
      communication_amounts[i * hosts_count + j] = 1e7; // 10 MB

  msg_task_t ptask =
    MSG_parallel_task_create("parallel task", hosts_count, hosts, computation_amounts, communication_amounts, NULL);
  MSG_parallel_task_execute(ptask);
  MSG_task_destroy(ptask);
  /* The arrays communication_amounts and computation_amounts are not to be freed manually */

  XBT_INFO("Then, build a parallel task involving only computations and no communication (1 Gflop per node)");
  computation_amounts = xbt_new0(double, hosts_count);
  for (int i = 0; i < hosts_count; i++)
    computation_amounts[i] = 1e9; // 1 Gflop
  ptask = MSG_parallel_task_create("parallel exec", hosts_count, hosts, computation_amounts, NULL/* no comm */, NULL);
  MSG_parallel_task_execute(ptask);
  MSG_task_destroy(ptask);

  XBT_INFO("Then, build a parallel task with no computation nor communication (synchro only)");
  computation_amounts = xbt_new0(double, hosts_count);
  communication_amounts = xbt_new0(double, hosts_count * hosts_count); /* memset to 0 by xbt_new0 */
  ptask = MSG_parallel_task_create("parallel sync", hosts_count, hosts, computation_amounts, communication_amounts, NULL);
  MSG_parallel_task_execute(ptask);
  MSG_task_destroy(ptask);

   XBT_INFO("Finally, trick the ptask to do a 'remote execution', on host %s", MSG_host_get_name(hosts[1]));
  computation_amounts = xbt_new0(double, 1);
  computation_amounts[0] = 1e9; // 1 Gflop
  msg_host_t *remote = xbt_new(msg_host_t,1);
  remote[0] = hosts[1];
  ptask = MSG_parallel_task_create("remote exec", 1, remote, computation_amounts, NULL/* no comm */, NULL);
  MSG_parallel_task_execute(ptask);
  MSG_task_destroy(ptask);
  free(remote);

  XBT_INFO("Goodbye now!");
  free(hosts);
  return 0;
}
Пример #2
0
static int par_task(int /*argc*/, char* /*argv*/ [])
{
  double * computation_amount = new double[2] {10E7, 10E7};
  double * communication_amount = new double[4] {1E6, 1E6, 1E6, 1E6};
  double progress;

  std::vector<msg_host_t> hosts_to_use = std::vector<msg_host_t>();
  hosts_to_use.push_back(MSG_get_host_by_name("Tremblay"));
  hosts_to_use.push_back(MSG_get_host_by_name("Jupiter"));

  msg_task_t task = MSG_parallel_task_create("ptask", 2, hosts_to_use.data(), computation_amount, communication_amount, NULL);
  tasks.push_back(task);

  XBT_INFO("get the progress of %s before the task starts", task->name);
  progress = MSG_task_get_remaining_work_ratio(task);
  xbt_assert(progress == 1.0, "Progress should be 1.0 not %f", progress);

  XBT_INFO("Executing task: \"%s\"", task->name);
  MSG_parallel_task_execute(task);

  XBT_INFO("get the progress of %s after the task finishes", task->name);
  progress = MSG_task_get_remaining_work_ratio(task);
  xbt_assert(progress == 0.0, "Progress should be equal to 0.0 not %f", progress);

  MSG_task_destroy(task);
  delete[] computation_amount;
  delete[] communication_amount;

  XBT_INFO("Goodbye now!");
  return 0;
}
Пример #3
0
int execute(int argc, char *argv[])
{
  char buffer[32];
  int i, j;
  msg_host_t *m_host_list = NULL;
  msg_task_t task = NULL;
  int host_list_size;
  double *computation_duration = NULL;
  double *communication_table = NULL;
  double communication_amount = 0;
  double computation_amount = 0;
  double execution_time;


  host_list_size = argc - 3;
  XBT_DEBUG("host_list_size=%d", host_list_size);
  m_host_list = calloc(host_list_size, sizeof(msg_host_t));
  for (i = 1; i <= host_list_size; i++) {
    m_host_list[i - 1] = MSG_get_host_by_name(argv[i]);
    xbt_assert(m_host_list[i - 1] != NULL,
                "Unknown host %s. Stopping Now! ", argv[i]);
  }

  _XBT_GNUC_UNUSED int read;
  read = sscanf(argv[argc - 2], "%lg", &computation_amount);
  xbt_assert(read, "Invalid argument %s\n", argv[argc - 2]);
  read = sscanf(argv[argc - 1], "%lg", &communication_amount);
  xbt_assert(read, "Invalid argument %s\n", argv[argc - 1]);
  computation_duration = (double *) calloc(host_list_size, sizeof(double));
  communication_table =
      (double *) calloc(host_list_size * host_list_size, sizeof(double));
  for (i = 0; i < host_list_size; i++) {
    computation_duration[i] = computation_amount / host_list_size;
    for (j = 0; j < host_list_size; j++)
      communication_table[i * host_list_size + j] =
          communication_amount / (host_list_size * host_list_size);
  }

  sprintf(buffer, "redist#0\n");
  task = MSG_parallel_task_create(buffer,
                                  host_list_size,
                                  m_host_list,
                                  computation_duration,
                                  communication_table, NULL);

  execution_time = MSG_get_clock();
  MSG_parallel_task_execute(task);
  MSG_task_destroy(task);
  xbt_free(m_host_list);
  execution_time = MSG_get_clock() - execution_time;

  XBT_INFO("execution_time=%g ", execution_time);

  return 0;
}
Пример #4
0
/** \ingroup msg_task_usage
 * \brief Executes a task and waits for its termination.
 *
 * This function is used for describing the behavior of a process. It
 * takes only one parameter.
 * \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_task_execute(msg_task_t task)
{
  /* TODO: add this to other locations */
  msg_host_t host = MSG_process_get_host(MSG_process_self());
  MSG_host_add_task(host, task);

  msg_error_t ret = MSG_parallel_task_execute(task);

  MSG_host_del_task(host, task);

  return ret;
}
Пример #5
0
/** \ingroup msg_file_management
 * \brief Write into a file (local or remote)
 *
 * \param size of the file to write
 * \param fd is a the file descriptor
 * \return the number of bytes successfully write or -1 if an error occurred
 */
sg_size_t MSG_file_write(msg_file_t fd, sg_size_t size)
{
  msg_file_priv_t file_priv = MSG_file_priv(fd);
  sg_size_t write_size, offset;

  /* Find the host where the file is physically located (remote or local)*/
  msg_storage_t storage_src =(msg_storage_t) xbt_lib_get_elm_or_null(storage_lib, file_priv->storageId);
  msg_storage_priv_t storage_priv_src = MSG_storage_priv(storage_src);
  msg_host_t attached_host = MSG_get_host_by_name(storage_priv_src->hostname);

  if(strcmp(storage_priv_src->hostname, MSG_host_get_name(MSG_host_self()))){
    /* the file is hosted on a remote host, initiate a communication between src and dest hosts for data transfer */
    XBT_DEBUG("File is on %s remote host, initiate data transfer of %llu bytes.", storage_priv_src->hostname, size);
    msg_host_t *m_host_list = NULL;
    m_host_list = calloc(2, sizeof(msg_host_t));

    m_host_list[0] = MSG_host_self();
    m_host_list[1] = attached_host;
    double flops_amount[] = { 0, 0 };
    double bytes_amount[] = { 0, (double)size, 0, 0 };

    msg_task_t task = MSG_parallel_task_create("file transfer for write", 2, m_host_list, flops_amount, bytes_amount, NULL);
    msg_error_t transfer = MSG_parallel_task_execute(task);
    MSG_task_destroy(task);
    free(m_host_list);
    if(transfer != MSG_OK){
      if (transfer == MSG_HOST_FAILURE)
        XBT_WARN("Transfer error, %s remote host just turned off!", MSG_host_get_name(attached_host));
      if (transfer == MSG_TASK_CANCELED)
        XBT_WARN("Transfer error, task has been canceled!");

      return -1;
    }
  }
  /* Write file on local or remote host */
  offset = simcall_file_tell(file_priv->simdata->smx_file);
  write_size = simcall_file_write(file_priv->simdata->smx_file, size, attached_host);
  file_priv->size = offset+write_size;

  return write_size;
}
Пример #6
0
/** Emitter function  */
int test(int argc, char *argv[])
{
  xbt_dynar_t slaves_dynar;
  int slaves_count = 0;
  msg_host_t *slaves = NULL;
  double task_comp_size = 100000;
  double task_comm_size = 10000;
  double *computation_amount = NULL;
  double *communication_amount = NULL;
  msg_task_t ptask = NULL;
  int i, j;

  slaves_dynar = MSG_hosts_as_dynar();
  slaves_count = xbt_dynar_length(slaves_dynar);
  slaves = xbt_dynar_to_array(slaves_dynar);

  computation_amount = xbt_new0(double, slaves_count);
  communication_amount = xbt_new0(double, slaves_count * slaves_count);

  for (i = 0; i < slaves_count; i++)
    computation_amount[i] = task_comp_size;

  for (i = 0; i < slaves_count; i++)
    for (j = i + 1; j < slaves_count; j++)
      communication_amount[i * slaves_count + j] = task_comm_size;

  ptask = MSG_parallel_task_create("parallel task",
                                   slaves_count, slaves,
                                   computation_amount,
                                   communication_amount, NULL);
  MSG_parallel_task_execute(ptask);

  MSG_task_destroy(ptask);
  /* There is no need to free that! */
/*   free(communication_amount); */
/*   free(computation_amount); */

  XBT_INFO("Goodbye now!");
  free(slaves);
  return 0;
}
Пример #7
0
/** \ingroup msg_task_usage
 * \brief Executes a task and waits for its termination.
 *
 * This function is used for describing the behavior of a process. It
 * takes only one parameter.
 * \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_task_execute(msg_task_t task)
{
  return MSG_parallel_task_execute(task);
}