1 //------------------------------------------------------------------------------
2 // gb_usage: check usage and make sure GrB.init has been called
3 //------------------------------------------------------------------------------
4 
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: GPL-3.0-or-later
7 
8 //------------------------------------------------------------------------------
9 
10 #include "gb_matlab.h"
11 
gb_usage(bool ok,const char * usage)12 void gb_usage       // check usage and make sure GrB.init has been called
13 (
14     bool ok,                // if false, then usage is not correct
15     const char *usage       // error message if usage is not correct
16 )
17 {
18 
19     //--------------------------------------------------------------------------
20     // clear the debug memory table (for debugging only)
21     //--------------------------------------------------------------------------
22 
23     GB_Global_memtable_clear ( ) ;
24 
25     //--------------------------------------------------------------------------
26     // make sure GrB.init has been called
27     //--------------------------------------------------------------------------
28 
29     if (!GB_Global_GrB_init_called_get ( )) // TODO::: add this as GxB_get
30     {
31 
32         //----------------------------------------------------------------------
33         // initialize GraphBLAS
34         //----------------------------------------------------------------------
35 
36         OK (GxB_init (GrB_NONBLOCKING, mxMalloc, mxCalloc, mxRealloc, mxFree,
37             false)) ;
38 
39         // must use mexPrintf to print to MATLAB Command Window
40         OK (GxB_Global_Option_set (GxB_PRINTF, mexPrintf)) ;
41         OK (GxB_Global_Option_set (GxB_FLUSH, gb_flush)) ;
42 
43         // disable the memory pool
44         int64_t free_pool_limit [64] =
45             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
46              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } ;
47         OK (GxB_Global_Option_set (GxB_MEMORY_POOL, free_pool_limit)) ;
48 
49         // MATLAB matrices are stored by column
50         OK (GxB_Global_Option_set (GxB_FORMAT, GxB_BY_COL)) ;
51 
52         // print 1-based indices
53         GB_Global_print_one_based_set (true) ;      // TODO:: add to GxB_set/get
54 
55         // for debug only
56         GB_Global_abort_function_set (gb_abort) ;   // TODO:: add as GxB_set/get
57     }
58 
59     //--------------------------------------------------------------------------
60     // check usage
61     //--------------------------------------------------------------------------
62 
63     if (!ok)
64     {
65         ERROR (usage) ;
66     }
67 
68     //--------------------------------------------------------------------------
69     // get test coverage
70     //--------------------------------------------------------------------------
71 
72     #ifdef GBCOV
73     gbcov_get ( ) ;
74     #endif
75 }
76 
77