int main(int argc, char *argv[]){
  MSG_init(&argc, argv);

  xbt_assert(argc == 2);
  MSG_create_environment(argv[1]);

  xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
  msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
  launch_master(pm0);

  int res = MSG_main();
  XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
  xbt_dynar_free(&hosts_dynar);

  return !(res == MSG_OK);
}
Beispiel #2
0
/** @brief Merge dynar d2 into d1
 *
 * \param d1 dynar to keep
 * \param d2 dynar to merge into d1. This dynar is free at end.
 */
void xbt_dynar_merge(xbt_dynar_t *d1, xbt_dynar_t *d2)
{
  if((*d1)->elmsize != (*d2)->elmsize)
    xbt_die("Element size must are not equal");

  const unsigned long elmsize = (*d1)->elmsize;

  void *ptr = _xbt_dynar_elm((*d2), 0);
  _xbt_dynar_resize(*d1, (*d1)->size + (*d2)->size);
  void *elm = _xbt_dynar_elm((*d1), (*d1)->used);

  memcpy(elm, ptr, ((*d2)->size)*elmsize);
  (*d1)->used += (*d2)->used;
  (*d2)->used = 0;
  xbt_dynar_free(d2);
}
Beispiel #3
0
JNIEXPORT int JNICALL Java_org_simgrid_msg_Comm_waitAny(JNIEnv *env, jclass cls, jobjectArray jcomms)
{
  int count;
  msg_comm_t* comms = jarray_to_commArray(env, jcomms, &count);
  if (not comms)
    return -1;
  xbt_dynar_t dyn = xbt_dynar_new(sizeof(msg_comm_t),nullptr);
  for (int i=0; i<count; i++) {
    xbt_dynar_push(dyn, &(comms[i]));
  }

  int rank = MSG_comm_waitany(dyn);
  delete[] comms;
  xbt_dynar_free(&dyn);
  return rank;
}
Beispiel #4
0
/* Basic SimDag Test 0
 * Scenario:
 *   - Create a no-op Init task
 *   - Create two communication tasks: 100MB and 1B
 *   - Schedule them concurrently on the two hosts of the platform
 * The two communications occur simultaneously but one is so short that it has
 * no impact on the other.
 * Simulated time should be:
 *          1e8/1.25e8 + 1e-4 = 0.8001 seconds
 * This corresponds to paying latency once and having the full bandwidth for the
 * big message.
 */
