当前位置: 首页>>代码示例>>C++>>正文


C++ xbt_dynar_length函数代码示例

本文整理汇总了C++中xbt_dynar_length函数的典型用法代码示例。如果您正苦于以下问题:C++ xbt_dynar_length函数的具体用法?C++ xbt_dynar_length怎么用?C++ xbt_dynar_length使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xbt_dynar_length函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Java_org_simgrid_msg_Msg_run

JNIEXPORT void JNICALL JNICALL Java_org_simgrid_msg_Msg_run(JNIEnv * env, jclass cls)
{
  /* Run everything */
  XBT_DEBUG("Ready to run MSG_MAIN");
  msg_error_t rv = MSG_main();
  XBT_DEBUG("Done running MSG_MAIN");
  jxbt_check_res("MSG_main()", rv, MSG_OK,
                 xbt_strdup("unexpected error : MSG_main() failed .. please report this bug "));

  XBT_INFO("MSG_main finished; Cleaning up the simulation...");
  /* Cleanup java hosts */
  xbt_dynar_t hosts = MSG_hosts_as_dynar();
  for (unsigned long index = 0; index < xbt_dynar_length(hosts) - 1; index++) {
    msg_host_t msg_host = xbt_dynar_get_as(hosts,index,msg_host_t);
    jobject jhost = (jobject) msg_host->extension(JAVA_HOST_LEVEL);
    if (jhost)
      jhost_unref(env, jhost);

  }
  xbt_dynar_free(&hosts);

  /* Cleanup java storages */
  xbt_dynar_t storages = MSG_storages_as_dynar();
  if(!xbt_dynar_is_empty(storages)){
    for (unsigned long index = 0; index < xbt_dynar_length(storages) - 1; index++) {
      jobject jstorage = (jobject) xbt_lib_get_level(xbt_dynar_get_as(storages,index,msg_storage_t), JAVA_STORAGE_LEVEL);
      if (jstorage)
        jstorage_unref(env, jstorage);
    }
  }
  xbt_dynar_free(&storages);
}
开发者ID:oar-team,项目名称:simgrid-batsim,代码行数:32,代码来源:jmsg.cpp

示例2: xbt_dynar_length

/** \brief Insert \e data under all the keys contained in \e keys, providing their sizes in \e lens.
 *
 * \arg mdict: the multi-dict
 * \arg keys: dynar of (char *) containing all the keys
 * \arg lens: length of each element of \e keys
 * \arg data: where to put what was found in structure
 * \arg free_ctn: function to use to free the pushed content on need
 *
 * Dynars are not modified during the operation.
 */
void *xbt_multidict_get_ext(xbt_dict_t mdict,
                            xbt_dynar_t keys, xbt_dynar_t lens)
{
  xbt_dict_t thislevel, nextlevel;
  int i;

  unsigned long int thislen;
  char *thiskey;
  int keys_len = xbt_dynar_length(keys);

  xbt_assert(xbt_dynar_length(keys) == xbt_dynar_length(lens));
  xbt_assert(!xbt_dynar_is_empty(keys),
              "Can't get a zero-long key set in a multidict");

  XBT_DEBUG("xbt_multidict_get(%p, %ld)", mdict, xbt_dynar_length(keys));

  for (i = 0, thislevel = mdict; i < keys_len - 1;
       i++, thislevel = nextlevel) {

    xbt_dynar_get_cpy(keys, i, &thiskey);
    xbt_dynar_get_cpy(lens, i, &thislen);

    XBT_DEBUG("multi_get: at level %d (%p), len=%ld, key=%p |%*s|",
           i, thislevel, thislen, thiskey, (int) thislen, thiskey);

    /* search the dict of next level: let mismatch raise if not found */
    nextlevel = xbt_dict_get_ext(thislevel, thiskey, thislen);
  }

  xbt_dynar_get_cpy(keys, i, &thiskey);
  xbt_dynar_get_cpy(lens, i, &thislen);

  return xbt_dict_get_ext(thislevel, thiskey, thislen);
}
开发者ID:Shurakai,项目名称:SimGrid,代码行数:44,代码来源:dict_multi.c

