Beispiel #1
0
static void linkContainers (container_t src, container_t dst, xbt_dict_t filter)
{
  //ignore loopback
  if (strcmp (src->name, "__loopback__") == 0 || strcmp (dst->name, "__loopback__") == 0){
    XBT_DEBUG ("  linkContainers: ignoring loopback link");
    return;
  }

  //find common father
  container_t father = lowestCommonAncestor (src, dst);
  if (!father){
    xbt_die ("common father unknown, this is a tracing problem");
  }

  if (filter != NULL){
    //check if we already register this pair (we only need one direction)
    char aux1[INSTR_DEFAULT_STR_SIZE], aux2[INSTR_DEFAULT_STR_SIZE];
    snprintf (aux1, INSTR_DEFAULT_STR_SIZE, "%s%s", src->name, dst->name);
    snprintf (aux2, INSTR_DEFAULT_STR_SIZE, "%s%s", dst->name, src->name);
    if (xbt_dict_get_or_null (filter, aux1)){
      XBT_DEBUG ("  linkContainers: already registered %s <-> %s (1)", src->name, dst->name);
      return;
    }
    if (xbt_dict_get_or_null (filter, aux2)){
      XBT_DEBUG ("  linkContainers: already registered %s <-> %s (2)", dst->name, src->name);
      return;
    }

    //ok, not found, register it
    xbt_dict_set (filter, aux1, xbt_strdup ("1"), NULL);
    xbt_dict_set (filter, aux2, xbt_strdup ("1"), NULL);
  }

  //declare type
  char link_typename[INSTR_DEFAULT_STR_SIZE];
  snprintf (link_typename, INSTR_DEFAULT_STR_SIZE, "%s-%s%s-%s%s",
            father->type->name,
            src->type->name, src->type->id,
            dst->type->name, dst->type->id);
  type_t link_type = PJ_type_get_or_null (link_typename, father->type);
  if (link_type == NULL){
    link_type = PJ_type_link_new (link_typename, father->type, src->type, dst->type);
  }

  //register EDGE types for triva configuration
  xbt_dict_set (trivaEdgeTypes, link_type->name, xbt_strdup("1"), NULL);

  //create the link
  static long long counter = 0;

  char key[INSTR_DEFAULT_STR_SIZE];
  snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
  new_pajeStartLink(SIMIX_get_clock(), father, link_type, src, "topology", key);
  new_pajeEndLink(SIMIX_get_clock(), father, link_type, dst, "topology", key);

  XBT_DEBUG ("  linkContainers %s <-> %s", src->name, dst->name);
}
Beispiel #2
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 #3
0
void NetworkSmpiModel::gapAppend(double size, Link* link, NetworkAction *act)
{
    const char *src = link->getName();
    xbt_fifo_t fifo;
    NetworkCm02Action *action= static_cast<NetworkCm02Action*>(act);

    if (sg_sender_gap > 0.0) {
        if (!gap_lookup) {
            gap_lookup = xbt_dict_new_homogeneous(nullptr);
        }
        fifo = (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, src);
        action->senderGap_ = 0.0;
        if (fifo && xbt_fifo_size(fifo) > 0) {
            /* Compute gap from last send */
            /*last_action =
            (surf_action_network_CM02_t)
            xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));*/
            // bw = net_get_link_bandwidth(link);
            action->senderGap_ = sg_sender_gap;
            /*  max(sg_sender_gap,last_action->sender.size / bw);*/
            action->latency_ += action->senderGap_;
        }
        /* Append action as last send */
        /*action->sender.link_name = link->lmm_resource.generic_resource.name;
        fifo =
        (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
                                          action->sender.link_name);
        if (!fifo) {
        fifo = xbt_fifo_new();
        xbt_dict_set(gap_lookup, action->sender.link_name, fifo, nullptr);
        }
        action->sender.fifo_item = xbt_fifo_push(fifo, action);*/
        action->senderSize_ = size;
    }
}
Beispiel #4
0
FILE *
config_get_log_file(const char *hostname)
{
    FILE *floc = (FILE *)xbt_dict_get_or_null(book_of_log, hostname);
    
    return (floc)? floc: stderr;
}
Beispiel #5
0
int smpi_sample_2(int global, const char *file, int line)
{
  char *loc = sample_location(global, file, line);
  local_data_t *data;

  xbt_assert(samples, "You did something very inconsistent, didn't you?");
  data = xbt_dict_get_or_null(samples, loc);
  if (!data) {
    xbt_assert(data, "Please, do thing in order");
  }
  if (!data->started) {
    if ((data->iters > 0 && data->count >= data->iters)
        || (data->count > 1 && data->threshold > 0.0 && data->relstderr <= data->threshold)) {
      XBT_DEBUG("Perform some wait of %f", data->mean);
      smpi_execute(data->mean);
    } else {
      data->started = 1;
      data->count++;
    }
  } else {
    data->started = 0;
  }
  free(loc);
  smpi_bench_begin();
  smpi_process_simulated_start();
  return data->started;
}
//used by all methods
static void __TRACE_surf_check_variable_set_to_zero(double now,
                                                    const char *variable,
                                                    const char *resource)
{
  /*
   * To trace resource utilization, we use pajeAddVariable and pajeSubVariable only.
   * The Paje simulator needs a pajeSetVariable in the first place so it knows
   * the initial value of all variables for subsequent adds/subs. If we don't do
   * so, the first pajeAddVariable is added to a non-determined value within
   * the Paje simulator, causing analysis problems.
   */

  // create a key considering the resource and variable
  int n = strlen(variable)+strlen(resource)+1;
  char *key = (char*)xbt_malloc(n*sizeof(char));
  snprintf (key, n, "%s%s", resource, variable);

  // check if key exists: if it doesn't, set the variable to zero and mark this in the dict
  if (!xbt_dict_get_or_null(platform_variables, key)) {
    container_t container = PJ_container_get (resource);
    type_t type = PJ_type_get (variable, container->type);
    new_pajeSetVariable (now, container, type, 0);
    xbt_dict_set(platform_variables, key, (char*)"", NULL);
  }
  xbt_free(key);
}
Beispiel #7
0
const char *MSG_environment_as_get_property_value(msg_as_t as, const char *name)
{
  xbt_dict_t dict = xbt_lib_get_or_null(as_router_lib, MSG_environment_as_get_name(as), ROUTING_PROP_ASR_LEVEL);
  if (dict==NULL)
    return NULL;
  return xbt_dict_get_or_null(dict, name);
}
Beispiel #8
0
StorageAction *StorageN11::open(const char* mount, const char* path)
{
  XBT_DEBUG("\tOpen file '%s'",path);

  sg_size_t size, *psize;
  psize = (sg_size_t*) xbt_dict_get_or_null(content_, path);
  // if file does not exist create an empty file
  if(psize)
    size = *psize;
  else {
    psize = xbt_new(sg_size_t,1);
    size = 0;
    *psize = size;
    xbt_dict_set(content_, path, psize, nullptr);
    XBT_DEBUG("File '%s' was not found, file created.",path);
  }
  surf_file_t file = xbt_new0(s_surf_file_t,1);
  file->name = xbt_strdup(path);
  file->size = size;
  file->mount = xbt_strdup(mount);
  file->current_position = 0;

  StorageAction *action = new StorageN11Action(getModel(), 0, isOff(), this, OPEN);
  action->p_file = file;

  return action;
}
Beispiel #9
0
void smpi_shared_free(void *ptr)
{
  char loc[PTR_STRLEN];
  shared_metadata_t* meta;
  shared_data_t* data;

  if (!allocs) {
    XBT_WARN("Cannot free: nothing was allocated");
    return;
  }
  if(!allocs_metadata) {
    XBT_WARN("Cannot free: no metadata was allocated");
  }
  snprintf(loc, PTR_STRLEN, "%p", ptr);
  meta = (shared_metadata_t*)xbt_dict_get_or_null(allocs_metadata, loc);
  if (!meta) {
    XBT_WARN("Cannot free: %p was not shared-allocated by SMPI", ptr);
    return;
  }
  data = meta->data;
  if(!data) {
    XBT_WARN("Cannot free: something is broken in the metadata link");
    return;
  }
  if(munmap(ptr, meta->size) < 0) {
    XBT_WARN("Unmapping of fd %d failed: %s", data->fd, strerror(errno));
  }
  data->count--;
  if (data->count <= 0) {
    close(data->fd);
    xbt_dict_remove(allocs, data->loc);
    free(data->loc);
  }
}
Beispiel #10
0
 xbt_dict_foreach(trace_connect_list_link_lat, cursor, trace_name, elm) {
   tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
   xbt_assert(trace, "Trace %s undefined", trace_name);
   Link *link = Link::byName(elm);
   xbt_assert(link, "Link %s undefined", elm);
   link->setLatencyTrace(trace);
 }
