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


C++ xbt_malloc函数代码示例

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


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

示例1: smpi_coll_tuned_reduce_flat_tree

int
smpi_coll_tuned_reduce_flat_tree(void *sbuf, void *rbuf, int count,
                                 MPI_Datatype dtype, MPI_Op op,
                                 int root, MPI_Comm comm)
{
  int i, tag = 4321;
  int size;
  int rank;
  MPI_Aint extent;
  char *origin = 0;
  char *inbuf;
  MPI_Status status;

  rank = smpi_comm_rank(comm);
  size = smpi_comm_size(comm);

  /* If not root, send data to the root. */
  extent = smpi_datatype_get_extent(dtype);

  if (rank != root) {
    smpi_mpi_send(sbuf, count, dtype, root, tag, comm);
    return 0;
  }

  /* Root receives and reduces messages.  Allocate buffer to receive
     messages. */

  if (size > 1)
    origin = (char *) xbt_malloc(count * extent);


  /* Initialize the receive buffer. */
  if (rank == (size - 1))
    smpi_mpi_sendrecv(sbuf, count, dtype, rank, tag,
                 rbuf, count, dtype, rank, tag, comm, &status);
  else
    smpi_mpi_recv(rbuf, count, dtype, size - 1, tag, comm, &status);

  /* Loop receiving and calling reduction function (C or Fortran). */

  for (i = size - 2; i >= 0; --i) {
    if (rank == i)
      inbuf = sbuf;
    else {
      smpi_mpi_recv(origin, count, dtype, i, tag, comm, &status);
      inbuf = origin;
    }

    /* Call reduction function. */
    smpi_op_apply(op, inbuf, rbuf, &count, &dtype);

  }

  if (origin)
    free(origin);

  /* All done */
  return 0;
}
开发者ID:dhascome,项目名称:simgrid,代码行数:59,代码来源:reduce-flat-tree.c

示例2: main

int main(int argc, char *argv[])
{
  int rank, size;
  int i;
  int *sb;
  int *rb;
  int status;
  int mult=1;

  MPI_Init(&argc, &argv);
  int maxlen = argc >= 2 ? atoi(argv[1]) : 1;

  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &size);
  if (maxlen>1)mult=size;
  sb = (int *) xbt_malloc(size *maxlen * sizeof(int));
  rb = (int *) xbt_malloc(size *maxlen * sizeof(int));
  
  for (i = 0; i < size *maxlen; ++i) {
    sb[i] = rank*size + i;
    rb[i] = 0;
  }

  printf("[%d] sndbuf=[", rank);
  for (i = 0; i < size *mult; i++)
    printf("%d ", sb[i]);
  printf("]\n");

  status = MPI_Allreduce(sb, rb, size *maxlen, MPI_INT, MPI_SUM, MPI_COMM_WORLD);

  printf("[%d] rcvbuf=[", rank);
  for (i =  0; i < size *mult; i++)//do not print everything
    printf("%d ", rb[i]);
  printf("]\n");

  if (rank == 0) {
    if (status != MPI_SUCCESS) {
      printf("all_to_all returned %d\n", status);
      fflush(stdout);
    }
  }
  free(sb);
  free(rb);
  MPI_Finalize();
  return (EXIT_SUCCESS);
}
开发者ID:R7R8,项目名称:simgrid,代码行数:46,代码来源:coll-allreduce.c

示例3: main

/**
 * Main function
 * Create the platform, list the available hosts and give them some work
 */