int main(int argc, char **argv)
{
  SD_task_t taskInit;
  SD_task_t taskA;
  SD_task_t taskB;
  xbt_dynar_t ret;

  /* scheduling parameters */

  double communication_amount1[] = { 0, 1e8, 0, 0 };
  double communication_amount2[] = { 0, 1, 0, 0 };
  const double no_cost[] = { 0.0, 0.0 };

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

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

  /* creation of the tasks and their dependencies */
  taskInit = SD_task_create("Init", NULL, 1.0);
  taskA = SD_task_create("Task Comm 1", NULL, 1.0);
  taskB = SD_task_create("Task Comm 2", NULL, 1.0);

  /* let's launch the simulation! */

  SD_task_schedule(taskInit, 1, SD_workstation_get_list(), no_cost,
                   no_cost, -1.0);
  SD_task_schedule(taskA, 2, SD_workstation_get_list(), no_cost,
                   communication_amount1, -1.0);
  SD_task_schedule(taskB, 2, SD_workstation_get_list(), no_cost,
                   communication_amount2, -1.0);

  SD_task_dependency_add(NULL, NULL, taskInit, taskA);
  SD_task_dependency_add(NULL, NULL, taskInit, taskB);

  ret = SD_simulate(-1.0);
  xbt_dynar_free(&ret);
  SD_task_destroy(taskInit);
  SD_task_destroy(taskA);
  SD_task_destroy(taskB);

  XBT_INFO("Simulation time: %f", SD_get_clock());

  SD_exit();
  return 0;
}
Beispiel #5
0
NetworkIBModel::NetworkIBModel()
 : NetworkSmpiModel() {
  m_haveGap=false;
  active_nodes=NULL;
    
  const char* IB_factors_string=sg_cfg_get_string("smpi/IB_penalty_factors");
  xbt_dynar_t radical_elements = xbt_str_split(IB_factors_string, ";");
  
  if(xbt_dynar_length(radical_elements)!=3)
    surf_parse_error("smpi/IB_penalty_factors should be provided and contain 3 elements, semi-colon separated : for example 0.965;0.925;1.35");
  
  Be = atof(xbt_dynar_get_as(radical_elements, 0, char *));
  Bs = atof(xbt_dynar_get_as(radical_elements, 1, char *));
  ys = atof(xbt_dynar_get_as(radical_elements, 2, char *));

  xbt_dynar_free(&radical_elements);
}
Beispiel #6
0
int main(int argc, char **argv)
{
  MSG_init(&argc, argv);
  MSG_create_environment(argv[1]);
  xbt_dynar_t hosts =  MSG_hosts_as_dynar();
  MSG_function_register("host", host);
  unsigned long nb_hosts = xbt_dynar_length(hosts);
  XBT_INFO("Number of host '%lu'",nb_hosts);
  for(int i = 0 ; i < nb_hosts; i++){
    MSG_process_create("host", host, NULL, xbt_dynar_get_as(hosts,i,msg_host_t));
  }
  xbt_dynar_free(&hosts);

  int res = MSG_main();
  XBT_INFO("Simulation time %g", MSG_get_clock());
  return res != MSG_OK;
}
Beispiel #7
0
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;

  MSG_init(&argc, argv);
  xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);  /** - Load the platform description */
  MSG_function_register("dream_master", dream_master); /** - Create and deploy the @ref dream_master */
  xbt_dynar_t hosts = MSG_hosts_as_dynar();
  MSG_process_create("dream_master", dream_master, NULL, xbt_dynar_getfirst_as(hosts, msg_host_t));
  xbt_dynar_free(&hosts);
  res = MSG_main();                 /** - Run the simulation */

  XBT_INFO("Simulation time %g", MSG_get_clock());
  return res != MSG_OK;
}
Beispiel #8
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 #9
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 #10
0
int main(int argc, char **argv)
{
  double time;
  SD_task_t root;
  SD_task_t task1;
  SD_task_t task2;
  double communication_amount1[] = { 0.0, 1.0, 0.0, 0.0 };
  double communication_amount2[] = { 0.0, 1.0, 0.0, 0.0 };
  double no_cost1[] = { 0.0 };
  double no_cost[] = { 0.0, 0.0 };
  xbt_dynar_t ret;

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

  root = SD_task_create("Root", NULL, 1.0);
  task1 = SD_task_create("Comm 1", NULL, 1.0);
  task2 = SD_task_create("Comm 2", NULL, 1.0);

  SD_task_schedule(root, 1, SD_workstation_get_list(), no_cost1, no_cost1,
                   -1.0);
  SD_task_schedule(task1, 2, SD_workstation_get_list(), no_cost,
                   communication_amount1, -1.0);
  SD_task_schedule(task2, 2, SD_workstation_get_list(), no_cost,
                   communication_amount2, -1.0);

  SD_task_dependency_add(NULL, NULL, root, task1);
  SD_task_dependency_add(NULL, NULL, root, task2);

  ret = SD_simulate(-1.0);
  xbt_dynar_free(&ret);

  time = SD_get_clock();

  printf("%g\n", time);
  fflush(stdout);

  SD_task_destroy(root);
  SD_task_destroy(task1);
  SD_task_destroy(task2);

  SD_exit();

  return 0;
}
Beispiel #11
0
/** Test function */
msg_error_t test_all(const char *platform_file)
{
  msg_error_t res = MSG_OK;
  xbt_dynar_t all_hosts;
  msg_host_t first_host;

  MSG_config("host/model", "ptask_L07");
  MSG_create_environment(platform_file);

  all_hosts = MSG_hosts_as_dynar();
  first_host = xbt_dynar_getfirst_as(all_hosts,msg_host_t);
  MSG_process_create("test", test, NULL, first_host);
  res = MSG_main();
  xbt_dynar_free(&all_hosts);

  XBT_INFO("Simulation time %g", MSG_get_clock());
  return res;
}
Beispiel #12
0
static void mytest(const char *input, const char *patterns,
                   const char *expected)
{
  xbt_dynar_t dyn_patterns;     /* splited string */
  xbt_dict_t p;                 /* patterns */
  unsigned int cpt;
  char *str;                    /*foreach */
  xbt_strbuff_t sb;             /* what we test */

  p = xbt_dict_new_homogeneous(free);
  dyn_patterns = xbt_str_split(patterns, " ");
  xbt_dynar_foreach(dyn_patterns, cpt, str) {
    xbt_dynar_t keyvals = xbt_str_split(str, "=");
    char *key = xbt_dynar_get_as(keyvals, 0, char *);
    char *val = xbt_dynar_get_as(keyvals, 1, char *);
    xbt_str_subst(key, '_', ' ', 0);    // to put space in names without breaking the enclosing dynar_foreach
    xbt_dict_set(p, key, xbt_strdup(val), NULL);
    xbt_dynar_free(&keyvals);
  }
Beispiel #13
0
JNIEXPORT jobjectArray JNICALL
Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg)
{
  int index;
  jobjectArray jtable;
  jobject jhost;
  jstring jname;
  msg_host_t host;

  xbt_dynar_t table =  MSG_hosts_as_dynar();
  int count = xbt_dynar_length(table);

  jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");

  if (!cls) {
    return NULL;
  }

  jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL);

  if (!jtable) {
    jxbt_throw_jni(env, "Hosts table allocation failed");
    return NULL;
  }

  for (index = 0; index < count; index++) {
    host = xbt_dynar_get_as(table,index,msg_host_t);
    jhost = (jobject) (MSG_host_get_data(host));

    if (!jhost) {
      jname = (*env)->NewStringUTF(env, MSG_host_get_name(host));

      jhost =
      		Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname);
      /* FIXME: leak of jname ? */
    }

    (*env)->SetObjectArrayElement(env, jtable, index, jhost);
  }
  xbt_dynar_free(&table);
  return jtable;
}
int main(int argc, char *argv[])
{
  MSG_init(&argc, argv);
  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
             "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);

  MSG_create_environment(argv[1]);

  //declaring user variables
  TRACE_host_variable_declare("is_worker");
  TRACE_host_variable_declare("is_master");
  TRACE_host_variable_declare("task_creation");
  TRACE_host_variable_declare("task_computation");

  //declaring user markers and values
  TRACE_declare_mark("msmark");
  TRACE_declare_mark_value ("msmark", "start_send_tasks");
  TRACE_declare_mark_value ("msmark", "finish_send_tasks");

  //declaring user categories with RGB colors (values from 0 to 1)
  TRACE_category_with_color ("compute", "1 0 0");  //compute is red
  TRACE_category_with_color ("finalize", "0 1 0"); //finalize is green
  //categories without user-defined colors receive random colors generated by the tracing system
  TRACE_category ("request");
  TRACE_category_with_color ("report", NULL);

  MSG_function_register("master", master);
  MSG_function_register("worker", worker);
  MSG_launch_application(argv[2]);

  MSG_main();

  unsigned int cursor;
  xbt_dynar_t categories = TRACE_get_categories ();
  if (categories){
    XBT_INFO ("Declared tracing categories:");
    char *category;
    xbt_dynar_foreach (categories, cursor, category){
      XBT_INFO ("%s", category);
    }
    xbt_dynar_free (&categories);
  }
Beispiel #15
0
void jedule_log_sd_event(SD_task_t task)
{
  jed_event_t event;

  xbt_assert(task != NULL);

  xbt_dynar_t host_list = xbt_dynar_new(sizeof(char*), NULL);

  for(int i=0; i<task->host_count; i++) {
    const char *hostname = sg_host_get_name(task->host_list[i]);
    xbt_dynar_push(host_list, &hostname);
  }

  create_jed_event(&event, (char*)SD_task_get_name(task), task->start_time, task->finish_time,"SD");

  jed_event_add_resources(event, host_list);
  jedule_store_event(event);

  xbt_dynar_free(&host_list);
}
Beispiel #16
0
static int master_main(int argc, char *argv[])
{
  xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
  msg_host_t pm0 = MSG_host_by_name("Fafard");
  msg_vm_t   vm0 = MSG_vm_create_core(pm0, "VM0");
  MSG_vm_start(vm0);

  launch_computation_worker(vm0);

  while(MSG_get_clock()<100) {
  if (atask != NULL)
    XBT_INFO("aTask remaining duration: %g", MSG_task_get_flops_amount(atask));
  MSG_process_sleep(1);
  }

  MSG_process_sleep(10000);
  MSG_vm_destroy(vm0);
  xbt_dynar_free(&hosts_dynar);
  return 1;
}
Beispiel #17
0
int main(int argc, char **argv)
{
  int res;
  xbt_dynar_t all_hosts;
  msg_host_t first_host;
  MSG_init(&argc, argv);
  MSG_create_environment(argv[1]);
  MSG_function_register("host", host);
  all_hosts = MSG_hosts_as_dynar();
  first_host = xbt_dynar_pop_as(all_hosts,msg_host_t);
  MSG_process_create( "host", host, NULL, first_host);
  xbt_dynar_free(&all_hosts);

  res = MSG_main();
  XBT_INFO("Simulation time %g", MSG_get_clock());

  if (res == MSG_OK)
    return 0;
  else
    return 1;
}
Beispiel #18
0
void xbt_multidict_remove(xbt_dict_t mdict, xbt_dynar_t keys)
{
  xbt_dynar_t lens = xbt_dynar_new(sizeof(unsigned long int), NULL);
  unsigned long i;

  for (i = 0; i < xbt_dynar_length(keys); i++) {
    char *thiskey = xbt_dynar_get_as(keys, i, char *);
    unsigned long int thislen = strlen(thiskey);
    xbt_dynar_push(lens, &thislen);
  }

  TRY {
    xbt_multidict_remove_ext(mdict, keys, lens);
  }
  TRY_CLEANUP {
    xbt_dynar_free(&lens);
  }
  CATCH_ANONYMOUS {
    RETHROW;
  }
}
Beispiel #19
0
int main(int argc, char **argv) {
  xbt_os_timer_t timer = xbt_os_timer_new();

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

  if (argc > 1) {
    SD_create_environment(argv[1]);
  } else {
    SD_create_environment("../../platforms/One_cluster_no_backbone.xml");
  }

  ws_list = SD_workstation_get_list();
  reclaimed = xbt_dynar_new(sizeof(bcast_task_t),xbt_free_ref);
  xbt_dynar_t done = NULL;

  xbt_os_cputimer_start(timer);
  send_one(0,SD_workstation_get_number());
  do {
    if (done != NULL && !xbt_dynar_is_empty(done)) {
      unsigned int cursor;
      SD_task_t task;

      xbt_dynar_foreach(done, cursor, task) {
        bcast_task_t bt = SD_task_get_data(task);

        if (bt->i != bt->j -1)
          send_one(bt->i,bt->j);
        if (bt->j != bt->k -1)
          send_one(bt->j,bt->k);

        if (xbt_dynar_length(reclaimed)<100) {
          xbt_dynar_push_as(reclaimed,bcast_task_t,bt);
        } else {
          free(bt);
        }
        SD_task_destroy(task);
      }
      xbt_dynar_free(&done);
    }
Beispiel #20
0
static int receiver(int argc, char *argv[])
{
  xbt_assert(argc==3, "This function expects 2 parameters from the XML deployment file");
  int id = xbt_str_parse_int(argv[1], "ID should be numerical, not %s");
  int task_amount = xbt_str_parse_int(argv[2], "Invalid amount of tasks: %s");
  msg_task_t *tasks = xbt_new(msg_task_t, task_amount);
  xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);

  char mailbox[80];
  snprintf(mailbox,79, "receiver-%d", id);
   
  MSG_process_sleep(10);
  for (int i = 0; i < task_amount; i++) {
    XBT_INFO("Wait to receive task %d", i);
    tasks[i] = NULL;
    msg_comm_t comm = MSG_task_irecv(&tasks[i], mailbox);
    xbt_dynar_push_as(comms, msg_comm_t, comm);
  }

  /* Here we are waiting for the receiving of all communications */
  while (!xbt_dynar_is_empty(comms)) {
    msg_comm_t comm;
    // MSG_comm_waitany returns the rank of the comm that just ended. Remove it.
    xbt_dynar_remove_at(comms, MSG_comm_waitany(comms), &comm);
    msg_task_t task = MSG_comm_get_task(comm);
    MSG_comm_destroy(comm);
    XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
    MSG_task_execute(task);
    XBT_INFO("\"%s\" done", MSG_task_get_name(task));
    msg_error_t err = MSG_task_destroy(task);
    xbt_assert(err == MSG_OK, "MSG_task_destroy failed");
  }
  xbt_dynar_free(&comms);
  xbt_free(tasks);

  /* Here we tell to sender that all tasks are done */
  MSG_task_send(MSG_task_create(NULL, 0, 0, NULL), "finalize");
  XBT_INFO("I'm done. See you!");
  return 0;
}
Beispiel #21
0
static int test_parmap_basic(e_xbt_parmap_mode_t mode)
{
  int ret = 0;
  unsigned num_workers;
  for (num_workers = 1 ; num_workers <= 16 ; num_workers *= 2) {
    const unsigned len = 1033;
    const unsigned num = 5;
    unsigned *a;
    xbt_dynar_t data;
    xbt_parmap_t parmap;
    unsigned i;

    parmap = xbt_parmap_new(num_workers, mode);

    a = xbt_malloc(len * sizeof *a);
    data = xbt_dynar_new(sizeof a, NULL);
    for (i = 0; i < len; i++) {
      a[i] = i;
      xbt_dynar_push_as(data, void *, &a[i]);
    }

    for (i = 0; i < num; i++)
      xbt_parmap_apply(parmap, fun_double, data);

    for (i = 0; i < len; i++) {
      unsigned expected = (1U << num) * (i + 1) - 1;
      if (a[i] != expected) {
        XBT_CRITICAL("with %u threads, a[%u]: expected %u, got %u",
                     num_workers, i, expected, a[i]);
        ret = 1;
        break;
      }
    }

    xbt_dynar_free(&data);
    xbt_free(a);
    xbt_parmap_destroy(parmap);
  }
  return ret;
}
Beispiel #22
0
int main(int argc, char **argv)
{
  double time;
  SD_task_t task;
  xbt_dynar_t ret;

  double communication_amount[] = { 0.0, 1.0, 2.0, 3.0,
    0.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 0.0, 0.0,
  };

  double no_cost[] = { 0.0, 0.0, 0.0, 0.0 };


  /***************************************/

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

  task = SD_task_create("Scatter task", NULL, 1.0);

  SD_task_schedule(task, 4, SD_workstation_get_list(), no_cost,
                   communication_amount, -1.0);

  ret = SD_simulate(-1.0);
  xbt_dynar_free(&ret);

  time = SD_get_clock();

  printf("%g\n", time);
  fflush(stdout);

  SD_task_destroy(task);

  SD_exit();

  return 0;
}
Beispiel #23
0
JNIEXPORT jobjectArray JNICALL
Java_org_simgrid_msg_Storage_all(JNIEnv * env, jclass cls_arg)
{
  int index;
  jobjectArray jtable;
  jobject jstorage;
  jstring jname;
  msg_storage_t storage;

  xbt_dynar_t table =  MSG_storages_as_dynar();
  int count = xbt_dynar_length(table);

  jclass cls = jxbt_get_class(env, "org/simgrid/msg/Storage");

  if (!cls) {
    return NULL;
  }

  jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL);

  if (!jtable) {
    jxbt_throw_jni(env, "Storages table allocation failed");
    return NULL;
  }

  for (index = 0; index < count; index++) {
    storage = xbt_dynar_get_as(table,index,msg_storage_t);
    jstorage = (jobject) (xbt_lib_get_level(storage, JAVA_STORAGE_LEVEL));

    if (!jstorage) {
      jname = (*env)->NewStringUTF(env, MSG_storage_get_name(storage));
      jstorage = Java_org_simgrid_msg_Storage_getByName(env, cls_arg, jname);
    }

    (*env)->SetObjectArrayElement(env, jtable, index, jstorage);
  }
  xbt_dynar_free(&table);
  return jtable;
}
Beispiel #24
0
void Container::createHierarchy(NetZone_t from_as)
{
  xbt_dict_cursor_t cursor = nullptr;
  char *key;
  NetZone_t elem;
  xbt_dict_t routing_sons = from_as->children();

  if (xbt_dict_is_empty(routing_sons)) {
    // I am no AS
    // add hosts to jedule platform
    xbt_dynar_t table = from_as->hosts();
    unsigned int dynar_cursor;
    sg_host_t host;

    std::vector<sg_host_t> hosts;

    xbt_dynar_foreach(table, dynar_cursor, host) {
      hosts.push_back(host);
    }
    this->addResources(hosts);
    xbt_dynar_free(&table);
  } else {
Beispiel #25
0
static int test_parmap_extended(e_xbt_parmap_mode_t mode)
{
  int ret = 0;
  unsigned num_workers;

  for (num_workers = 1 ; num_workers <= 16 ; num_workers *= 2) {
    const unsigned len = 2 * num_workers;
    uintptr_t *a;
    xbt_parmap_t parmap;
    xbt_dynar_t data;
    unsigned i;
    unsigned count;

    parmap = xbt_parmap_new(num_workers, mode);

    a = xbt_malloc(len * sizeof *a);
    data = xbt_dynar_new(sizeof a, NULL);
    for (i = 0; i < len; i++)
      xbt_dynar_push_as(data, void *, &a[i]);

    xbt_parmap_apply(parmap, fun_get_id, data);

    qsort(a, len, sizeof a[0], fun_compare);
    count = 1;
    for (i = 1; i < len; i++)
      if (a[i] != a[i - 1])
        count++;
    if (count != num_workers) {
      XBT_CRITICAL("only %u/%u threads did some work", count, num_workers);
      ret = 1;
    }

    xbt_dynar_free(&data);
    xbt_free(a);
    xbt_parmap_destroy(parmap);
  }
  return ret;
}
Beispiel #26
0
int main(int argc, char **argv)
{
  int res;
  MSG_init(&argc, argv);
  MSG_create_environment(argv[1]);
  xbt_dynar_t hosts =  MSG_hosts_as_dynar();
  MSG_function_register("host", host);
  unsigned long nb_hosts = xbt_dynar_length(hosts);
  XBT_INFO("Number of host '%lu'",nb_hosts);
  char* name_host = xbt_strdup("0");
  MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,0,msg_host_t) );
  free(name_host);

  xbt_dynar_free(&hosts);

  res = MSG_main();
  XBT_INFO("Simulation time %g", MSG_get_clock());
  if (res == MSG_OK)
    return 0;
  else
    return 1;

}
Beispiel #27
0
int main(int argc, char *argv[])
{
  MSG_init(&argc, argv);
  MSG_config("host/model", "ptask_L07");

  xbt_assert(argc <= 3, "1Usage: %s <platform file> [--energy]", argv[0]);
  xbt_assert(argc >= 2, "2Usage: %s <platform file> [--energy]", argv[0]);

  if(argc == 3 && argv[2][2] == 'e')
    sg_energy_plugin_init();

  MSG_create_environment(argv[1]);

  /* Pick a process, no matter which, from the platform file */
  xbt_dynar_t all_hosts = MSG_hosts_as_dynar();
  msg_host_t first_host = xbt_dynar_getfirst_as(all_hosts,msg_host_t);
  xbt_dynar_free(&all_hosts);

  MSG_process_create("test", runner, NULL, first_host);
  msg_error_t res = MSG_main();
  XBT_INFO("Simulation done.");

  return res != MSG_OK;
}
Beispiel #28
0
/** \brief Insert \e data under all the keys contained in \e keys
 *
 * \arg head: the head of dict
 * \arg keys: dynar of null-terminated strings containing all the keys
 * \arg data: what to store in the structure
 * \arg free_ctn: function to use to free the pushed content on need
 */
void
xbt_multidict_set(xbt_dict_t mdict,
                  xbt_dynar_t keys, void *data, void_f_pvoid_t free_ctn)
{
  xbt_dynar_t lens = xbt_dynar_new(sizeof(unsigned long int), NULL);
  unsigned long i;

  for (i = 0; i < xbt_dynar_length(keys); i++) {
    char *thiskey = xbt_dynar_get_as(keys, i, char *);
    unsigned long int thislen = (unsigned long int) strlen(thiskey);
    XBT_DEBUG("Push %ld as level %lu length", thislen, i);
    xbt_dynar_push(lens, &thislen);
  }

  TRY {
    xbt_multidict_set_ext(mdict, keys, lens, data, free_ctn);
  }
  TRY_CLEANUP {
    xbt_dynar_free(&lens);
  }
  CATCH_ANONYMOUS {
    RETHROW;
  }
}
Beispiel #29
0
static inline void routing_storage_host_free(void *r)
{
  xbt_dynar_t dyn = (xbt_dynar_t) r;
  xbt_dynar_free(&dyn);
}
Beispiel #30
0
int main(int argc, char **argv)
{
  int i;
  const char *platform_file;
  const SD_workstation_t *workstations;
  SD_task_t taskA, taskB, taskC, taskD;
  xbt_dynar_t changed_tasks;

  /* 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);

  /* Change the access mode of the workstations */
  workstations = SD_workstation_get_list();
  for (i = 0; i < 2; i++) {
    SD_workstation_dump(workstations[i]);
    
    SD_workstation_set_access_mode(workstations[i],
                                   SD_WORKSTATION_SEQUENTIAL_ACCESS);
    XBT_INFO(" Change access mode of %s to %s",
          SD_workstation_get_name(workstations[i]),
          (SD_workstation_get_access_mode(workstations[i]) ==
           SD_WORKSTATION_SEQUENTIAL_ACCESS) ? "sequential" : "shared");
  }
  /* Well I changed my mind, I want the second workstation to be shared */

  SD_workstation_set_access_mode(workstations[1],
                                     SD_WORKSTATION_SHARED_ACCESS);
  XBT_INFO(" Change access mode of %s to %s",
           SD_workstation_get_name(workstations[1]),
           (SD_workstation_get_access_mode(workstations[1]) ==
           SD_WORKSTATION_SEQUENTIAL_ACCESS) ? "sequential" : "shared");

  /* creation of the tasks and their dependencies */
  taskA = SD_task_create_comp_seq("Task A", NULL, 2e10);
  taskB = SD_task_create_comm_e2e("Task B", NULL, 2e8);
  taskC = SD_task_create_comp_seq("Task C", NULL, 1e10);
  taskD = SD_task_create_comp_seq("Task D", NULL, 1e11);

  SD_task_dependency_add("B->C", NULL,taskB, taskC);

  /* watch points */
  SD_task_watch(taskA, SD_RUNNING);
  SD_task_watch(taskB, SD_RUNNING);
  SD_task_watch(taskC, SD_RUNNING);
  SD_task_watch(taskC, SD_DONE);
  SD_task_watch(taskD, SD_DONE);


  /* scheduling parameters */
  SD_task_schedulel(taskA, 1, workstations[0]);
  SD_task_schedulel(taskB, 2, workstations[0], workstations[1]);
  SD_task_schedulel(taskC, 1, workstations[1]);
  SD_task_schedulel(taskD, 1, workstations[1]);

  /* let's launch the simulation! */
  while (!xbt_dynar_is_empty(changed_tasks = SD_simulate(-1.0))) {
    XBT_INFO(" Simulation was suspended, check workstation states"); 
    for (i = 0; i < 2; i++) {
      SD_workstation_dump(workstations[i]);
    }
    xbt_dynar_free(&changed_tasks);
  }
  xbt_dynar_free(&changed_tasks);

  XBT_DEBUG("Destroying tasks...");

  SD_task_destroy(taskA);
  SD_task_destroy(taskB);
  SD_task_destroy(taskC);
  SD_task_destroy(taskD);

  XBT_DEBUG("Tasks destroyed. Exiting SimDag...");

  SD_exit();
  return 0;
}