Beispiel #11
0
void print_TIDestroyContainer(paje_event_t event)
{
  if (!xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file")|| xbt_dict_length(tracing_files) == 1) {
    FILE* f = (FILE*)xbt_dict_get_or_null(tracing_files, ((destroyContainer_t) event->data)->container->name);
    fclose(f);
  }
  xbt_dict_remove(tracing_files, ((destroyContainer_t) event->data)->container->name);
}
Beispiel #12
0
const char *MSG_environment_as_get_property_value(msg_as_t as, const char *name)
{
  xbt_dict_t dict = static_cast<xbt_dict_t> (xbt_lib_get_or_null(as_router_lib, MSG_environment_as_get_name(as),
                                                                 ROUTING_PROP_ASR_LEVEL));
  if (dict==nullptr)
    return nullptr;
  return static_cast<const char*>(xbt_dict_get_or_null(dict, name));
}
Beispiel #13
0
const char *TRACE_internal_smpi_get_category (void)
{
  if (!TRACE_smpi_is_enabled()) return NULL;

  char processid[INSTR_DEFAULT_STR_SIZE];
  snprintf (processid, INSTR_DEFAULT_STR_SIZE, "%p", SIMIX_process_self());
  return xbt_dict_get_or_null (process_category, processid);
}
Beispiel #14
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 #15
0
static void store_in_dict(xbt_dict_t dict, const char *key, double value)
{
  double *ir;

  ir = xbt_dict_get_or_null(dict, key);
  if (!ir) {
    ir = xbt_new0(double, 1);
    xbt_dict_set(dict, key, ir, xbt_free_f);
  }
Beispiel #16
0
  xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
    CpuCas01Ptr host = static_cast<CpuCas01Ptr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));

    xbt_assert(host, "Host %s undefined", elm);
    xbt_assert(trace, "Trace %s undefined", trace_name);

    host->setPowerEvent(tmgr_history_add_trace(history, trace, 0.0, 0, host));
  }