示例3: find_active_VMs_to_stop

/* Build the set of hosts/VMs that have to be terminated. This function selects how_many VMs from the source set of
 * candidates.
 * Remark: In the paper by Malawski et al., no details are provided about how the VMs are selected in the source set.
 * Moreover, there is no check w.r.t. the size of the source set.
 * Assumptions:
 * 1) If the source set is too small, display a warning and return a smaller set than expected.
 * 2) Straightforward selection of the VMs in the set. Just pick the how_many first ones without any consideration of
 *    the time remaining until the next hourly billing cycle. Just check if the VM is not currently executing a task
 */
xbt_dynar_t find_active_VMs_to_stop(int how_many, xbt_dynar_t source){
  int i, found;
  long unsigned int source_size = xbt_dynar_length(source);
  xbt_dynar_t to_stop = xbt_dynar_new(sizeof(sg_host_t), NULL);
  sg_host_t v;

  if (how_many > source_size){
    XBT_WARN("Trying to terminate more VMs than what is available (%d > %lu)."
        " Change the number of VMs to terminate to %lu", how_many, source_size, source_size);
    how_many = source_size;
  }

  i = 0;
  found = 0;

  while(found < how_many && i < xbt_dynar_length(source)){
    /* No advanced selection process. Just pick the how_many first idle VMs in the source set. */
    xbt_dynar_get_cpy(source, i, &v);
    HostAttribute attr = sg_host_user(v);
    if (!attr->idle_busy){
      xbt_dynar_push(to_stop, &v);
      found++;
    }
    i++;
  }

  if (found < how_many)
    XBT_WARN("Trying to terminate too many VMs, some are busy... Change the number of VMs to terminate to %d", found);

  return to_stop;
}
开发者ID:frs69wq,项目名称:EnsembleSched,代码行数:40,代码来源:host.c

示例4: xbt_dynar_compare

/** @brief Compare two dynars
 *
 *  \param d1 first dynar to compare
 *  \param d2 second dynar to compare
 *  \param compar function to use to compare elements
 *  \return 0 if d1 and d2 are equal and 1 if not equal
 *
 *  d1 and d2 should be dynars of pointers. The compar function takes two  elements and returns 0 when they are
 *  considered equal, and a value different of zero when they are considered different. Finally, d2 is destroyed
 *  afterwards.
 */
int xbt_dynar_compare(xbt_dynar_t d1, xbt_dynar_t d2, int(*compar)(const void *, const void *))
{
  int i ;
  int size;
  if((!d1) && (!d2)) return 0;
  if((!d1) || (!d2))
  {
    XBT_DEBUG("NULL dynar d1=%p d2=%p",d1,d2);
    xbt_dynar_free(&d2);
    return 1;
  }
  if((d1->elmsize)!=(d2->elmsize)) {
    XBT_DEBUG("Size of elmsize d1=%lu d2=%lu",d1->elmsize,d2->elmsize);
    xbt_dynar_free(&d2);
    return 1; // xbt_die
  }
  if(xbt_dynar_length(d1) != xbt_dynar_length(d2)) {
    XBT_DEBUG("Size of dynar d1=%lu d2=%lu",xbt_dynar_length(d1),xbt_dynar_length(d2));
    xbt_dynar_free(&d2);
    return 1;
  }

  size = xbt_dynar_length(d1);
  for(i=0;i<size;i++) {
    void *data1 = xbt_dynar_get_as(d1, i, void *);
    void *data2 = xbt_dynar_get_as(d2, i, void *);
    XBT_DEBUG("link[%d] d1=%p d2=%p",i,data1,data2);
    if(compar(data1,data2)){
      xbt_dynar_free(&d2);
      return 1;
    }
  }
  xbt_dynar_free(&d2);
  return 0;
}
开发者ID:R7R8,项目名称:simgrid,代码行数:46,代码来源:dynar.c

