root/ompi/mpi/c/alloc_mem.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Alloc_mem

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2005 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2007      Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2015      Research Organization for Information Science
  15  *                         and Technology (RIST). All rights reserved.
  16  * Copyright (c) 2015      Los Alamos National Security, LLC.  All rights
  17  *                         reserved.
  18  * $COPYRIGHT$
  19  *
  20  * Additional copyrights may follow
  21  *
  22  * $HEADER$
  23  */
  24 
  25 #include "ompi_config.h"
  26 
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 
  30 #include "ompi/mpi/c/bindings.h"
  31 #include "ompi/runtime/params.h"
  32 #include "ompi/communicator/communicator.h"
  33 #include "ompi/errhandler/errhandler.h"
  34 #include "ompi/info/info.h"
  35 #include "opal/mca/mpool/mpool.h"
  36 
  37 #if OMPI_BUILD_MPI_PROFILING
  38 #if OPAL_HAVE_WEAK_SYMBOLS
  39 #pragma weak MPI_Alloc_mem = PMPI_Alloc_mem
  40 #endif
  41 #define MPI_Alloc_mem PMPI_Alloc_mem
  42 #endif
  43 
  44 static const char FUNC_NAME[] = "MPI_Alloc_mem";
  45 
  46 
  47 int MPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr)
  48 {
  49     char info_value[MPI_MAX_INFO_VAL + 1];
  50     char *mpool_hints = NULL;
  51 
  52     if (MPI_PARAM_CHECK) {
  53         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  54         if (size < 0 || NULL == baseptr) {
  55             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
  56                                           FUNC_NAME);
  57         } else if (NULL == info || ompi_info_is_freed(info)) {
  58             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_INFO,
  59                                           FUNC_NAME);
  60         }
  61     }
  62 
  63     /* Per these threads:
  64 
  65          http://www.open-mpi.org/community/lists/devel/2007/07/1977.php
  66          http://www.open-mpi.org/community/lists/devel/2007/07/1979.php
  67 
  68        If you call MPI_ALLOC_MEM with a size of 0, you get NULL
  69        back .*/
  70     if (0 == size) {
  71         *((void **) baseptr) = NULL;
  72         return MPI_SUCCESS;
  73     }
  74 
  75     OPAL_CR_ENTER_LIBRARY();
  76 
  77     if (MPI_INFO_NULL != info) {
  78         int flag;
  79         (void) ompi_info_get (info, "mpool_hints", MPI_MAX_INFO_VAL, info_value, &flag);
  80         if (flag) {
  81             mpool_hints = info_value;
  82         }
  83     }
  84 
  85     *((void **) baseptr) = mca_mpool_base_alloc ((size_t) size, (struct opal_info_t*)info,
  86                                                  mpool_hints);
  87     OPAL_CR_EXIT_LIBRARY();
  88     if (NULL == *((void **) baseptr)) {
  89         return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_NO_MEM,
  90                                       FUNC_NAME);
  91     }
  92 
  93     /* All done */
  94     return MPI_SUCCESS;
  95 }
  96 

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