root/test/mpool/mpool_memkind.c

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

DEFINITIONS

This source file includes following definitions.
  1. main
  2. main

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2016      Research Organization for Information Science
  13  *                         and Technology (RIST). All rights reserved.
  14  * Copyright (c) 2018      Los Alamos National Security, LLC.  All rights reserved.
  15  * $COPYRIGHT$
  16  *
  17  * Additional copyrights may follow
  18  *
  19  * $HEADER$
  20  */
  21 
  22 /*
  23  * only do this test if we have built with memkind support
  24  */
  25 
  26 #include <stdio.h>
  27 #include <string.h>
  28 #include <stdlib.h>
  29 #include "opal_config.h"
  30 #ifdef HAVE_MEMKIND_H
  31 #include "opal/constants.h"
  32 #include "opal/mca/mpool/mpool.h"
  33 #include "opal/include/opal/frameworks.h"
  34 #include "opal/runtime/opal.h"
  35 
  36 #define SIZE (2 * 1024 * 1024)
  37 
  38 const char *memory_types[] = {
  39   "memkind_default",
  40   "memkind_hbw",
  41    NULL
  42 };
  43 
  44 const char *memory_policy[] = {
  45    "mempolicy_bind_local",
  46    "mempolicy_bind_all",
  47    "mempolicy_perferred_local",
  48    "mempolicy_interleave_local",
  49    "mempolicy_interleave_all",
  50    NULL
  51 };
  52 
  53 const char *memory_kind_bits[] = {
  54    "memkind_mask_page_size_4KB",
  55    "memkind_mask_page_size_2MB",
  56    NULL
  57 };
  58 
  59 int main (int argc, char* argv[])
  60 {
  61     int ret = 0;
  62     void *ptr = NULL;
  63     char *error = NULL;
  64     char **mp_ptr = NULL;
  65     char **mt_ptr = NULL;
  66     char **mk_ptr = NULL;
  67     const char mpool_hints[] = "mpool=memkind";
  68     char hints[1024];
  69 
  70     opal_init_util(&argc, &argv);
  71 
  72     if (opal_frameworks == NULL){
  73         error = "opal frameworks is NULL";
  74         goto error;
  75     }
  76 
  77     if (OPAL_SUCCESS != (ret = mca_base_framework_open(&opal_allocator_base_framework, 0))) {
  78         error = "mca_allocator_base_open() failed";
  79         goto error;
  80     }
  81 
  82     if (OPAL_SUCCESS != (ret = mca_base_framework_open(&opal_mpool_base_framework, 0))) {
  83         error = "mca_mpool_base_open() failed";
  84         goto error;
  85     }
  86 
  87     /*
  88      * first try basic allocation
  89      */
  90 
  91     ptr = mca_mpool_base_alloc(SIZE, NULL, mpool_hints);
  92     if (NULL == ptr) {
  93         error = "mca_mpool_base_alloc() failed";
  94         goto error;
  95     }
  96 
  97     if (OPAL_SUCCESS != mca_mpool_base_free(ptr)) {
  98         error = "mca_mpool_base_free() failed";
  99         goto error;
 100     }
 101 
 102     /*
 103      * now try policies
 104      */
 105 
 106     mp_ptr = (char **)memory_policy;
 107     while (NULL != *mp_ptr) {
 108 
 109         mt_ptr = (char **)memory_types;
 110         while (NULL != *mt_ptr) {
 111 
 112             mk_ptr = (char **)memory_kind_bits;
 113             while (NULL != *mk_ptr) {
 114                 snprintf(hints, sizeof(hints), "%s,policy=%s,type=%s,kind=%s", 
 115                          mpool_hints, *mp_ptr, *mt_ptr, *mk_ptr);
 116                 ptr = mca_mpool_base_alloc(SIZE, NULL, hints);
 117                 if (NULL == ptr) {
 118                     error = "mca_mpool_base_alloc() failed";
 119                     goto error;
 120                 }
 121 
 122                 if (OPAL_SUCCESS != mca_mpool_base_free(ptr)) {
 123                     error = "mca_mpool_base_free() failed";
 124                     goto error;
 125                 }
 126                 mk_ptr++;
 127             }
 128             mt_ptr++;
 129         }
 130         mp_ptr++;
 131     }
 132 
 133     if (OPAL_SUCCESS != (ret = mca_base_framework_close(&opal_mpool_base_framework))) {
 134         error = "mca_mpool_base_close() failed";
 135         goto error;
 136     }
 137 
 138     if (OPAL_SUCCESS != (ret = mca_base_framework_close(&opal_allocator_base_framework))) {
 139         error = "mca_mpool_base_close() failed";
 140         goto error;
 141     }
 142 
 143     opal_finalize();
 144 
 145 error:
 146     if (NULL != error) {
 147         fprintf(stderr, "mpool/memkind test failed %s\n", error);
 148         ret = -1;
 149     } else {
 150         fprintf(stderr, "mpool/memkind test passed\n");
 151     }
 152 
 153     return ret;
 154 }
 155 #else
 156 int main (int argc, char* argv[])
 157 {
 158     return 77;
 159 }
 160 #endif /* HAVE_MEMKIND_H */

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