xbt_node_t new_xbt_graph_node(xbt_graph_t graph, const char *name, xbt_dict_t nodes)
{
  xbt_node_t ret = (xbt_node_t) xbt_dict_get_or_null(nodes, name);
  if (ret)
    return ret;

  ret = xbt_graph_new_node(graph, xbt_strdup(name));
  xbt_dict_set(nodes, name, ret, nullptr);
  return ret;
}
Beispiel #18
0
  xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
    tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
    cpu_Cas01_t host = surf_cpu_resource_by_name(elm);

    xbt_assert(host, "Host %s undefined", elm);
    xbt_assert(trace, "Trace %s undefined", trace_name);

    host->power_event =
        tmgr_history_add_trace(history, trace, 0.0, 0, host);
  }
Beispiel #19
0
smx_mailbox_t SIMIX_mbox_create(const char *name)
{
  xbt_assert(name, "Mailboxes must have a name");
  /* two processes may have pushed the same mbox_create simcall at the same time */
  smx_mailbox_t mbox = static_cast<smx_mailbox_t>(xbt_dict_get_or_null(mailboxes, name));
  if (!mbox) {
    mbox = new simgrid::simix::Mailbox(name);
    XBT_DEBUG("Creating a mailbox at %p with name %s", mbox, name);
    xbt_dict_set(mailboxes, mbox->name, mbox, nullptr);
  }
  return mbox;
}
Beispiel #20
0
static void IB_action_init_callback(NetworkActionPtr action,RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate){
  if(((NetworkIBModel*)surf_network_model)->active_nodes==NULL)
    xbt_die("IB comm added, without any node connected !");
  
  IBNode* act_src= (IBNode*) xbt_dict_get_or_null(((NetworkIBModel*)surf_network_model)->active_nodes, src->getName());
  if(act_src==NULL)
    xbt_die("could not find src node active comms !");
  //act_src->rate=rate;
  
  IBNode* act_dst= (IBNode*) xbt_dict_get_or_null(((NetworkIBModel*)surf_network_model)->active_nodes, dst->getName());
  if(act_dst==NULL)
    xbt_die("could not find dst node active comms !");  
 // act_dst->rate=rate;
  
  ((NetworkIBModel*)surf_network_model)->active_comms[action]=make_pair<IBNode*,IBNode*>(act_src, act_dst);
  //post the action in the second dist, to retrieve in the other callback
  XBT_DEBUG("IB callback - action %p init", action);

  ((NetworkIBModel*)surf_network_model)->updateIBfactors(action, act_src, act_dst, 0);
  
}
Beispiel #21
0
tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input,
                                        double periodicity)
{
  tmgr_trace_t trace = NULL;
  int linecount = 0;
  s_tmgr_event_t event;
  tmgr_event_t last_event = NULL;
  xbt_dynar_t list;
  unsigned int cpt;
  char *val;

  if (trace_list) {
    trace = xbt_dict_get_or_null(trace_list, id);
    if (trace) {
      XBT_WARN("Ignoring redefinition of trace %s", id);
      return trace;
    }
  }

  xbt_assert(periodicity >= 0,
              "Invalid periodicity %lg (must be positive)", periodicity);

  trace = xbt_new0(s_tmgr_trace_t, 1);
  trace->type = e_trace_list;
  trace->s_list.event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);

  list = xbt_str_split(input, "\n\r");

  xbt_dynar_foreach(list, cpt, val) {
    linecount++;
    xbt_str_trim(val, " \t\n\r\x0B");
    if (val[0] == '#' || val[0] == '\0' || val[0] == '%')
      continue;

    if (sscanf(val, "PERIODICITY " "%lg" "\n", &periodicity) == 1)
      continue;

    if (sscanf(val, "%lg" " " "%lg" "\n", &event.delta, &event.value) != 2)
      xbt_die("%s:%d: Syntax error in trace\n%s", id, linecount, input);

    if (last_event) {
      if (last_event->delta > event.delta) {
        xbt_die("%s:%d: Invalid trace: Events must be sorted, "
                "but time %lg > time %lg.\n%s",
                id, linecount, last_event->delta, event.delta, input);
      }
      last_event->delta = event.delta - last_event->delta;
    }
    xbt_dynar_push(trace->s_list.event_list, &event);
    last_event =
        xbt_dynar_get_ptr(trace->s_list.event_list,
                          xbt_dynar_length(trace->s_list.event_list) - 1);
  }