示例5: main

int main(int argc, char **argv)
{
  double comm_cost[] = { 0.0, 0.0, 0.0, 0.0 };
  double comp_cost[] = { 1.0 };
  SD_task_t taskA, taskB;
  xbt_dynar_t ret;

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

  taskA = SD_task_create("Task A", NULL, 1.0);
  taskB = SD_task_create("Task B", NULL, 1.0);

  SD_task_schedule(taskA, 1, SD_workstation_get_list(), comp_cost,
                   comm_cost, -1.0);
  SD_task_schedule(taskB, 1, SD_workstation_get_list(), comp_cost,
                   comm_cost, -1.0);

  ret = SD_simulate(-1.0);
  xbt_assert(xbt_dynar_length(ret) == 2,
      "I was expecting the terminaison of 2 tasks, but I got %lu instead",
      xbt_dynar_length(ret));
  xbt_dynar_free(&ret);
  SD_task_destroy(taskA);
  SD_task_destroy(taskB);

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

  SD_exit();
  return 0;
}
开发者ID:Julio-Anjos,项目名称:simgrid,代码行数:31,代码来源:basic6.c

示例6: xbt_dynar_new

/* Business methods */
xbt_dynar_t AsFloyd::getOneLinkRoutes()
{
  xbt_dynar_t ret = xbt_dynar_new(sizeof(OnelinkPtr), xbt_free_f);
  sg_platf_route_cbarg_t route =   xbt_new0(s_sg_platf_route_cbarg_t, 1);
  route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);

  int src,dst;
  sg_routing_edge_t src_elm, dst_elm;
  int table_size = xbt_dynar_length(p_indexNetworkElm);
  for(src=0; src < table_size; src++) {
    for(dst=0; dst< table_size; dst++) {
      xbt_dynar_reset(route->link_list);
      src_elm = xbt_dynar_get_as(p_indexNetworkElm, src, RoutingEdgePtr);
      dst_elm = xbt_dynar_get_as(p_indexNetworkElm, dst, RoutingEdgePtr);
      this->getRouteAndLatency(src_elm, dst_elm, route, NULL);

      if (xbt_dynar_length(route->link_list) == 1) {
        void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0);
        OnelinkPtr onelink;
        if (p_hierarchy == SURF_ROUTING_BASE)
          onelink = new Onelink(link, src_elm, dst_elm);
        else if (p_hierarchy == SURF_ROUTING_RECURSIVE)
          onelink = new Onelink(link, route->gw_src, route->gw_dst);
        else
          onelink = new Onelink(link, NULL, NULL);
        xbt_dynar_push(ret, &onelink);
      }
    }
  }

  return ret;
}
开发者ID:FlorianPO,项目名称:simgrid,代码行数:33,代码来源:surf_routing_floyd.cpp

示例7: xbt_dict_dump_sizes