int main(int argc, char **argv) {

  unsigned long seed[] = {134, 233445, 865, 2634, 424242, 876543};
  int connected;
  int max_tries = 10;

  //MSG initialization
  MSG_init(&argc, argv);

  //Set up the seed for the platform generation
  platf_random_seed(seed);

  XBT_INFO("creating nodes...");
  platf_graph_uniform(50);
  do {
    max_tries--;
    XBT_INFO("creating links...");
    platf_graph_clear_links();
    platf_graph_interconnect_uniform(0.07); //Unrealistic, but simple
    XBT_INFO("done. Check connectedness...");
    connected = platf_graph_is_connected();
    XBT_INFO("Is it connected : %s", connected ? "yes" : (max_tries ? "no, retrying" : "no"));
  } while(!connected && max_tries);

  if(!connected && !max_tries) {
    xbt_die("Impossible to connect the graph, aborting.");
  }

  XBT_INFO("registering callbacks...");
  platf_graph_promoter(promoter_1);
  platf_graph_labeler(labeler_1);

  XBT_INFO("protmoting...");
  platf_do_promote();

  XBT_INFO("labeling...");
  platf_do_label();

  XBT_INFO("Putting it in surf...");
  platf_generate();

  XBT_INFO("Let's get the available hosts and dispatch work:");

  unsigned int i;
  msg_host_t host = NULL;
  msg_host_t host_master = NULL;
  xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
  char** hostname_list = xbt_malloc(sizeof(char*) * xbt_dynar_length(host_dynar));

  xbt_dynar_foreach(host_dynar, i, host) {
    MSG_process_create("slave", slave, NULL, host);
    if(i==0) {
      //The first node will also be the master
      XBT_INFO("%s will be the master", MSG_host_get_name(host));
      host_master = host;
    }
    hostname_list[i] = (char*) MSG_host_get_name(host);
  }
开发者ID:apargupta,项目名称:simgrid,代码行数:62,代码来源:masterslave_platfgen.c

示例4: main

int main(int argc, char *argv[])
{
  int i, rank, size;
  int *sb, *rb;
  int status;

  int root = 0;

  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &size);

  int count = 2;
  sb = (int *) xbt_malloc(count * sizeof(int));
  rb = (int *) xbt_malloc(count * size * sizeof(int));
  
  for (i = 0; i < count; ++i)
    sb[i] = rank * count + i;
  for (i = 0; i < count * size; ++i)  
    rb[i] = 0;

  printf("[%d] sndbuf=[", rank);
  for (i = 0; i < count; i++)
    printf("%d ", sb[i]);
  printf("]\n");

  status = MPI_Gather(sb, count, MPI_INT, rb, count, MPI_INT, root, MPI_COMM_WORLD);

  if (rank == root) {
    printf("[%d] rcvbuf=[", rank);
    for (i = 0; i < count * size; i++)
      printf("%d ", rb[i]);
    printf("]\n");

    if (status != MPI_SUCCESS) {
      printf("allgather returned %d\n", status);
      fflush(stdout);
    }
  }
  free(sb);
  free(rb);
  MPI_Barrier(MPI_COMM_WORLD);
  MPI_Finalize();
  return (EXIT_SUCCESS);
}
开发者ID:R7R8,项目名称:simgrid,代码行数:45,代码来源:coll-gather.c

示例5: smpi_get_tmp_recvbuffer

//allocate a single buffer for all recv
void* smpi_get_tmp_recvbuffer(int size){
  if (!smpi_process_get_replaying())
  return xbt_malloc(size);
  if (recvbuffer_size<size){
    recvbuffer=static_cast<char*>(xbt_realloc(recvbuffer,size));
    recvbuffer_size=size;
  }
  return recvbuffer;
}
开发者ID:fabienchaix,项目名称:simgrid,代码行数:10,代码来源:smpi_replay.cpp

示例6: smpi_get_tmp_recvbuffer

//allocate a single buffer for all recv
void* smpi_get_tmp_recvbuffer(int size){
  if (!smpi_process_get_replaying())
	return xbt_malloc(size);
  if (recvbuffer_size<size){
    recvbuffer=xbt_realloc(recvbuffer,size);
    recvbuffer_size=size;
  }
  return sendbuffer;
}
开发者ID:apargupta,项目名称:simgrid,代码行数:10,代码来源:smpi_replay.c