Beispiel #22
0
static char *TRACE_smpi_get_key(int src, int dst, char *key, int n)
{
  char aux[INSTR_DEFAULT_STR_SIZE];
  snprintf(aux, INSTR_DEFAULT_STR_SIZE, "%d#%d", src, dst);
  xbt_dynar_t d = xbt_dict_get_or_null(keys, aux);

  xbt_assert(!xbt_dynar_is_empty(d),
      "Trying to get a link key (for message reception) that has no corresponding send (%s).", __FUNCTION__);
  char *s = xbt_dynar_get_as (d, 0, char *);
  snprintf (key, n, "%s", s);
  xbt_dynar_remove_at (d, 0, NULL);
  return key;
}
xbt_edge_t new_xbt_graph_edge(xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt_dict_t edges)
{
  const char *sn = instr_node_name(s);
  const char *dn = instr_node_name(d);
  int len = strlen(sn) + strlen(dn) + 1;
  char *name = (char *) xbt_malloc(len * sizeof(char));


  snprintf(name, len, "%s%s", sn, dn);
  xbt_edge_t ret = (xbt_edge_t) xbt_dict_get_or_null(edges, name);
  if (ret == nullptr) {
    snprintf(name, len, "%s%s", dn, sn);
    ret = (xbt_edge_t) xbt_dict_get_or_null(edges, name);
  }

  if (ret == nullptr) {
    ret = xbt_graph_new_edge(graph, s, d, nullptr);
    xbt_dict_set(edges, name, ret, nullptr);
  }
  free(name);
  return ret;
}
Beispiel #24
0
void
config_init_log_file(void)
{
    xmlXPathObjectPtr xmlobject = NULL;
    const char *r = "/config/batch";
    
#ifdef VERBOSE
    fprintf(stderr, "Init log files : \n");
#endif
    xmlobject = config_get(r);
    if (!xmlobject) {
#ifdef VERBOSE
        fprintf(stderr, "failed\n");
        fprintf(stderr, "XPathError : %s\n", r);
#endif
        free(config);
        exit(2);
    }
    
    if (xmlobject->type == XPATH_NODESET)
        if (xmlobject->nodesetval) {
            int i = 0;
#ifdef VERBOSE
            fprintf(stderr, "\tnb log file : %d\n",
                    xmlobject->nodesetval->nodeNr);
#endif
            for (i=0; i<xmlobject->nodesetval->nodeNr; ++i) {
                char *logfile = NULL;
                FILE *flog = NULL;
                xmlChar *batchName; 
                
                batchName = xmlGetProp(xmlobject->nodesetval->nodeTab[i], 
                                       BAD_CAST("host"));
		
                logfile = calloc(xmlStrlen(batchName) + 5, sizeof(char));
                sprintf(logfile, "%s.log", batchName);
                flog = (FILE *)xbt_dict_get_or_null(book_of_log, 
                                                    (char *)batchName);
                if (!flog) {
                    flog = fopen(logfile, "w");
                    xbt_dict_set(book_of_log, (char *)batchName, flog, 
                                 close_log_file);
#ifdef VERBOSE
                    fprintf(stderr, "\tlog file : %s\n", logfile);
#endif
                    free(logfile);
                }
            }
        }
}
Beispiel #25
0
void TRACE_internal_smpi_set_category (const char *category)
{
  if (!TRACE_smpi_is_enabled()) return;

  //declare category
  TRACE_category (category);

  char processid[INSTR_DEFAULT_STR_SIZE];
  snprintf (processid, INSTR_DEFAULT_STR_SIZE, "%p", SIMIX_process_self());
  if (xbt_dict_get_or_null (process_category, processid))
    xbt_dict_remove (process_category, processid);
  if (category != NULL)
    xbt_dict_set (process_category, processid, xbt_strdup(category), NULL);
}
val_t PJ_value_get (const char *name, type_t father)
{
  if (name == NULL || father == NULL){
    THROWF (tracing_error, 0, "can't get a value with a NULL name (or a NULL father)");
  }

  if (father->kind == TYPE_VARIABLE)
    THROWF(tracing_error, 0,
           "variables can't have different values (%s)", father->name);
  val_t ret = (val_t)xbt_dict_get_or_null (father->values, name);
  if (ret == NULL) {
    THROWF(tracing_error, 2,
           "value with name (%s) not found in father type (%s)",
           name, father->name);
  }
  return ret;
}
Beispiel #27
0
void *smpi_shared_malloc(size_t size, const char *file, int line)
{
  char *loc = bprintf("%zu_%s_%d", (size_t)getpid(), file, line);
  size_t len = strlen(loc);
  size_t i;
  int fd;
  void* mem;
  shared_data_t *data;

  for(i = 0; i < len; i++) {
    /* Make the 'loc' ID be a flat filename */
    if(loc[i] == '/') {
      loc[i] = '_';
    }
  }
  if (!allocs) {
    allocs = xbt_dict_new_homogeneous(free);
  }
  data = xbt_dict_get_or_null(allocs, loc);
  if(!data) {
    fd = shm_open(loc, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    if(fd < 0) {
      switch(errno) {
        case EEXIST:
          xbt_die("Please cleanup /dev/shm/%s", loc);
        default:
          xbt_die("An unhandled error occured while opening %s: %s", loc, strerror(errno));
      }
    }
    data = xbt_new(shared_data_t, 1);
    data->fd = fd;
    data->count = 1;
    data->loc = loc;
    mem = shm_map(fd, size, data);
    if(shm_unlink(loc) < 0) {
      XBT_WARN("Could not early unlink %s: %s", loc, strerror(errno));
    }
    xbt_dict_set(allocs, loc, data, NULL);
    XBT_DEBUG("Mapping %s at %p through %d", loc, mem, fd);
  } else {
    mem = shm_map(data->fd, size, data);
    data->count++;
  }
  XBT_DEBUG("Malloc %zu in %p (metadata at %p)", size, mem, data);
  return mem;
}
Beispiel #28
0
void CpuCas01Model::addTraces()
{
  xbt_dict_cursor_t cursor = NULL;
  char *trace_name, *elm;
  static int called = 0;
  if (called)
    return;
  called = 1;

  /* connect all traces relative to hosts */
  xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
    CpuCas01Ptr host = static_cast<CpuCas01Ptr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));

    xbt_assert(host, "Host %s undefined", elm);
    xbt_assert(trace, "Trace %s undefined", trace_name);

    host->setStateEvent(tmgr_history_add_trace(history, trace, 0.0, 0, host));
  }
Beispiel #29
0
void *smpi_shared_malloc(size_t size, const char *file, int line)
{
  char *loc = bprintf("%s:%d:%zu", file, line, size);
  shared_data_t *data;

  if (!allocs) {
    allocs = xbt_dict_new();
  }
  data = xbt_dict_get_or_null(allocs, loc);
  if (!data) {
    data = (shared_data_t *) xbt_malloc0(sizeof(int) + size);
    data->count = 1;
    xbt_dict_set(allocs, loc, data, &free);
  } else {
    data->count++;
  }
  free(loc);
  return data->data;
}
Beispiel #30
0
static void cpu_add_traces_cpu(void)
{
  xbt_dict_cursor_t cursor = NULL;
  char *trace_name, *elm;
  static int called = 0;
  if (called)
    return;
  called = 1;

  /* connect all traces relative to hosts */
  xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
    tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
    cpu_Cas01_t host = surf_cpu_resource_by_name(elm);

    xbt_assert(host, "Host %s undefined", elm);
    xbt_assert(trace, "Trace %s undefined", trace_name);

    host->state_event =
        tmgr_history_add_trace(history, trace, 0.0, 0, host);
  }