/** @brief shows some debugging info about the bucklet repartition */
void xbt_dict_dump_sizes(xbt_dict_t dict)
{

    int i;
    unsigned int count;
    unsigned int size;
    xbt_dictelm_t element;
    xbt_dynar_t sizes = xbt_dynar_new(sizeof(int), NULL);

    printf("Dict %p: %d bucklets, %d used cells (of %d) ", dict, dict->count,
           dict->fill, dict->table_size);
    if (dict != NULL) {
        for (i = 0; i < dict->table_size; i++) {
            element = dict->table[i];
            size = 0;
            if (element) {
                while (element != NULL) {
                    size++;
                    element = element->next;
                }
            }
            if (xbt_dynar_length(sizes) <= size) {
                int prevsize = 1;
                xbt_dynar_set(sizes, size, &prevsize);
            } else {
                int prevsize;
                xbt_dynar_get_cpy(sizes, size, &prevsize);
                prevsize++;
                xbt_dynar_set(sizes, size, &prevsize);
            }
        }
        if (!all_sizes)
            all_sizes = xbt_dynar_new(sizeof(int), NULL);

        xbt_dynar_foreach(sizes, count, size) {
            /* Copy values of this one into all_sizes */
            int prevcount;
            if (xbt_dynar_length(all_sizes) <= count) {
                prevcount = size;
                xbt_dynar_set(all_sizes, count, &prevcount);
            } else {
                xbt_dynar_get_cpy(all_sizes, count, &prevcount);
                prevcount += size;
                xbt_dynar_set(all_sizes, count, &prevcount);
            }

            /* Report current sizes */
            if (count == 0)
                continue;
            if (size == 0)
                continue;
            printf("%uelm x %u cells; ", count, size);
        }
    }
开发者ID:apargupta,项目名称:simgrid,代码行数:55,代码来源:dict.c

示例8: malloc

inline unsigned int *rankId_to_coords(int rankId, xbt_dynar_t dimensions)
{

  unsigned int i = 0, cur_dim_size = 1, dim_size_product = 1;
  unsigned int *coords = (unsigned int *) malloc(xbt_dynar_length(dimensions) * sizeof(unsigned int));
  for (i = 0; i < xbt_dynar_length(dimensions); i++) {
    cur_dim_size = xbt_dynar_get_as(dimensions, i, int);
    coords[i] = (rankId / dim_size_product) % cur_dim_size;
    dim_size_product *= cur_dim_size;
  }

  return coords;
}
开发者ID:dindon-sournois,项目名称:simgrid,代码行数:13,代码来源:AsClusterTorus.cpp

示例9: action_finalize

static void action_finalize(const char *const *action)
{
  smpi_replay_globals_t globals =
      (smpi_replay_globals_t) smpi_process_get_user_data();

  if (globals){
    XBT_DEBUG("There are %lu isends and %lu irecvs in the dynars",
         xbt_dynar_length(globals->isends),xbt_dynar_length(globals->irecvs));
    xbt_dynar_free_container(&(globals->isends));
    xbt_dynar_free_container(&(globals->irecvs));
  }
  free(globals);
}
开发者ID:Shurakai,项目名称:SimGrid,代码行数:13,代码来源:smpi_replay.c

示例10: Seal

void AsFull::Seal() {
  int i;
  sg_platf_route_cbarg_t e_route;

  /* set utils vars */
  int table_size = (int)xbt_dynar_length(vertices_);

  /* Create table if necessary */
  if (!routingTable_)
    routingTable_ = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);

  /* Add the loopback if needed */
  if (routing_platf->loopback_ && hierarchy_ == RoutingMode::base) {
    for (i = 0; i < table_size; i++) {
      e_route = TO_ROUTE_FULL(i, i);
      if (!e_route) {
        e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
        e_route->gw_src = NULL;
        e_route->gw_dst = NULL;
        e_route->link_list = new std::vector<Link*>();
        e_route->link_list->push_back(routing_platf->loopback_);
        TO_ROUTE_FULL(i, i) = e_route;
      }
    }
  }
}
开发者ID:adegomme,项目名称:simgrid,代码行数:26,代码来源:AsFull.cpp

示例11: suspend

void BoostSerialContext::suspend()
{
  /* determine the next context */
  BoostSerialContext* next_context = nullptr;
  unsigned long int i = process_index_++;

  if (i < xbt_dynar_length(simix_global->process_to_run)) {
    /* execute the next process */
    XBT_DEBUG("Run next process");
    next_context = static_cast<BoostSerialContext*>(xbt_dynar_get_as(
        simix_global->process_to_run, i, smx_process_t)->context);
  }
  else {
    /* all processes were run, return to maestro */
    XBT_DEBUG("No more process to run");
    next_context = static_cast<BoostSerialContext*>(
      maestro_context_);
  }
  SIMIX_context_set_current((smx_context_t) next_context);
  #if HAVE_BOOST_CONTEXTS == 1
  boost::context::jump_fcontext(
    this->fc_, next_context->fc_, (intptr_t) next_context);
  #else
  boost::context::jump_fcontext(
    &this->fc_, next_context->fc_, (intptr_t) next_context);
  #endif
}
开发者ID:RockyMeadow,项目名称:simgrid,代码行数:27,代码来源:BoostContext.cpp