示例7: main

int main(int argc, char *argv[])
{
    int rank, size;
    int i;
    int *sb;
    int *rb;
    int status;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    sb = (int *) xbt_malloc(size * sizeof(int) * 2);
    rb = (int *) xbt_malloc(size * sizeof(int) * 2);

    for (i = 0; i < size; ++i) {
        sb[i] = rank*size + i;
        rb[i] = 0;
    }

    printf("[%d] sndbuf=[", rank);
    for (i = 0; i < size; i++)
        printf("%d ", sb[i]);
    printf("]\n");

    status = MPI_Alltoall(sb, 1, MPI_INT, rb, 1, MPI_INT, MPI_COMM_WORLD);

    printf("[%d] rcvbuf=[", rank);
    for (i = 0; i < size; i++)
        printf("%d ", rb[i]);
    printf("]\n");


    if (rank == 0) {
        if (status != MPI_SUCCESS) {
            printf("all_to_all returned %d\n", status);
            fflush(stdout);
        }
    }
    free(sb);
    free(rb);
    MPI_Finalize();
    return (EXIT_SUCCESS);
}
开发者ID:FlorianPO,项目名称:simgrid,代码行数:44,代码来源:alltoall_coll.c

示例8: smpi_process_init

void smpi_process_init(int *argc, char ***argv)
{
  int index=-1;
  smpi_process_data_t data;
  smx_process_t proc;

  if (argc && argv) {
    proc = SIMIX_process_self();
    //FIXME: dirty cleanup method to avoid using msg cleanup functions on these processes when using MSG+SMPI
    SIMIX_process_set_cleanup_function(proc, MSG_process_cleanup_from_SIMIX);
    char* instance_id = (*argv)[1];
    int rank = xbt_str_parse_int((*argv)[2], "Invalid rank: %s");
    index = smpi_process_index_of_smx_process(proc);

    if(!index_to_process_data){
      index_to_process_data=(int*)xbt_malloc(SIMIX_process_count()*sizeof(int));
    }

    if(smpi_privatize_global_variables){
      /* Now using segment index of the process  */
      index = proc->segment_index;
      /* Done at the process's creation */
      SMPI_switch_data_segment(index);
    }

    MPI_Comm* temp_comm_world;
    xbt_bar_t temp_bar;
    smpi_deployment_register_process(instance_id, rank, index, &temp_comm_world, &temp_bar);
    data              = smpi_process_remote_data(index);
    data->comm_world  = temp_comm_world;
    if(temp_bar != NULL) data->finalization_barrier = temp_bar;
    data->index       = index;
    data->instance_id = instance_id;
    data->replaying   = 0;
    //xbt_free(simcall_process_get_data(proc));

    simdata_process_t simdata = static_cast<simdata_process_t>(simcall_process_get_data(proc));
    simdata->data             = data;

    if (*argc > 3) {
      free((*argv)[1]);
      memmove(&(*argv)[0], &(*argv)[2], sizeof(char *) * (*argc - 2));
      (*argv)[(*argc) - 1] = NULL;
      (*argv)[(*argc) - 2] = NULL;
    }
    (*argc)-=2;
    data->argc = argc;
    data->argv = argv;
    // set the process attached to the mailbox
    simcall_mbox_set_receiver(data->mailbox_small, proc);
    XBT_DEBUG("<%d> New process in the game: %p", index, proc);
  }
  xbt_assert(smpi_process_data(),
      "smpi_process_data() returned NULL. You probably gave a NULL parameter to MPI_Init. Although it's required by "
      "MPI-2, this is currently not supported by SMPI.");
}
开发者ID:krytarowski,项目名称:simgrid,代码行数:56,代码来源:smpi_global.cpp

示例9: xbt_matrix_new

