1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
//------------------------------------------------------------------------------
// GB_mx_get_global: get variables from the global workspace
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
#include "GB_mex.h"
#include "../Source/jitifyer/GB_jitifyer.h"
bool GB_mx_get_global // true if doing malloc_debug
(
bool cover // true if doing statement coverage
)
{
//--------------------------------------------------------------------------
// get malloc debug
//--------------------------------------------------------------------------
bool malloc_debug = false ;
bool *debug = NULL ;
const mxArray *debug_builtin = NULL ;
debug_builtin = mexGetVariablePtr ("global", "GraphBLAS_debug") ;
if (debug_builtin == NULL || mxIsEmpty (debug_builtin))
{
// doesn't exist; create it and set it to false
debug_builtin = GB_mx_create_full (1, 1, GrB_BOOL) ;
debug = (bool *) mxGetData (debug_builtin) ;
if (debug == NULL) mexErrMsgTxt ("debug_builtin null?!") ;
debug [0] = false ;
// copy it into the global workspace
mexPutVariable ("global", "GraphBLAS_debug", debug_builtin) ;
}
else
{
debug = (bool *) mxGetData (debug_builtin) ;
if (debug == NULL) mexErrMsgTxt ("debug_builtin null!") ;
malloc_debug = debug [0] ;
}
//--------------------------------------------------------------------------
// get test coverage
//--------------------------------------------------------------------------
GB_cover_get (cover) ;
//--------------------------------------------------------------------------
// initialize GraphBLAS
//--------------------------------------------------------------------------
// save current burble
bool burble = GB_Global_burble_get ( ) ;
// save JIT control
int control = GB_jitifyer_get_control ( ) ;
if (!GB_Global_GrB_init_called_get ( ))
{
// call GxB_init (see also gb_usage in @GrB)
mexAtExit (GB_mx_at_exit) ;
GB_Global_persistent_set (mexMakeMemoryPersistent) ;
GxB_init (GrB_NONBLOCKING, mxMalloc, mxCalloc, mxRealloc, mxFree) ;
}
// mxMalloc, mxCalloc, mxRealloc, and mxFree are not thread safe
GB_Global_malloc_is_thread_safe_set (false) ;
ASSERT (GB_Global_nmalloc_get ( ) == 0) ;
GB_Global_abort_set (GB_mx_abort) ;
GB_Global_malloc_tracking_set (true) ;
GxB_Global_Option_set_(GxB_FORMAT, GxB_BY_COL) ;
GxB_Global_Option_set_(GxB_PRINTF, mexPrintf) ;
// restore the burble
GxB_Global_Option_set_(GxB_BURBLE, burble) ;
// restore the JIT control
GB_jitifyer_set_control (control) ;
GxB_Global_Option_set_(GxB_JIT_C_CONTROL, control) ;
//--------------------------------------------------------------------------
// get nthreads
//--------------------------------------------------------------------------
int *nthreads = NULL ;
const mxArray *nthreads_builtin = NULL ;
nthreads_builtin = mexGetVariablePtr ("global", "GraphBLAS_nthreads") ;
if (nthreads_builtin == NULL || mxIsEmpty (nthreads_builtin))
{
// doesn't exist; create it and set it to 1
nthreads_builtin = GB_mx_create_full (1, 1, GrB_INT32) ;
nthreads = (int32_t *) mxGetData (nthreads_builtin) ;
if (nthreads == NULL) mexErrMsgTxt ("nthreads_builtin null?!") ;
nthreads [0] = 1 ;
// copy it into the global workspace
mexPutVariable ("global", "GraphBLAS_nthreads", nthreads_builtin) ;
}
else
{
nthreads = (int32_t *) mxGetData (nthreads_builtin) ;
if (nthreads == NULL) mexErrMsgTxt ("nthreads_builtin null!") ;
}
GxB_Global_Option_set_(GxB_NTHREADS, nthreads [0]) ;
//--------------------------------------------------------------------------
// get chunk
//--------------------------------------------------------------------------
double *chunk = NULL ;
const mxArray *chunk_builtin = NULL ;
chunk_builtin = mexGetVariablePtr ("global", "GraphBLAS_chunk") ;
if (chunk_builtin == NULL || mxIsEmpty (chunk_builtin))
{
// doesn't exist; create it and set it to GB_CHUNK_DEFAULT
chunk_builtin = GB_mx_create_full (1, 1, GrB_FP64) ;
chunk = (double *) mxGetData (chunk_builtin) ;
if (chunk == NULL) mexErrMsgTxt ("chunk_builtin null?!") ;
chunk [0] = GB_CHUNK_DEFAULT ;
// copy it into the global workspace
mexPutVariable ("global", "GraphBLAS_chunk", chunk_builtin) ;
}
else
{
chunk = (double *) mxGetData (chunk_builtin) ;
if (chunk == NULL) mexErrMsgTxt ("chunk_builtin null!") ;
}
GxB_Global_Option_set_(GxB_CHUNK, chunk [0]) ;
//--------------------------------------------------------------------------
// get GraphBLAS_complex flag and allocate the complex type and operators
//--------------------------------------------------------------------------
bool *builtin_complex = NULL ;
const mxArray *builtin_complex_builtin = NULL ;
builtin_complex_builtin =
mexGetVariablePtr ("global", "GraphBLAS_builtin_complex") ;
if (builtin_complex_builtin == NULL || mxIsEmpty (builtin_complex_builtin))
{
// doesn't exist; create it and set it to TRUE
builtin_complex_builtin = GB_mx_create_full (1, 1, GrB_BOOL) ;
builtin_complex = (bool *) mxGetData (builtin_complex_builtin) ;
if (builtin_complex == NULL)
{
mexErrMsgTxt ("builtin_complex_builtin null?!") ;
}
builtin_complex [0] = true ;
// copy it into the global workspace
mexPutVariable ("global", "GraphBLAS_builtin_complex",
builtin_complex_builtin) ;
}
else
{
builtin_complex = (bool *) mxGetData (builtin_complex_builtin) ;
if (builtin_complex == NULL)
{
mexErrMsgTxt ("builtin_complex_builtin null!") ;
}
}
Complex_init (builtin_complex [0]) ;
//--------------------------------------------------------------------------
// set the hyper_hash control to a small value
//--------------------------------------------------------------------------
GrB_Scalar s ;
GrB_Scalar_new (&s, GrB_INT64) ;
GrB_Scalar_setElement_INT64 (s, 8) ;
GrB_Global_set_Scalar (GrB_GLOBAL, s, GxB_HYPER_HASH) ;
GrB_Scalar_free (&s) ;
//--------------------------------------------------------------------------
// return malloc debug status
//--------------------------------------------------------------------------
return (malloc_debug) ;
}
|