root/opal/mca/reachable/base/reachable_base_alloc.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. opal_reachable_construct
  2. opal_reachable_destruct
  3. opal_reachable_allocate

   1 /*
   2  * Copyright (c) 2017      Amazon.com, Inc. or its affiliates.
   3  *                         All Rights reserved.
   4  * $COPYRIGHT$
   5  *
   6  * Additional copyrights may follow
   7  *
   8  * $HEADER$
   9  */
  10 
  11 #include "opal_config.h"
  12 
  13 #include "opal/class/opal_object.h"
  14 
  15 #include "opal/mca/reachable/reachable.h"
  16 #include "opal/mca/reachable/base/base.h"
  17 
  18 
  19 static void opal_reachable_construct(opal_reachable_t *reachable)
  20 {
  21     reachable->weights = NULL;
  22 }
  23 
  24 
  25 static void opal_reachable_destruct(opal_reachable_t * reachable)
  26 {
  27     if (NULL != reachable->memory) {
  28         free(reachable->memory);
  29     }
  30 }
  31 
  32 
  33 opal_reachable_t * opal_reachable_allocate(unsigned int num_local,
  34                                            unsigned int num_remote)
  35 {
  36     char *memory;
  37     unsigned int i;
  38     opal_reachable_t *reachable = OBJ_NEW(opal_reachable_t);
  39 
  40     reachable->num_local = num_local;
  41     reachable->num_remote = num_remote;
  42 
  43     /* allocate all the pieces of the two dimensional array in one
  44        malloc, rather than a bunch of little allocations */
  45     memory = malloc(sizeof(int*) * num_local +
  46                     num_local * (sizeof(int) * num_remote));
  47     if (memory == NULL) return NULL;
  48 
  49     reachable->memory = (void*)memory;
  50     reachable->weights = (int**)reachable->memory;
  51     memory += (sizeof(int*) * num_local);
  52 
  53     for (i = 0; i < num_local; i++) {
  54         reachable->weights[i] = (int*)memory;
  55         memory += (sizeof(int) * num_remote);
  56     }
  57 
  58     return reachable;
  59 }
  60 
  61 OBJ_CLASS_INSTANCE(
  62     opal_reachable_t,
  63     opal_object_t,
  64     opal_reachable_construct,
  65     opal_reachable_destruct
  66 );

/* [<][>][^][v][top][bottom][index][help] */