/** \brief constructor */
xbt_matrix_t xbt_matrix_new(int lines, int rows, const unsigned long elmsize, void_f_pvoid_t const free_f)
{
  xbt_matrix_t res = xbt_new(s_xbt_matrix_t, 1);
  res->lines = lines;
  res->rows = rows;
  res->elmsize = elmsize;
  res->free_f = free_f;
  res->data = xbt_malloc(elmsize * lines * rows);
  return res;
}
开发者ID:R7R8,项目名称:simgrid,代码行数:11,代码来源:xbt_matrix.c

示例10: xbt_str_split_str

/**
 * \brief This functions splits a string after using another string as separator
 * For example A!!B!!C splitted after !! will return the dynar {A,B,C}
 * \return An array of dynars containing the string tokens
 */
xbt_dynar_t xbt_str_split_str(const char *s, const char *sep)
{
  xbt_dynar_t res = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
  int done;
  const char *p, *q;

  p = q = s;
  done = 0;

  if (s[0] == '\0')
    return res;
  if (sep[0] == '\0') {
    s = xbt_strdup(s);
    xbt_dynar_push(res, &s);
    return res;
  }

  while (!done) {
    char *to_push;
    int v = 0;
    //get the start of the first occurence of the substring
    q = strstr(p, sep);
    //if substring was not found add the entire string
    if (NULL == q) {
      v = strlen(p);
      to_push = xbt_malloc(v + 1);
      memcpy(to_push, p, v);
      to_push[v] = '\0';
      xbt_dynar_push(res, &to_push);
      done = 1;
    } else {
      //get the appearance
      to_push = xbt_malloc(q - p + 1);
      memcpy(to_push, p, q - p);
      //add string terminator
      to_push[q - p] = '\0';
      xbt_dynar_push(res, &to_push);
      p = q + strlen(sep);
    }
  }
  return res;
}
开发者ID:FlorianPO,项目名称:simgrid,代码行数:47,代码来源:xbt_str.c

示例11: while

static char *remplace(char *value, const char **src_list, int src_size,
    const char **dst_list, int dst_size)
{
  char result[BUFFER_SIZE];
  int i_res = 0;
  int i = 0;

  while (value[i]) {
    if (value[i] == '$') {
      i++;                      /* skip the '$' */
      if (value[i] < '0' || value[i] > '9')
        xbt_die("bad string parameter, no number indication, at offset: "
            "%d (\"%s\")", i, value);

      /* solve the number */
      int number = value[i++] - '0';
      while (value[i] >= '0' && value[i] <= '9')
        number = 10 * number + (value[i++] - '0');

      /* solve the indication */
      const char **param_list;
      _XBT_GNUC_UNUSED int param_size;
      if (value[i] == 's' && value[i + 1] == 'r' && value[i + 2] == 'c') {
        param_list = src_list;
        param_size = src_size;
      } else if (value[i] == 'd' && value[i + 1] == 's'
          && value[i + 2] == 't') {
        param_list = dst_list;
        param_size = dst_size;
      } else {
        xbt_die("bad string parameter, support only \"src\" and \"dst\", "
            "at offset: %d (\"%s\")", i, value);
      }
      i += 3;

      xbt_assert(number < param_size,
          "bad string parameter, not enough length param_size, "
          "at offset: %d (\"%s\") %d %d", i, value, param_size, number);

      const char *param = param_list[number];
      int j = 0;
      while (param[j] && i_res < BUFFER_SIZE)
        result[i_res++] = param[j++];
    } else {
      result[i_res++] = value[i++]; /* next char */
    }
    if (i_res >= BUFFER_SIZE)
      xbt_die("solving string \"%s\", small buffer size (%d)",
          value, BUFFER_SIZE);
  }
  result[i_res++] = '\0';
  char *res = xbt_malloc(i_res);
  return memcpy(res, result, i_res);
}
开发者ID:Shurakai,项目名称:SimGrid,代码行数:54,代码来源:surf_routing_rulebased.c

示例12: array_new

