1 //------------------------------------------------------------------------------
2 // GB_mx_put_global: put the GraphBLAS status in MATLAB workspace
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 #include "GB_mex.h"
11 
GB_mx_put_global(bool cover)12 void GB_mx_put_global
13 (
14     bool cover
15 )
16 {
17 
18     //--------------------------------------------------------------------------
19     // free the complex type and operators
20     //--------------------------------------------------------------------------
21 
22     Complex_finalize ( ) ;
23 
24     //--------------------------------------------------------------------------
25     // return the time to MATLAB, if it was computed
26     //--------------------------------------------------------------------------
27 
28     GB_mx_put_time ( ) ;
29 
30     //--------------------------------------------------------------------------
31     // log the statement coverage
32     //--------------------------------------------------------------------------
33 
34     #ifdef GBCOVER
35     if (cover) GB_cover_put ( ) ;
36     #endif
37 
38     //--------------------------------------------------------------------------
39     // finalize GraphBLAS
40     //--------------------------------------------------------------------------
41 
42     GrB_finalize ( ) ;
43 
44     // disable the memory pool, in case a @GrB method is called next
45     int64_t free_pool_limit [64] =
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          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 } ;
48     GxB_Global_Option_set (GxB_MEMORY_POOL, free_pool_limit) ;
49 
50     //--------------------------------------------------------------------------
51     // check nmemtable and nmalloc
52     //--------------------------------------------------------------------------
53 
54     int nmemtable = GB_Global_memtable_n ( ) ;
55     if (nmemtable != 0)
56     {
57         printf ("in GB_mx_put_global: GraphBLAS nmemtable %d!\n", nmemtable) ;
58         GB_Global_free_pool_dump (2) ;
59         GB_Global_memtable_dump ( ) ;
60         mexErrMsgTxt ("memory leak in test!") ;
61     }
62 
63     int64_t nblocks = GB_Global_free_pool_nblocks_total ( ) ;
64     if (nblocks != 0)
65     {
66         printf ("in GB_mx_put_global: GraphBLAS nblocks "GBd" in free_pool!\n",
67             nblocks) ;
68         GB_Global_free_pool_dump (2) ;
69         GB_Global_memtable_dump ( ) ;
70         mexErrMsgTxt ("memory leak in test!") ;
71     }
72 
73     int64_t nmalloc = GB_Global_nmalloc_get ( ) ;
74     if (nmalloc != 0)
75     {
76         printf ("in GB_mx_put_global: GraphBLAS nmalloc "GBd"!\n", nmalloc) ;
77         GB_Global_free_pool_dump (2) ;
78         GB_Global_memtable_dump ( ) ;
79         mexErrMsgTxt ("memory leak in test!") ;
80     }
81 
82     //--------------------------------------------------------------------------
83     // allow GrB_init to be called again
84     //--------------------------------------------------------------------------
85 
86     GB_Global_GrB_init_called_set (false) ;
87 }
88 
89