1 //------------------------------------------------------------------------------
2 // GB_mex_init: initialize GraphBLAS
3 //------------------------------------------------------------------------------
4
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7
8 //------------------------------------------------------------------------------
9
10 // Returns the status of all global settings.
11
12 #include "GB_mex.h"
13
14 #define USAGE "[nthreads format hyper_switch " \
15 "name version date about license compiledate compiletime api api_about" \
16 " chunk bitmap_switch] = GB_mex_init"
17
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])18 void mexFunction
19 (
20 int nargout,
21 mxArray *pargout [ ],
22 int nargin,
23 const mxArray *pargin [ ]
24 )
25 {
26 mexPrintf ("usage:\n%s\n", USAGE) ;
27
28 GxB_init (GrB_NONBLOCKING, mxMalloc, NULL , NULL , mxFree, false) ;
29 // GxB_init (GrB_NONBLOCKING, mxMalloc, mxCalloc, mxRealloc, mxFree, false) ;
30 GB_Global_abort_function_set (GB_mx_abort) ;
31 GB_Global_malloc_tracking_set (true) ;
32
33 // MATLAB default is by column
34 GxB_Global_Option_set_(GxB_FORMAT, GxB_BY_COL) ;
35
36 int nthreads ;
37 GxB_Global_Option_get_(GxB_NTHREADS, &nthreads) ;
38 pargout [0] = mxCreateDoubleScalar (nthreads) ;
39
40 GxB_Format_Value format ;
41 GxB_Global_Option_get_(GxB_FORMAT, &format) ;
42 pargout [1] = mxCreateDoubleScalar (format) ;
43
44 double hyper_switch ;
45 GxB_Global_Option_get_(GxB_HYPER_SWITCH, &hyper_switch) ;
46 pargout [2] = mxCreateDoubleScalar (hyper_switch) ;
47
48 char *name ;
49 GxB_Global_Option_get_(GxB_LIBRARY_NAME, &name) ;
50 pargout [3] = mxCreateString (name) ;
51
52 int version [3] ;
53 GxB_Global_Option_get_(GxB_LIBRARY_VERSION, version) ;
54 pargout [4] = mxCreateDoubleMatrix (1, 3, mxREAL) ;
55 double *p = mxGetPr (pargout [4]) ;
56 p [0] = version [0] ;
57 p [1] = version [1] ;
58 p [2] = version [2] ;
59
60 char *date ;
61 GxB_Global_Option_get_(GxB_LIBRARY_DATE, &date) ;
62 pargout [5] = mxCreateString (date) ;
63
64 char *about ;
65 GxB_Global_Option_get_(GxB_LIBRARY_ABOUT, &about) ;
66 pargout [6] = mxCreateString (about) ;
67
68 char *license ;
69 GxB_Global_Option_get_(GxB_LIBRARY_LICENSE, &license) ;
70 pargout [7] = mxCreateString (license) ;
71
72 char *compile_date ;
73 GxB_Global_Option_get_(GxB_LIBRARY_COMPILE_DATE, &compile_date) ;
74 pargout [8] = mxCreateString (compile_date) ;
75
76 char *compile_time ;
77 GxB_Global_Option_get_(GxB_LIBRARY_COMPILE_TIME, &compile_time) ;
78 pargout [9] = mxCreateString (compile_time) ;
79
80 int api [3] ;
81 GxB_Global_Option_get_(GxB_API_VERSION, api) ;
82 pargout [10] = mxCreateDoubleMatrix (1, 3, mxREAL) ;
83 double *a = mxGetPr (pargout [10]) ;
84 a [0] = api [0] ;
85 a [1] = api [1] ;
86 a [2] = api [2] ;
87
88 char *api_about ;
89 GxB_Global_Option_get_(GxB_API_ABOUT, &api_about) ;
90 pargout [11] = mxCreateString (api_about) ;
91
92 double chunk ;
93 GxB_Global_Option_get_(GxB_CHUNK, &chunk) ;
94 pargout [12] = mxCreateDoubleScalar (chunk) ;
95
96 double bitmap_switch [GxB_NBITMAP_SWITCH] ;
97 GxB_Global_Option_get_(GxB_BITMAP_SWITCH, bitmap_switch) ;
98 pargout [13] = mxCreateDoubleMatrix (1, GxB_NBITMAP_SWITCH, mxREAL) ;
99 double *bswitch = mxGetPr (pargout [13]) ;
100 for (int k = 0 ; k < GxB_NBITMAP_SWITCH ; k++)
101 {
102 bswitch [k] = bitmap_switch [k] ;
103 }
104
105 for (int k = 0 ; k < GxB_NBITMAP_SWITCH ; k++)
106 {
107 printf ("bitmap_switch [%d] = %g ", k, bswitch [k]) ;
108 if (k == 0)
109 {
110 printf ("for vectors and matrices with 1 row or column\n") ;
111 }
112 else if (k == GxB_NBITMAP_SWITCH - 1)
113 {
114 printf ("for matrices with min dimension > %d\n", 1 << (k-1)) ;
115 }
116 else
117 {
118 printf ("for matrices with min dimension %d to %d\n",
119 (1 << (k-1)) + 1, 1 << k) ;
120 }
121 }
122
123 // #include "GB_Test_init_mkl_template.c"
124
125 GrB_finalize ( ) ;
126 }
127
128