static void array_new(unsigned **a, xbt_dynar_t *data)
{
  int i;
  *a = xbt_malloc(ARRAY_SIZE * sizeof **a);
  *data = xbt_dynar_new(sizeof *a, NULL);
  xbt_dynar_shrink(*data, ARRAY_SIZE);
  for (i = 0 ; i < ARRAY_SIZE ; i++) {
    (*a)[i] = i;
    xbt_dynar_push_as(*data, void*, &(*a)[i]);
  }
}
开发者ID:Shurakai,项目名称:SimGrid,代码行数:11,代码来源:parmap_bench.c

示例13: _xbt_log_event_log

void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...)
{
  xbt_log_category_t cat = ev->cat;

  xbt_assert(ev->priority >= 0,
             "Negative logging priority naturally forbidden");
  xbt_assert(ev->priority < sizeof(xbt_log_priority_names),
             "Priority %d is greater than the biggest allowed value",
             ev->priority);

  do {
    xbt_log_appender_t appender = cat->appender;

    if (!appender)
      continue;                 /* No appender, try next */

    xbt_assert(cat->layout,
               "No valid layout for the appender of category %s", cat->name);

    /* First, try with a static buffer */
    if (XBT_LOG_STATIC_BUFFER_SIZE) {
      char buff[XBT_LOG_STATIC_BUFFER_SIZE];
      int done;
      ev->buffer = buff;
      ev->buffer_size = sizeof buff;
      va_start(ev->ap, fmt);
      done = cat->layout->do_layout(cat->layout, ev, fmt);
      va_end(ev->ap);
      if (done) {
        appender->do_append(appender, buff);
        continue;               /* Ok, that worked: go next */
      }
    }

    /* The static buffer was too small, use a dynamically expanded one */
    ev->buffer_size = XBT_LOG_DYNAMIC_BUFFER_SIZE;
    ev->buffer = xbt_malloc(ev->buffer_size);
    while (1) {
      int done;
      va_start(ev->ap, fmt);
      done = cat->layout->do_layout(cat->layout, ev, fmt);
      va_end(ev->ap);
      if (done)
        break;                  /* Got it */
      ev->buffer_size *= 2;
      ev->buffer = xbt_realloc(ev->buffer, ev->buffer_size);
    }
    appender->do_append(appender, ev->buffer);
    xbt_free(ev->buffer);

  } while (cat->additivity && (cat = cat->parent, 1));
}
开发者ID:Tien-Dat,项目名称:simgrid,代码行数:52,代码来源:log.c

示例14: smpi_coll_tuned_allgather_spreading_simple

/*****************************************************************************
 * Function: allgather_spreading_simple
 * return: int
 *  inputs:
 *   send_buff: send input buffer
 *   send_count: number of elements to send
 *   send_type: data type of elements being sent
 *   recv_buff: receive output buffer
 *   recv_count: number of elements to received
 *   recv_type: data type of elements being received
 *   comm: communication
 * Descrp: Let i -> j denote the communication from node i to node j. The
 *         order of communications for node i is i -> i + 1, i -> i + 2, ...,
 *         i -> (i + p -1) % P.
 *
 * Auther: Ahmad Faraj
 ****************************************************************************/