示例12: parse_factor

static xbt_dynar_t parse_factor(const char *smpi_coef_string)
{
  char *value = NULL;
  unsigned int iter = 0;
  s_smpi_factor_t fact;
  xbt_dynar_t smpi_factor, radical_elements, radical_elements2 = NULL;

  smpi_factor = xbt_dynar_new(sizeof(s_smpi_factor_t), NULL);
  radical_elements = xbt_str_split(smpi_coef_string, ";");
  xbt_dynar_foreach(radical_elements, iter, value) {

    radical_elements2 = xbt_str_split(value, ":");
    surf_parse_assert(xbt_dynar_length(radical_elements2) == 2,
        "Malformed radical '%s' for smpi factor. I was expecting something like 'a:b'", value);

    char *errmsg = bprintf("Invalid factor in chunk #%d: %%s", iter+1);
    fact.factor = xbt_str_parse_int(xbt_dynar_get_as(radical_elements2, 0, char *), errmsg);
    xbt_free(errmsg);
    fact.value = xbt_str_parse_double(xbt_dynar_get_as(radical_elements2, 1, char *), errmsg);
    errmsg = bprintf("Invalid factor value in chunk #%d: %%s", iter+1);
    xbt_free(errmsg);

    xbt_dynar_push_as(smpi_factor, s_smpi_factor_t, fact);
    XBT_DEBUG("smpi_factor:\t%ld : %f", fact.factor, fact.value);
    xbt_dynar_free(&radical_elements2);
  }
开发者ID:adegomme,项目名称:simgrid,代码行数:26,代码来源:network_smpi.cpp

示例13: main

int main(int argc, char **argv)
{
  int i;
  msg_error_t res = MSG_OK;

  MSG_init(&argc, argv);
  surf_parse = surf_parse_bypass_platform;
  MSG_create_environment(NULL);

  MSG_function_register("host", host);

  xbt_dynar_t hosts = MSG_hosts_as_dynar();
  nb_hosts =  xbt_dynar_length(hosts);

  XBT_INFO("Number of host '%d'",nb_hosts);
  for(i = 0 ; i<nb_hosts; i++)
  {
    char* name_host = bprintf("%d",i);
    MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,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;

}
开发者ID:tempbottle,项目名称:simgrid,代码行数:32,代码来源:token_bypass.c

示例14: smx_ctx_boost_suspend_serial

static void smx_ctx_boost_suspend_serial(smx_context_t context)
{
  /* determine the next context */
  smx_ctx_boost_t next_context;
  unsigned long int i = boost_process_index++;

  if (i < xbt_dynar_length(simix_global->process_to_run)) {
    /* execute the next process */
    XBT_DEBUG("Run next process");
    next_context = (smx_ctx_boost_t) xbt_dynar_get_as(
        simix_global->process_to_run, i, smx_process_t)->context;
  }
  else {
    /* all processes were run, return to maestro */
    XBT_DEBUG("No more process to run");
    next_context = (smx_ctx_boost_t) boost_maestro_context;
  }
  SIMIX_context_set_current((smx_context_t) next_context);
#if HAVE_BOOST_CONTEXT == 1
  boost::context::jump_fcontext(
    ((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context);
#else
  boost::context::jump_fcontext(
    &((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context);
#endif
}
开发者ID:apargupta,项目名称:simgrid,代码行数:26,代码来源:smx_context_boost.cpp

示例15: main

int main(int argc, char **argv)
{
  int i,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);
  for(i = 0 ; i<nb_hosts; i++)
  {
    char* name_host = bprintf("%d",i);
    MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,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;

}
开发者ID:Julio-Anjos,项目名称:simgrid,代码行数:25,代码来源:file.c


注:本文中的xbt_dynar_length函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。