Exemplo n.º 1
0
int main(int argc, char **argv)
{
  unsigned int ctr;
  const SD_workstation_t *workstations;
  SD_task_t t1, c1, t2, c2, t3, c3, t4, task;
  xbt_dynar_t changed_tasks;

  SD_init(&argc, argv);
  SD_create_environment(argv[1]);
  workstations = SD_workstation_get_list();

  t1 = SD_task_create_comp_seq("t1", NULL, 25000000);
  c1 = SD_task_create_comm_e2e("c1", NULL, 125000000);
  t2 = SD_task_create_comp_seq("t2", NULL, 25000000);
  c2 = SD_task_create_comm_e2e("c2", NULL, 62500000);
  t3 = SD_task_create_comp_seq("t3", NULL, 25000000);
  c3 = SD_task_create_comm_e2e("c3", NULL, 31250000);
  t4 = SD_task_create_comp_seq("t4", NULL, 25000000);

  /* Add dependencies: t1->c1->t2->c2->t3 */
  SD_task_dependency_add(NULL, NULL, t1, c1);
  SD_task_dependency_add(NULL, NULL, c1, t2);
  SD_task_dependency_add(NULL, NULL, t2, c2);
  SD_task_dependency_add(NULL, NULL, c2, t3);
  SD_task_dependency_add(NULL, NULL, t3, c3);
  SD_task_dependency_add(NULL, NULL, c3, t4);

  /* Schedule tasks t1 and w3 on first host, t2 on second host */
  /* Transfers are auto-scheduled */
  SD_task_schedulel(t1, 1, workstations[0]);
  SD_task_schedulel(t2, 1, workstations[1]);
  SD_task_schedulel(t3, 1, workstations[0]);
  SD_task_schedulel(t4, 1, workstations[1]);

  /* Add some watchpoint upon task completion */
  SD_task_watch(t1, SD_DONE);
  SD_task_watch(c1, SD_DONE);
  SD_task_watch(t2, SD_DONE);
  SD_task_watch(c2, SD_DONE);
  SD_task_watch(t3, SD_DONE);
  SD_task_watch(c3, SD_DONE);
  SD_task_watch(t4, SD_DONE);

  while (!xbt_dynar_is_empty((changed_tasks = SD_simulate(-1.0)))) {    
    XBT_INFO("link1: bw=%.0f, lat=%f",
             SD_route_get_current_bandwidth(workstations[0], workstations[1]),
             SD_route_get_current_latency(workstations[0], workstations[1]));
    XBT_INFO("Jupiter: power=%.0f",
             SD_workstation_get_power(workstations[0])*
             SD_workstation_get_available_power(workstations[0]));
    XBT_INFO("Tremblay: power=%.0f",
             SD_workstation_get_power(workstations[1])*
             SD_workstation_get_available_power(workstations[1]));
    xbt_dynar_foreach(changed_tasks, ctr, task) {
      XBT_INFO("Task '%s' start time: %f, finish time: %f",
           SD_task_get_name(task),
           SD_task_get_start_time(task), SD_task_get_finish_time(task));
      if (SD_task_get_state(task)==SD_DONE)
        SD_task_destroy(task);
    }
    xbt_dynar_free_container(&changed_tasks);
  }
Exemplo n.º 2
0
int main(int argc, char **argv)
{
  /* initialisation of SD */

  SD_workstation_t w1, w2;
  const SD_workstation_t *workstations;
  const SD_link_t *route;
  const char *name1;
  const char *name2;
  int route_size, i, j, k;
  int list_size;

#ifdef _XBT_WIN32
  setbuf(stderr, NULL);
  setbuf(stdout, NULL);
#else
  setvbuf(stdout, NULL, _IOLBF, 0);
#endif

  SD_init(&argc, argv);

  /* creation of the environment */
  SD_create_environment(argv[1]);
  printf("Workstation number: %d, link number: %d\n",
         SD_workstation_get_number(), SD_link_get_number());

  if (argc >= 3) {
    if (!strcmp(argv[2], "ONE_LINK")) {
      workstations = SD_workstation_get_list();
      w1 = workstations[0];
      w2 = workstations[1];
      name1 = SD_workstation_get_name(w1);
      name2 = SD_workstation_get_name(w2);

      printf("Route between %s and %s\n", name1, name2);
      route = SD_route_get_list(w1, w2);
      route_size = SD_route_get_size(w1, w2);
      printf("Route size %d\n", route_size);
      for (i = 0; i < route_size; i++) {
      printf("  Link %s: latency = %f, bandwidth = %f\n",
           SD_link_get_name(route[i]),
           SD_link_get_current_latency(route[i]),
           SD_link_get_current_bandwidth(route[i]));
      }
      printf("Route latency = %f, route bandwidth = %f\n",
         SD_route_get_current_latency(w1, w2),
         SD_route_get_current_bandwidth(w1, w2));
    }
    if (!strcmp(argv[2], "FULL_LINK")) {
      workstations = SD_workstation_get_list();
      list_size = SD_workstation_get_number();
      for (i = 0; i < list_size; i++) {
      w1 = workstations[i];
      name1 = SD_workstation_get_name(w1);
      for (j = 0; j < list_size; j++) {
        w2 = workstations[j];
        name2 = SD_workstation_get_name(w2);
        printf("Route between %s and %s\n", name1, name2);
        route = SD_route_get_list(w1, w2);
        route_size = SD_route_get_size(w1, w2);
        printf("  Route size %d\n", route_size);
        for (k = 0; k < route_size; k++) {
        printf("  Link %s: latency = %f, bandwidth = %f\n",
             SD_link_get_name(route[k]),
             SD_link_get_current_latency(route[k]),
             SD_link_get_current_bandwidth(route[k]));
        }
        printf("  Route latency = %f, route bandwidth = %f\n",
           SD_route_get_current_latency(w1, w2),
           SD_route_get_current_bandwidth(w1, w2));
      }
      }
    }
    if (!strcmp(argv[2], "PROP")) {
      printf("SG_TEST_mem: %s\n",
          SD_workstation_get_property_value(SD_workstation_get_by_name("host1"),
          "SG_TEST_mem")
          );
      printf("Author: %s\n", SD_as_router_get_property_value("AS0", "author"));
      printf("AS1: %s\n", SD_as_router_get_property_value("AS1", "name"));
      printf("AS2: %s\n", SD_as_router_get_property_value("AS2", "name"));
    }
  }

  SD_exit();
  return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
  int i;
  unsigned int ctr;
  const char *platform_file;
  const SD_workstation_t *workstations;
  const char *name1;
  const char *name2;
  double computation_amount1;
  double computation_amount2;
  double communication_amount12;
  double communication_amount21;
  const SD_link_t *route;
  int route_size;
  SD_task_t task, taskA, taskB, taskC, taskD, checkB, checkD;
  xbt_dynar_t changed_tasks;
  xbt_ex_t ex;
  const int workstation_number = 2;
  SD_workstation_t workstation_list[2];
  double computation_amount[2];
  double communication_amount[4] = { 0 };
  double rate = -1.0;
  SD_workstation_t w1, w2;

  /* initialization of SD */
  SD_init(&argc, argv);

  /*  xbt_log_control_set("sd.thres=debug"); */

  if (argc < 2) {
    XBT_INFO("Usage: %s platform_file", argv[0]);
    XBT_INFO("example: %s sd_platform.xml", argv[0]);
    exit(1);
  }

  /* creation of the environment */
  platform_file = argv[1];
  SD_create_environment(platform_file);

  /* test the estimation functions */
  workstations = SD_workstation_get_list();
  w1 = workstations[0];
  w2 = workstations[1];
  SD_workstation_set_access_mode(w2, SD_WORKSTATION_SEQUENTIAL_ACCESS);
  name1 = SD_workstation_get_name(w1);
  name2 = SD_workstation_get_name(w2);
  computation_amount1 = 2000000;
  computation_amount2 = 1000000;
  communication_amount12 = 2000000;
  communication_amount21 = 3000000;
  XBT_INFO("Computation time for %f flops on %s: %f", computation_amount1,
        name1, SD_workstation_get_computation_time(w1,
                                                   computation_amount1));
  XBT_INFO("Computation time for %f flops on %s: %f", computation_amount2,
        name2, SD_workstation_get_computation_time(w2,
                                                   computation_amount2));

  XBT_INFO("Route between %s and %s:", name1, name2);
  route = SD_route_get_list(w1, w2);
  route_size = SD_route_get_size(w1, w2);
  for (i = 0; i < route_size; i++) {
    XBT_INFO("   Link %s: latency = %f, bandwidth = %f",
          SD_link_get_name(route[i]),
          SD_link_get_current_latency(route[i]),
          SD_link_get_current_bandwidth(route[i]));
  }
  XBT_INFO("Route latency = %f, route bandwidth = %f",
        SD_route_get_current_latency(w1, w2),
        SD_route_get_current_bandwidth(w1, w2));
  XBT_INFO("Communication time for %f bytes between %s and %s: %f",
        communication_amount12, name1, name2,
        SD_route_get_communication_time(w1, w2, communication_amount12));
  XBT_INFO("Communication time for %f bytes between %s and %s: %f",
        communication_amount21, name2, name1,
        SD_route_get_communication_time(w2, w1, communication_amount21));

  /* creation of the tasks and their dependencies */
  taskA = SD_task_create("Task A", NULL, 10.0);
  taskB = SD_task_create("Task B", NULL, 40.0);
  taskC = SD_task_create("Task C", NULL, 30.0);
  taskD = SD_task_create("Task D", NULL, 60.0);

  /* try to attach and retrieve user data to a task */
  SD_task_set_data(taskA, (void*) &computation_amount1);
  if (computation_amount1 != (*((double*) SD_task_get_data(taskA))))
      XBT_ERROR("User data was corrupted by a simple set/get");

  SD_task_dependency_add(NULL, NULL, taskB, taskA);
  SD_task_dependency_add(NULL, NULL, taskC, taskA);
  SD_task_dependency_add(NULL, NULL, taskD, taskB);
  SD_task_dependency_add(NULL, NULL, taskD, taskC);
  /*  SD_task_dependency_add(NULL, NULL, taskA, taskD); /\* deadlock */



  TRY {
    SD_task_dependency_add(NULL, NULL, taskA, taskA);   /* shouldn't work and must raise an exception */
    xbt_die("Hey, I can add a dependency between Task A and Task A!");
  }
  CATCH(ex) {
    if (ex.category != arg_error)
      RETHROW;                  /* this is a serious error */
    xbt_ex_free(ex);
  }

  TRY {
    SD_task_dependency_add(NULL, NULL, taskB, taskA);   /* shouldn't work and must raise an exception */
    xbt_die("Oh oh, I can add an already existing dependency!");
  }
  CATCH(ex) {
    if (ex.category != arg_error)
      RETHROW;
    xbt_ex_free(ex);
  }

  TRY {
    SD_task_dependency_remove(taskA, taskC);    /* shouldn't work and must raise an exception */
    xbt_die("Dude, I can remove an unknown dependency!");
  }
  CATCH(ex) {
    if (ex.category != arg_error)
      RETHROW;
    xbt_ex_free(ex);
  }

  TRY {
    SD_task_dependency_remove(taskC, taskC);    /* shouldn't work and must raise an exception */
    xbt_die("Wow, I can remove a dependency between Task C and itself!");
  }
  CATCH(ex) {
    if (ex.category != arg_error)
      RETHROW;
    xbt_ex_free(ex);
  }


  /* if everything is ok, no exception is forwarded or rethrown by main() */

  /* watch points */
  SD_task_watch(taskD, SD_DONE);
  SD_task_watch(taskB, SD_DONE);
  SD_task_unwatch(taskD, SD_DONE);


  /* scheduling parameters */
  workstation_list[0] = w1;
  workstation_list[1] = w2;
  computation_amount[0] = computation_amount1;
  computation_amount[1] = computation_amount2;

  communication_amount[1] = communication_amount12;
  communication_amount[2] = communication_amount21;

  /* estimated time */
  task = taskD;
  XBT_INFO("Estimated time for '%s': %f", SD_task_get_name(task),
        SD_task_get_execution_time(task, workstation_number,
                                   workstation_list, computation_amount,
                                   communication_amount));

  /* let's launch the simulation! */

  SD_task_schedule(taskA, workstation_number, workstation_list,
                   computation_amount, communication_amount, rate);
  SD_task_schedule(taskB, workstation_number, workstation_list,
                   computation_amount, communication_amount, rate);
  SD_task_schedule(taskC, workstation_number, workstation_list,
                   computation_amount, communication_amount, rate);
  SD_task_schedule(taskD, workstation_number, workstation_list,
                   computation_amount, communication_amount, rate);

  changed_tasks = SD_simulate(-1.0);
  xbt_dynar_foreach(changed_tasks, ctr, task) {
    XBT_INFO("Task '%s' start time: %f, finish time: %f",
          SD_task_get_name(task),
          SD_task_get_start_time(task), SD_task_get_finish_time(task));
  }