int
smpi_coll_tuned_allgather_spreading_simple(void *send_buff, int send_count,
                                           MPI_Datatype send_type,
                                           void *recv_buff, int recv_count,
                                           MPI_Datatype recv_type,
                                           MPI_Comm comm)
{
  MPI_Request *reqs, *req_ptr;
  MPI_Aint extent;
  int i, src, dst, rank, num_procs, num_reqs;
  int tag = COLL_TAG_ALLGATHER;
  MPI_Status status;
  char *recv_ptr = (char *) recv_buff;

  rank = smpi_comm_rank(comm);
  num_procs = smpi_comm_size(comm);
  extent = smpi_datatype_get_extent(send_type);

  num_reqs = (2 * num_procs) - 2;
  reqs = (MPI_Request *) xbt_malloc(num_reqs * sizeof(MPI_Request));
  if (!reqs) {
    printf("allgather-spreading-simple.c:40: cannot allocate memory\n");
    MPI_Finalize();
    exit(0);
  }

  req_ptr = reqs;
  smpi_mpi_sendrecv(send_buff, send_count, send_type, rank, tag,
               (char *) recv_buff + rank * recv_count * extent, recv_count,
               recv_type, rank, tag, comm, &status);

  for (i = 0; i < num_procs; i++) {
    src = (rank + i) % num_procs;
    if (src == rank)
      continue;
    *(req_ptr++) = smpi_mpi_irecv(recv_ptr + src * recv_count * extent, recv_count, recv_type,
              src, tag, comm);
  }

  for (i = 0; i < num_procs; i++) {
    dst = (rank + i) % num_procs;
    if (dst == rank)
      continue;
    *(req_ptr++) = smpi_mpi_isend(send_buff, send_count, send_type, dst, tag, comm);
  }

  smpi_mpi_waitall(num_reqs, reqs, MPI_STATUSES_IGNORE);
  free(reqs);

  return MPI_SUCCESS;
}
开发者ID:Julio-Anjos,项目名称:simgrid,代码行数:68,代码来源:allgather-spreading-simple.c

示例15: luaopen_simgrid

/**
 * \brief Opens the simgrid Lua module.
 *
 * This function is called automatically by the Lua interpreter when some
 * Lua code requires the "simgrid" module.
 *
 * \param L the Lua state
 */
int luaopen_simgrid(lua_State *L)
{
  XBT_DEBUG("luaopen_simgrid *****");

  /* Get the command line arguments from the lua interpreter */
  char **argv = xbt_malloc(sizeof(char *) * LUA_MAX_ARGS_COUNT);
  int argc = 1;
  argv[0] = (char *) "/usr/bin/lua";    /* Lie on the argv[0] so that the stack dumping facilities find the right binary. FIXME: what if lua is not in that location? */

  lua_getglobal(L, "arg");
  /* if arg is a null value, it means we use lua only as a script to init platform
   * else it should be a table and then take arg in consideration
   */
  if (lua_istable(L, -1)) {
    int done = 0;
    while (!done) {
      argc++;
      lua_pushinteger(L, argc - 2);
      lua_gettable(L, -2);
      if (lua_isnil(L, -1)) {
        done = 1;
      } else {
        xbt_assert(lua_isstring(L, -1),
                    "argv[%d] got from lua is no string", argc - 1);
        xbt_assert(argc < LUA_MAX_ARGS_COUNT,
                    "Too many arguments, please increase LUA_MAX_ARGS_COUNT in %s before recompiling SimGrid if you insist on having more than %d args on command line",
                    __FILE__, LUA_MAX_ARGS_COUNT - 1);
        argv[argc - 1] = (char *) luaL_checkstring(L, -1);
        lua_pop(L, 1);
        XBT_DEBUG("Got command line argument %s from lua", argv[argc - 1]);
      }
    }
    argv[argc--] = NULL;

    /* Initialize the MSG core */
    MSG_init(&argc, argv);
    MSG_process_set_data_cleanup((void_f_pvoid_t) lua_close);
    XBT_DEBUG("Still %d arguments on command line", argc); // FIXME: update the lua's arg table to reflect the changes from SimGrid
  }

  /* Keep the context mechanism informed of our lua world today */
  sglua_maestro_state = L;

  /* initialize access to my tables by children Lua states */
  lua_newtable(L);
  lua_setfield(L, LUA_REGISTRYINDEX, "simgrid.maestro_tables");

  sglua_register_c_functions(L);

  return 1;
}
开发者ID:dhascome,项目名称:simgrid,代码行数:59,代码来源:simgrid_lua.c


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