From d6e68b3454c0c87fd5ff8a6a3ff4e9416f91a513 Mon Sep 17 00:00:00 2001 From: Tim Davis Date: Wed, 16 Mar 2022 18:15:00 -0500 Subject: [PATCH] revise LAGraph memory wrappers: return int, add msg --- experimental/algorithm/LAGraph_BF_full.c | 31 ++++--- experimental/algorithm/LAGraph_BF_full1.c | 46 +++++----- experimental/algorithm/LAGraph_BF_full1a.c | 44 +++++---- experimental/algorithm/LAGraph_BF_full2.c | 46 +++++----- experimental/algorithm/LAGraph_BF_full_mxv.c | 46 +++++----- experimental/algorithm/LAGraph_BF_pure_c.c | 17 ++-- .../algorithm/LAGraph_BF_pure_c_double.c | 17 ++-- experimental/algorithm/LAGraph_cdlp.c | 42 ++++----- experimental/algorithm/LG_CC_FastSV5.c | 68 ++++++++------ experimental/test/LG_check_ktruss.c | 13 ++- experimental/test/LG_check_mis.c | 13 ++- experimental/test/test_AllKtruss.c | 58 ++++++------ experimental/test/test_BF.c | 28 +++--- experimental/test/test_SSaveSet.c | 6 +- experimental/test/test_SWrite.c | 29 +++--- experimental/utility/LAGraph_Random_Matrix.c | 86 +++++++++-------- experimental/utility/LAGraph_SFreeContents.c | 4 +- experimental/utility/LAGraph_SFreeSet.c | 2 +- experimental/utility/LAGraph_SLoadSet.c | 10 +- experimental/utility/LAGraph_SRead.c | 28 +++--- experimental/utility/LAGraph_SSaveSet.c | 14 ++- include/LAGraph.h | 92 +++++++++---------- 22 files changed, 366 insertions(+), 374 deletions(-) diff --git a/experimental/algorithm/LAGraph_BF_full.c b/experimental/algorithm/LAGraph_BF_full.c index d75174bda6..d0258d3004 100644 --- a/experimental/algorithm/LAGraph_BF_full.c +++ b/experimental/algorithm/LAGraph_BF_full.c @@ -42,12 +42,12 @@ GrB_free(&BF_EQ_Tuple3); \ GrB_free(&BF_lMIN_Tuple3_Monoid); \ GrB_free(&BF_lMIN_PLUSrhs_Tuple3); \ - LAGraph_Free ((void**)&I); \ - LAGraph_Free ((void**)&J); \ - LAGraph_Free ((void**)&w); \ - LAGraph_Free ((void**)&W); \ - LAGraph_Free ((void**)&h); \ - LAGraph_Free ((void**)&pi); \ + LAGraph_Free ((void**)&I, NULL); \ + LAGraph_Free ((void**)&J, NULL); \ + LAGraph_Free ((void**)&w, NULL); \ + LAGraph_Free ((void**)&W, NULL); \ + LAGraph_Free ((void**)&h, NULL); \ + LAGraph_Free ((void**)&pi, NULL); \ } #include @@ -198,12 +198,12 @@ GrB_Info LAGraph_BF_full //-------------------------------------------------------------------------- // allocate arrays used for tuplets //-------------------------------------------------------------------------- - I = LAGraph_Malloc (nz, sizeof(GrB_Index)) ; - J = LAGraph_Malloc (nz, sizeof(GrB_Index)) ; - w = LAGraph_Malloc (nz, sizeof(double)) ; - W = LAGraph_Malloc (nz, sizeof(BF_Tuple3_struct)) ; - LG_ASSERT (I != NULL && J != NULL && w != NULL && W != NULL, - GrB_OUT_OF_MEMORY) ; + + LAGRAPH_TRY (LAGraph_Malloc ((void **) &I, nz, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &J, nz, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &w, nz, sizeof(double), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &W, nz, sizeof(BF_Tuple3_struct), + msg)) ; //-------------------------------------------------------------------------- // create matrix Atmp based on A, while its entries become BF_Tuple3 type @@ -281,10 +281,11 @@ GrB_Info LAGraph_BF_full //-------------------------------------------------------------------------- // extract tuple from "distance" vector d and create GrB_Vectors for output //-------------------------------------------------------------------------- + GRB_TRY (GrB_Vector_extractTuples_UDT (I, (void *) W, &nz, d)); - h = LAGraph_Malloc (nz, sizeof(GrB_Index)) ; - pi = LAGraph_Malloc (nz, sizeof(GrB_Index)) ; - LG_ASSERT (w != NULL && h != NULL && pi != NULL, GrB_OUT_OF_MEMORY) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &h , nz, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &pi, nz, sizeof(GrB_Index), msg)) ; + for (GrB_Index k = 0; k < nz; k++) { w [k] = W[k].w ; diff --git a/experimental/algorithm/LAGraph_BF_full1.c b/experimental/algorithm/LAGraph_BF_full1.c index a1ec6715d4..b295808223 100644 --- a/experimental/algorithm/LAGraph_BF_full1.c +++ b/experimental/algorithm/LAGraph_BF_full1.c @@ -50,12 +50,12 @@ GrB_free(&BF_LT_Tuple3); \ GrB_free(&BF_lMIN_Tuple3_Monoid); \ GrB_free(&BF_lMIN_PLUSrhs_Tuple3); \ - LAGraph_Free ((void**)&I); \ - LAGraph_Free ((void**)&J); \ - LAGraph_Free ((void**)&w); \ - LAGraph_Free ((void**)&W); \ - LAGraph_Free ((void**)&h); \ - LAGraph_Free ((void**)&pi); \ + LAGraph_Free ((void**)&I, NULL); \ + LAGraph_Free ((void**)&J, NULL); \ + LAGraph_Free ((void**)&w, NULL); \ + LAGraph_Free ((void**)&W, NULL); \ + LAGraph_Free ((void**)&h, NULL); \ + LAGraph_Free ((void**)&pi, NULL); \ } #define LG_FREE_ALL \ @@ -228,12 +228,12 @@ GrB_Info LAGraph_BF_full1 //-------------------------------------------------------------------------- // allocate arrays used for tuplets //-------------------------------------------------------------------------- - I = LAGraph_Malloc (nz, sizeof(GrB_Index)) ; - J = LAGraph_Malloc (nz, sizeof(GrB_Index)) ; - w = LAGraph_Malloc (nz, sizeof(double)) ; - W = LAGraph_Malloc (nz, sizeof(BF1_Tuple3_struct)) ; - LG_ASSERT (I != NULL && J != NULL && w != NULL && W != NULL, - GrB_OUT_OF_MEMORY) ; + + LAGRAPH_TRY (LAGraph_Malloc ((void **) &I, nz, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &J, nz, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &w, nz, sizeof(double), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &W, nz, sizeof(BF1_Tuple3_struct), + msg)) ; //-------------------------------------------------------------------------- // create matrix Atmp based on A, while its entries become BF_Tuple3 type @@ -249,10 +249,10 @@ GrB_Info LAGraph_BF_full1 } GRB_TRY (GrB_Matrix_new(&Atmp, BF_Tuple3, n, n)); GRB_TRY (GrB_Matrix_build_UDT(Atmp, I, J, W, nz, BF_lMIN_Tuple3)); - LAGraph_Free ((void**)&I); - LAGraph_Free ((void**)&J); - LAGraph_Free ((void**)&W); - LAGraph_Free ((void**)&w); + LAGraph_Free ((void**)&I, NULL); + LAGraph_Free ((void**)&J, NULL); + LAGraph_Free ((void**)&W, NULL); + LAGraph_Free ((void**)&w, NULL); //-------------------------------------------------------------------------- // create and initialize "distance" vector d, dmasked and dless @@ -334,13 +334,13 @@ GrB_Info LAGraph_BF_full1 //-------------------------------------------------------------------------- // extract tuple from "distance" vector d and create GrB_Vectors for output //-------------------------------------------------------------------------- - I = LAGraph_Malloc (n, sizeof(GrB_Index)) ; - W = LAGraph_Malloc (n, sizeof(BF1_Tuple3_struct)) ; - w = LAGraph_Malloc (n, sizeof(double)) ; - h = LAGraph_Malloc (n, sizeof(GrB_Index)) ; - pi = LAGraph_Malloc (n, sizeof(GrB_Index)) ; - LG_ASSERT (I != NULL && W != NULL && w != NULL && h != NULL && pi != NULL, - GrB_OUT_OF_MEMORY) ; + + LAGRAPH_TRY (LAGraph_Malloc ((void **) &I, n, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &W, n, sizeof(BF1_Tuple3_struct), + msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &w, n, sizeof(double), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &h, n, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &pi, n, sizeof(GrB_Index), msg)) ; GRB_TRY (GrB_Vector_extractTuples_UDT (I, (void *) W, &n, d)); diff --git a/experimental/algorithm/LAGraph_BF_full1a.c b/experimental/algorithm/LAGraph_BF_full1a.c index 26edb8d598..0d636867e1 100644 --- a/experimental/algorithm/LAGraph_BF_full1a.c +++ b/experimental/algorithm/LAGraph_BF_full1a.c @@ -52,12 +52,12 @@ GrB_free(&BF_LT_Tuple3); \ GrB_free(&BF_lMIN_Tuple3_Monoid); \ GrB_free(&BF_lMIN_PLUSrhs_Tuple3); \ - LAGraph_Free ((void**)&I); \ - LAGraph_Free ((void**)&J); \ - LAGraph_Free ((void**)&w); \ - LAGraph_Free ((void**)&W); \ - LAGraph_Free ((void**)&h); \ - LAGraph_Free ((void**)&pi); \ + LAGraph_Free ((void**)&I, NULL); \ + LAGraph_Free ((void**)&J, NULL); \ + LAGraph_Free ((void**)&w, NULL); \ + LAGraph_Free ((void**)&W, NULL); \ + LAGraph_Free ((void**)&h, NULL); \ + LAGraph_Free ((void**)&pi, NULL); \ } #define LG_FREE_ALL \ @@ -221,12 +221,11 @@ GrB_Info LAGraph_BF_full1a // allocate arrays used for tuplets //-------------------------------------------------------------------------- #if 1 - I = LAGraph_Malloc (nz, sizeof(GrB_Index)) ; - J = LAGraph_Malloc (nz, sizeof(GrB_Index)) ; - w = LAGraph_Malloc (nz, sizeof(double)) ; - W = LAGraph_Malloc (nz, sizeof(BF_Tuple3_struct)) ; - LG_ASSERT (I != NULL && J != NULL && w != NULL && W != NULL, - GrB_OUT_OF_MEMORY) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &I, nz, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &J, nz, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &w, nz, sizeof(double), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &W, nz, sizeof(BF_Tuple3_struct), + msg)) ; //-------------------------------------------------------------------------- // create matrix Atmp based on A, while its entries become BF_Tuple3 type @@ -242,10 +241,10 @@ GrB_Info LAGraph_BF_full1a } GRB_TRY (GrB_Matrix_new(&Atmp, BF_Tuple3, n, n)); GRB_TRY (GrB_Matrix_build_UDT(Atmp, I, J, W, nz, BF_lMIN_Tuple3)); - LAGraph_Free ((void**)&I); - LAGraph_Free ((void**)&J); - LAGraph_Free ((void**)&W); - LAGraph_Free ((void**)&w); + LAGraph_Free ((void**)&I, NULL); + LAGraph_Free ((void**)&J, NULL); + LAGraph_Free ((void**)&W, NULL); + LAGraph_Free ((void**)&w, NULL); #else @@ -357,13 +356,12 @@ GrB_Info LAGraph_BF_full1a // extract tuple from "distance" vector d and create GrB_Vectors for output //-------------------------------------------------------------------------- - I = LAGraph_Malloc (n, sizeof(GrB_Index)) ; - W = LAGraph_Malloc (n, sizeof(BF_Tuple3_struct)) ; - w = LAGraph_Malloc (n, sizeof(double)) ; - h = LAGraph_Malloc (n, sizeof(GrB_Index)) ; - pi = LAGraph_Malloc (n, sizeof(GrB_Index)) ; - LG_ASSERT (I != NULL && W != NULL && w != NULL && h != NULL && pi != NULL, - GrB_OUT_OF_MEMORY) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &I, n, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &W, n, sizeof(BF_Tuple3_struct), + msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &w, n, sizeof(double), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &h, n, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &pi, n, sizeof(GrB_Index), msg)) ; // todo: create 3 unary ops, and use GrB_apply? diff --git a/experimental/algorithm/LAGraph_BF_full2.c b/experimental/algorithm/LAGraph_BF_full2.c index 2028194b4d..e9e6f52a9f 100644 --- a/experimental/algorithm/LAGraph_BF_full2.c +++ b/experimental/algorithm/LAGraph_BF_full2.c @@ -51,12 +51,12 @@ GrB_free(&BF_EQ_Tuple3); \ GrB_free(&BF_lMIN_Tuple3_Monoid); \ GrB_free(&BF_lMIN_PLUSrhs_Tuple3); \ - LAGraph_Free ((void**)&I); \ - LAGraph_Free ((void**)&J); \ - LAGraph_Free ((void**)&w); \ - LAGraph_Free ((void**)&W); \ - LAGraph_Free ((void**)&h); \ - LAGraph_Free ((void**)&pi); \ + LAGraph_Free ((void**)&I, NULL); \ + LAGraph_Free ((void**)&J, NULL); \ + LAGraph_Free ((void**)&w, NULL); \ + LAGraph_Free ((void**)&W, NULL); \ + LAGraph_Free ((void**)&h, NULL); \ + LAGraph_Free ((void**)&pi, NULL); \ } #define LG_FREE_ALL \ @@ -218,12 +218,12 @@ GrB_Info LAGraph_BF_full2 //-------------------------------------------------------------------------- // allocate arrays used for tuplets //-------------------------------------------------------------------------- - I = LAGraph_Malloc (nz, sizeof(GrB_Index)) ; - J = LAGraph_Malloc (nz, sizeof(GrB_Index)) ; - w = LAGraph_Malloc (nz, sizeof(double)) ; - W = LAGraph_Malloc (nz, sizeof(BF2_Tuple3_struct)) ; - LG_ASSERT (I != NULL && J != NULL && w != NULL && W != NULL, - GrB_OUT_OF_MEMORY) ; + + LAGRAPH_TRY (LAGraph_Malloc ((void **) &I, nz, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &J, nz, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &w, nz, sizeof(double), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &W, nz, sizeof(BF2_Tuple3_struct), + msg)) ; //-------------------------------------------------------------------------- // create matrix Atmp based on A, while its entries become BF_Tuple3 type @@ -246,10 +246,10 @@ GrB_Info LAGraph_BF_full2 } GRB_TRY (GrB_Matrix_new(&Atmp, BF_Tuple3, n, n)); GRB_TRY (GrB_Matrix_build_UDT(Atmp, I, J, W, nz, BF_lMIN_Tuple3)); - LAGraph_Free ((void**)&I); - LAGraph_Free ((void**)&J); - LAGraph_Free ((void**)&W); - LAGraph_Free ((void**)&w); + LAGraph_Free ((void**)&I, NULL); + LAGraph_Free ((void**)&J, NULL); + LAGraph_Free ((void**)&W, NULL); + LAGraph_Free ((void**)&w, NULL); //-------------------------------------------------------------------------- // create and initialize "distance" vector d @@ -314,13 +314,13 @@ GrB_Info LAGraph_BF_full2 //-------------------------------------------------------------------------- // extract tuple from "distance" vector d and create GrB_Vectors for output //-------------------------------------------------------------------------- - I = LAGraph_Malloc (n, sizeof(GrB_Index)) ; - W = LAGraph_Malloc (n, sizeof(BF2_Tuple3_struct)) ; - w = LAGraph_Malloc (n, sizeof(double)) ; - h = LAGraph_Malloc (n, sizeof(GrB_Index)) ; - pi = LAGraph_Malloc (n, sizeof(GrB_Index)) ; - LG_ASSERT (I != NULL && W != NULL && w != NULL && h != NULL && pi != NULL, - GrB_OUT_OF_MEMORY) ; + + LAGRAPH_TRY (LAGraph_Malloc ((void **) &I, n, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &W, n, sizeof(BF2_Tuple3_struct), + msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &w, n, sizeof(double), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &h, n, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &pi, n, sizeof(GrB_Index), msg)) ; nz = n ; GRB_TRY (GrB_Vector_extractTuples_UDT (I, (void *) W, &nz, d)); diff --git a/experimental/algorithm/LAGraph_BF_full_mxv.c b/experimental/algorithm/LAGraph_BF_full_mxv.c index 27872dc4ad..e9ba5082a9 100644 --- a/experimental/algorithm/LAGraph_BF_full_mxv.c +++ b/experimental/algorithm/LAGraph_BF_full_mxv.c @@ -53,12 +53,12 @@ GrB_free(&BF_EQ_Tuple3); \ GrB_free(&BF_lMIN_Tuple3_Monoid); \ GrB_free(&BF_lMIN_PLUSrhs_Tuple3); \ - LAGraph_Free ((void**)&I); \ - LAGraph_Free ((void**)&J); \ - LAGraph_Free ((void**)&w); \ - LAGraph_Free ((void**)&W); \ - LAGraph_Free ((void**)&h); \ - LAGraph_Free ((void**)&pi); \ + LAGraph_Free ((void**)&I, NULL); \ + LAGraph_Free ((void**)&J, NULL); \ + LAGraph_Free ((void**)&w, NULL); \ + LAGraph_Free ((void**)&W, NULL); \ + LAGraph_Free ((void**)&h, NULL); \ + LAGraph_Free ((void**)&pi, NULL); \ } #define LG_FREE_ALL \ @@ -221,12 +221,12 @@ GrB_Info LAGraph_BF_full_mxv //-------------------------------------------------------------------------- // allocate arrays used for tuplets //-------------------------------------------------------------------------- - I = LAGraph_Malloc (nz, sizeof(GrB_Index)) ; - J = LAGraph_Malloc (nz, sizeof(GrB_Index)) ; - w = LAGraph_Malloc (nz, sizeof(double)) ; - W = LAGraph_Malloc (nz, sizeof(BF_Tuple3_struct)) ; - LG_ASSERT (I != NULL && J != NULL && w != NULL && W != NULL, - GrB_OUT_OF_MEMORY) ; + + LAGRAPH_TRY (LAGraph_Malloc ((void **) &I, nz, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &J, nz, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &w, nz, sizeof(double), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &W, nz, sizeof(BF_Tuple3_struct), + msg)) ; //-------------------------------------------------------------------------- // create matrix Atmp based on AT, while its entries become BF_Tuple3 type @@ -247,10 +247,10 @@ GrB_Info LAGraph_BF_full_mxv } GRB_TRY (GrB_Matrix_new(&Atmp, BF_Tuple3, n, n)); GRB_TRY (GrB_Matrix_build_UDT(Atmp, I, J, W, nz, BF_lMIN_Tuple3)); - LAGraph_Free ((void**)&I); - LAGraph_Free ((void**)&J); - LAGraph_Free ((void**)&W); - LAGraph_Free ((void**)&w); + LAGraph_Free ((void**)&I, NULL); + LAGraph_Free ((void**)&J, NULL); + LAGraph_Free ((void**)&W, NULL); + LAGraph_Free ((void**)&w, NULL); //-------------------------------------------------------------------------- // create and initialize "distance" vector d @@ -305,13 +305,13 @@ GrB_Info LAGraph_BF_full_mxv //-------------------------------------------------------------------------- // extract tuple from "distance" vector d and create GrB_Vectors for output //-------------------------------------------------------------------------- - I = LAGraph_Malloc (n, sizeof(GrB_Index)) ; - W = LAGraph_Malloc (n, sizeof(BF_Tuple3_struct)) ; - w = LAGraph_Malloc (n, sizeof(double)) ; - h = LAGraph_Malloc (n, sizeof(GrB_Index)) ; - pi = LAGraph_Malloc (n, sizeof(GrB_Index)) ; - LG_ASSERT (I != NULL && W != NULL && w != NULL && h != NULL && pi != NULL, - GrB_OUT_OF_MEMORY) ; + + LAGRAPH_TRY (LAGraph_Malloc ((void **) &I, n, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &W, n, sizeof(BF_Tuple3_struct), + msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &w, n, sizeof(double), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &h, n, sizeof(GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &pi, n, sizeof(GrB_Index), msg)) ; nz = n ; GRB_TRY (GrB_Vector_extractTuples_UDT (I, (void *) W, &nz, d)); diff --git a/experimental/algorithm/LAGraph_BF_pure_c.c b/experimental/algorithm/LAGraph_BF_pure_c.c index 0516a2932a..5d0af4776b 100644 --- a/experimental/algorithm/LAGraph_BF_pure_c.c +++ b/experimental/algorithm/LAGraph_BF_pure_c.c @@ -32,10 +32,10 @@ //------------------------------------------------------------------------------ -#define LG_FREE_ALL \ -{ \ - LAGraph_Free ((void**) &d) ; \ - LAGraph_Free ((void**) &pi) ; \ +#define LG_FREE_ALL \ +{ \ + LAGraph_Free ((void**) &d, NULL) ; \ + LAGraph_Free ((void**) &pi, NULL) ; \ } #include "LG_internal.h" @@ -68,15 +68,14 @@ GrB_Info LAGraph_BF_pure_c LG_ASSERT (I != NULL && J != NULL && W != NULL && pd != NULL && ppi != NULL, GrB_NULL_POINTER) ; - LAGraph_Free ((void **) pd) ; - LAGraph_Free ((void **) ppi) ; + LAGraph_Free ((void **) pd, NULL) ; + LAGraph_Free ((void **) ppi, NULL) ; LG_ASSERT_MSG (s < n, GrB_INVALID_INDEX, "invalid source node") ; // allocate d and pi - d = LAGraph_Malloc(n, sizeof(int32_t)); - pi = LAGraph_Malloc(n, sizeof(int64_t)); - LG_ASSERT (d != NULL && pi != NULL, GrB_OUT_OF_MEMORY) ; + LAGRAPH_TRY (LAGraph_Malloc((void **) &d, n, sizeof(int32_t), msg)); + LAGRAPH_TRY (LAGraph_Malloc((void **) &pi, n, sizeof(int64_t), msg)); // initialize d to a vector of INF while set d(s) = 0 // and pi to a vector of -1 diff --git a/experimental/algorithm/LAGraph_BF_pure_c_double.c b/experimental/algorithm/LAGraph_BF_pure_c_double.c index a632948f19..61b1565108 100644 --- a/experimental/algorithm/LAGraph_BF_pure_c_double.c +++ b/experimental/algorithm/LAGraph_BF_pure_c_double.c @@ -34,10 +34,10 @@ //------------------------------------------------------------------------------ -#define LG_FREE_ALL \ -{ \ - LAGraph_Free ((void**) &d) ; \ - LAGraph_Free ((void**) &pi) ; \ +#define LG_FREE_ALL \ +{ \ + LAGraph_Free ((void**) &d, NULL) ; \ + LAGraph_Free ((void**) &pi, NULL) ; \ } #include "LG_internal.h" @@ -69,15 +69,14 @@ GrB_Info LAGraph_BF_pure_c_double LG_ASSERT (I != NULL && J != NULL && W != NULL && pd != NULL && ppi != NULL, GrB_NULL_POINTER) ; - LAGraph_Free ((void **) pd) ; - LAGraph_Free ((void **) ppi) ; + LAGraph_Free ((void **) pd, NULL) ; + LAGraph_Free ((void **) ppi, NULL) ; LG_ASSERT_MSG (s < n, GrB_INVALID_INDEX, "invalid source node") ; // allocate d and pi - d = LAGraph_Malloc(n, sizeof(double)); - pi = LAGraph_Malloc(n, sizeof(int64_t)); - LG_ASSERT (d != NULL && pi != NULL, GrB_OUT_OF_MEMORY) ; + LAGRAPH_TRY (LAGraph_Malloc((void **) &d, n, sizeof(double), msg)); + LAGRAPH_TRY (LAGraph_Malloc((void **) &pi, n, sizeof(int64_t), msg)); // initialize d to a vector of INF while set d(s) = 0 // and pi to a vector of -1 diff --git a/experimental/algorithm/LAGraph_cdlp.c b/experimental/algorithm/LAGraph_cdlp.c index 11d596b9a6..9102b8ab26 100644 --- a/experimental/algorithm/LAGraph_cdlp.c +++ b/experimental/algorithm/LAGraph_cdlp.c @@ -118,13 +118,13 @@ #define LG_FREE_ALL \ { \ - LAGraph_Free ((void *) &I) ; \ - LAGraph_Free ((void *) &X) ; \ - LAGraph_Free ((void *) &AI) ; \ - LAGraph_Free ((void *) &AJ) ; \ - LAGraph_Free ((void *) &AX) ; \ - LAGraph_Free ((void *) &X) ; \ - LAGraph_Free ((void *) &X) ; \ + LAGraph_Free ((void *) &I, NULL) ; \ + LAGraph_Free ((void *) &X, NULL) ; \ + LAGraph_Free ((void *) &AI, NULL) ; \ + LAGraph_Free ((void *) &AJ, NULL) ; \ + LAGraph_Free ((void *) &AX, NULL) ; \ + LAGraph_Free ((void *) &X, NULL) ; \ + LAGraph_Free ((void *) &X, NULL) ; \ GrB_free (&L) ; \ GrB_free (&L_prev) ; \ if (sanitize) GrB_free (&S) ; \ @@ -206,11 +206,11 @@ int LAGraph_cdlp { LAGraph_Tic (tic, NULL) ; - AI = LAGraph_Malloc(nz, sizeof(GrB_Index)); - AJ = LAGraph_Malloc(nz, sizeof(GrB_Index)); + LAGRAPH_TRY (LAGraph_Malloc ((void **) &AI, nz, sizeof(GrB_Index),msg)); + LAGRAPH_TRY (LAGraph_Malloc ((void **) &AJ, nz, sizeof(GrB_Index),msg)); GRB_TRY (GrB_Matrix_extractTuples_UINT64(AI, AJ, GrB_NULL, &nz, A)) - AX = LAGraph_Malloc(nz, sizeof(GrB_Index)); + LAGRAPH_TRY (LAGraph_Malloc ((void **) &AX, nz, sizeof(GrB_Index),msg)); GRB_TRY (GrB_Matrix_new(&S, GrB_UINT64, n, n)); GRB_TRY (GrB_Matrix_build(S, AI, AJ, AX, nz, GrB_PLUS_UINT64)); @@ -236,17 +236,16 @@ int LAGraph_cdlp #endif // Initialize L with diagonal elements 1..n - I = LAGraph_Malloc (n, sizeof (GrB_Index)) ; - X = LAGraph_Malloc (n, sizeof (GrB_Index)) ; - if (I == NULL || X == NULL) { LG_FREE_ALL ; return (GrB_OUT_OF_MEMORY) ; } + LAGRAPH_TRY (LAGraph_Malloc ((void **) &I, n, sizeof (GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &X, n, sizeof (GrB_Index), msg)) ; for (GrB_Index i = 0; i < n; i++) { I[i] = i; X[i] = i; } GRB_TRY (GrB_Matrix_new (&L, GrB_UINT64, n, n)) ; GRB_TRY (GrB_Matrix_build (L, I, I, X, n, GrB_PLUS_UINT64)) ; - LAGraph_Free ((void **)&I) ; I = NULL; - LAGraph_Free ((void **)&X) ; X = NULL; + LAGraph_Free ((void **) &I, NULL) ; + LAGraph_Free ((void **) &X, NULL) ; // Initialize matrix for storing previous labels GRB_TRY (GrB_Matrix_new(&L_prev, GrB_UINT64, n, n)) @@ -264,8 +263,8 @@ int LAGraph_cdlp for (int iteration = 0; iteration < itermax; iteration++) { // Initialize data structures for extraction from 'AL_in' and (for directed graphs) 'AL_out' - I = LAGraph_Malloc(nnz, sizeof(GrB_Index)); - X = LAGraph_Malloc(nnz, sizeof(GrB_Index)); + LAGRAPH_TRY (LAGraph_Malloc((void **) &I, nnz, sizeof(GrB_Index), msg)); + LAGRAPH_TRY (LAGraph_Malloc((void **) &X, nnz, sizeof(GrB_Index), msg)); // A = A min.2nd L // (using the "push" (saxpy) method) @@ -283,11 +282,6 @@ int LAGraph_cdlp GrB_NULL, &X[nz], &nz, AT)); } - //uint64_t *workspace1 = LAGraph_Malloc(nnz, sizeof(GrB_Index)); - //uint64_t *workspace2 = LAGraph_Malloc(nnz, sizeof(GrB_Index)); - //GB_msort_2(I, X, workspace1, workspace2, nnz, nthreads); - //LAGraph_Free ((void **)&workspace1) ; workspace1 = NULL; - //LAGraph_Free ((void **)&workspace2) ; workspace2 = NULL; LAGraph_Sort2((int64_t *) I, (int64_t *) X, nnz, nthreads, NULL); // save current labels for comparison by swapping L and L_prev @@ -326,9 +320,9 @@ int LAGraph_cdlp mode_length = 0; } } - LAGraph_Free ((void**)&I) ; I = NULL; - LAGraph_Free ((void**)&X) ; X = NULL; + LAGraph_Free ((void **) &I, NULL) ; + LAGraph_Free ((void **) &X, NULL) ; bool isequal; LAGraph_Matrix_IsEqual (&isequal, L_prev, L, NULL); diff --git a/experimental/algorithm/LG_CC_FastSV5.c b/experimental/algorithm/LG_CC_FastSV5.c index fa333bcfc6..bd868a3e30 100644 --- a/experimental/algorithm/LG_CC_FastSV5.c +++ b/experimental/algorithm/LG_CC_FastSV5.c @@ -40,6 +40,7 @@ // src/algorithm/LG_CC_FastSV6.c. They have thus been changed here to lower // case. +// todo: free all workspace in LG_FREE_ALL #define LG_FREE_ALL ; #include "LG_internal.h" @@ -195,7 +196,9 @@ static inline int Reduce_assign32 { // allocate a buf array for each thread, of size HASH_SIZE - uint32_t *mem = LAGraph_Malloc (nthreads*HASH_SIZE, sizeof (uint32_t)) ; + uint32_t *mem ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &mem, nthreads*HASH_SIZE, + sizeof (uint32_t), msg)) ; // todo: check out-of-memory condition here // todo why is hashing needed here? hashing is slow for what needs @@ -260,7 +263,7 @@ static inline int Reduce_assign32 } } - LAGraph_Free ((void **) &mem) ; + LAGraph_Free ((void **) &mem, NULL) ; } else { @@ -297,18 +300,18 @@ static inline int Reduce_assign32 // number of representatives. #undef LG_FREE_ALL -#define LG_FREE_ALL \ -{ \ - LAGraph_Free ((void **) &I) ; \ - LAGraph_Free ((void **) &V32) ; \ - LAGraph_Free ((void **) &ht_key) ; \ - LAGraph_Free ((void **) &ht_val) ; \ - /* todo why is T not freed?? */ \ - GrB_free (&f) ; \ - GrB_free (&gp) ; \ - GrB_free (&mngp) ; \ - GrB_free (&gp_new) ; \ - GrB_free (&mod) ; \ +#define LG_FREE_ALL \ +{ \ + LAGraph_Free ((void **) &I, NULL) ; \ + LAGraph_Free ((void **) &V32, NULL) ; \ + LAGraph_Free ((void **) &ht_key, NULL) ; \ + LAGraph_Free ((void **) &ht_val, NULL) ; \ + /* todo why is T not freed?? */ \ + GrB_free (&f) ; \ + GrB_free (&gp) ; \ + GrB_free (&mngp) ; \ + GrB_free (&gp_new) ; \ + GrB_free (&mod) ; \ } #endif @@ -381,9 +384,8 @@ int LG_CC_FastSV5 // SuiteSparse:GraphBLAS method, with GxB extensions GRB_TRY (GrB_Vector_new (&mod, GrB_BOOL, n)) ; // temporary arrays - I = LAGraph_Malloc (n, sizeof (GrB_Index)) ; - V32 = LAGraph_Malloc (n, sizeof (uint32_t)) ; - // todo: check out-of-memory condition + LAGRAPH_TRY (LAGraph_Malloc ((void **) &I , n, sizeof (GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &V32, n, sizeof (uint32_t), msg)) ; // prepare vectors #pragma omp parallel for num_threads(nthreads2) schedule(static) @@ -398,9 +400,10 @@ int LG_CC_FastSV5 // SuiteSparse:GraphBLAS method, with GxB extensions GRB_TRY (GrB_Vector_dup (&mngp, f)) ; // allocate the hash table - ht_key = LAGraph_Malloc (HASH_SIZE, sizeof (int32_t)) ; - ht_val = LAGraph_Malloc (HASH_SIZE, sizeof (int32_t)) ; - LG_ASSERT (ht_key != NULL && ht_val != NULL, GrB_OUT_OF_MEMORY) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &ht_key, HASH_SIZE, sizeof (int32_t), + msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &ht_val, HASH_SIZE, sizeof (int32_t), + msg)) ; //-------------------------------------------------------------------------- // sample phase @@ -440,20 +443,27 @@ int LG_CC_FastSV5 // SuiteSparse:GraphBLAS method, with GxB extensions GrB_Index Tp_len = nrows+1, Tp_size = Tp_len*sizeof(GrB_Index); GrB_Index Tj_len = nvals, Tj_size = Tj_len*sizeof(GrB_Index); GrB_Index Tx_len = nvals ; - GrB_Index *Tp = LAGraph_Malloc (Tp_len, sizeof (GrB_Index)) ; - GrB_Index *Tj = LAGraph_Malloc (Tj_len, sizeof (GrB_Index)) ; + + GrB_Index *Tp = NULL, *Tj = NULL ; GrB_Index Tx_size = typesize ; - void *Tx = LAGraph_Calloc (1, typesize) ; // T is iso + void *Tx = NULL ; + int32_t *range = NULL ; + GrB_Index *count = NULL ; - // todo check out-of-memory conditions + LAGRAPH_TRY (LAGraph_Malloc ((void **) &Tp, Tp_len, + sizeof (GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &Tj, Tj_len, + sizeof (GrB_Index), msg)) ; + LAGRAPH_TRY (LAGraph_Calloc (&Tx, 1, typesize, msg)) ; // T is iso //---------------------------------------------------------------------- // allocate workspace //---------------------------------------------------------------------- - int32_t *range = LAGraph_Malloc (nthreads + 1, sizeof (int32_t)) ; - GrB_Index *count = LAGraph_Malloc (nthreads + 1, sizeof (GrB_Index)) ; - // todo check out-of-memory conditions + LAGRAPH_TRY (LAGraph_Malloc ((void **) &range, nthreads + 1, + sizeof (int32_t), msg)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &count, nthreads + 1, + sizeof (GrB_Index), msg)) ; memset (count, 0, sizeof (GrB_Index) * (nthreads + 1)) ; @@ -675,8 +685,8 @@ int LG_CC_FastSV5 // SuiteSparse:GraphBLAS method, with GxB extensions Tp [n] = offset ; // free workspace - LAGraph_Free ((void **) &count) ; - LAGraph_Free ((void **) &range) ; + LAGraph_Free ((void **) &count, NULL) ; + LAGraph_Free ((void **) &range, NULL) ; // import S (unchanged since last export) GRB_TRY (GxB_Matrix_import_CSR (&S, type, nrows, ncols, diff --git a/experimental/test/LG_check_ktruss.c b/experimental/test/LG_check_ktruss.c index 0a194363fa..ee4a67a6dc 100644 --- a/experimental/test/LG_check_ktruss.c +++ b/experimental/test/LG_check_ktruss.c @@ -18,10 +18,10 @@ #define LG_FREE_WORK \ { \ - LAGraph_Free ((void **) &Cp) ; \ - LAGraph_Free ((void **) &Cj) ; \ - LAGraph_Free ((void **) &Cx) ; \ - LAGraph_Free ((void **) &Ax) ; \ + LAGraph_Free ((void **) &Cp, NULL) ; \ + LAGraph_Free ((void **) &Cj, NULL) ; \ + LAGraph_Free ((void **) &Cx, NULL) ; \ + LAGraph_Free ((void **) &Ax, NULL) ; \ } #define LG_FREE_ALL \ @@ -81,14 +81,13 @@ int LG_check_ktruss size_t typesize ; LG_TRY (LG_check_export (G, &Cp, &Cj, &Ax, &Cp_len, &Cj_len, &Cx_len, &typesize, msg)) ; - LAGraph_Free ((void **) &Ax) ; + LAGraph_Free ((void **) &Ax, NULL) ; //-------------------------------------------------------------------------- // allocate Cx //-------------------------------------------------------------------------- - Cx = (uint32_t *) LAGraph_Malloc (Cx_len, sizeof (uint32_t)) ; - LG_ASSERT (Cx != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &Cx, Cx_len, sizeof (uint32_t), msg)) ; //-------------------------------------------------------------------------- // construct the k-truss of G->A diff --git a/experimental/test/LG_check_mis.c b/experimental/test/LG_check_mis.c index 4e4c684929..0ab650c30d 100644 --- a/experimental/test/LG_check_mis.c +++ b/experimental/test/LG_check_mis.c @@ -14,8 +14,8 @@ #define LG_FREE_WORK \ { \ GrB_free (&C) ; \ - LAGraph_Free ((void **) &I) ; \ - LAGraph_Free ((void **) &X) ; \ + LAGraph_Free ((void **) &I, NULL) ; \ + LAGraph_Free ((void **) &X, NULL) ; \ } #define LG_FREE_ALL \ @@ -55,9 +55,8 @@ int LG_check_mis // check if iset is a valid MIS of A GrB_Index nvals ; GRB_TRY (GrB_Vector_nvals (&nvals, iset)) ; - I = (GrB_Index *) LAGraph_Malloc (nvals, sizeof (GrB_Index)) ; - X = (bool *) LAGraph_Malloc (nvals, sizeof (bool)) ; - LG_ASSERT (I != NULL && X != NULL, GrB_OUT_OF_MEMORY) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &I, nvals, sizeof (GrB_Index), msg)); + LAGRAPH_TRY (LAGraph_Malloc ((void **) &X, nvals, sizeof (bool), msg)) ; GRB_TRY (GrB_Vector_extractTuples_BOOL (I, X, &nvals, iset)) ; @@ -71,7 +70,7 @@ int LG_check_mis // check if iset is a valid MIS of A } } - LAGraph_Free ((void **) &X) ; + LAGraph_Free ((void **) &X, NULL) ; // printf ("independent set found: %.16g of %.16g nodes\n", // (double) isize, (double) n) ; @@ -115,7 +114,7 @@ int LG_check_mis // check if iset is a valid MIS of A GrB_Vector_free (&e) ; LG_ASSERT_MSG (nvals == n, -1, "error! A (I,I is not maximal!\n") ; - LAGraph_Free ((void **) &I) ; + LAGraph_Free ((void **) &I, NULL) ; printf ("maximal independent set OK %.16g of %.16g nodes", (double) isize, (double) n) ; diff --git a/experimental/test/test_AllKtruss.c b/experimental/test/test_AllKtruss.c index e2a81313a0..cd326ab41c 100644 --- a/experimental/test/test_AllKtruss.c +++ b/experimental/test/test_AllKtruss.c @@ -87,11 +87,13 @@ void test_AllKTruss (void) GrB_Index n ; int64_t kmax ; OK (GrB_Matrix_nrows (&n, G->A)) ; - GrB_Matrix *Cset = (GrB_Matrix *) LAGraph_Calloc (n, - sizeof (GrB_Matrix)) ; - int64_t *ntris = LAGraph_Malloc (n, sizeof (int64_t)) ; - int64_t *nedges = LAGraph_Malloc (n, sizeof (int64_t)) ; - int64_t *nsteps = LAGraph_Malloc (n, sizeof (int64_t)) ; + GrB_Matrix *Cset ; + int64_t *ntris, *nedges, *nsteps ; + OK (LAGraph_Calloc ((void **) &Cset , n, sizeof (GrB_Matrix), msg)) ; + OK (LAGraph_Malloc ((void **) &ntris , n, sizeof (int64_t), msg)) ; + OK (LAGraph_Malloc ((void **) &nedges, n, sizeof (int64_t), msg)) ; + OK (LAGraph_Malloc ((void **) &nsteps, n, sizeof (int64_t), msg)) ; + OK (LAGraph_AllKTruss (Cset, &kmax, ntris, nedges, nsteps, G, msg)) ; printf ("all k-truss: kmax %g\n", (double) kmax) ; @@ -134,11 +136,13 @@ void test_AllKTruss (void) G->kind = LAGraph_ADJACENCY_DIRECTED ; G->structure_is_symmetric = true ; int64_t k2 ; - GrB_Matrix *Cset2 = (GrB_Matrix *) LAGraph_Calloc (n, - sizeof (GrB_Matrix)) ; - int64_t *ntris2 = LAGraph_Malloc (n, sizeof (int64_t)) ; - int64_t *nedges2 = LAGraph_Malloc (n, sizeof (int64_t)) ; - int64_t *nsteps2 = LAGraph_Malloc (n, sizeof (int64_t)) ; + GrB_Matrix *Cset2 ; + int64_t *ntris2, *nedges2, *nsteps2 ; + OK (LAGraph_Calloc ((void **) &Cset2 , n, sizeof (GrB_Matrix), msg)) ; + OK (LAGraph_Malloc ((void **) &ntris2 , n, sizeof (int64_t), msg)) ; + OK (LAGraph_Malloc ((void **) &nedges2, n, sizeof (int64_t), msg)) ; + OK (LAGraph_Malloc ((void **) &nsteps2, n, sizeof (int64_t), msg)) ; + OK (LAGraph_AllKTruss (Cset2, &k2, ntris2, nedges2, nsteps2, G, msg)) ; TEST_CHECK (k2 == kmax) ; for (int k = 0 ; k <= kmax ; k++) @@ -165,15 +169,15 @@ void test_AllKTruss (void) OK (GrB_free (&(Cset2 [k]))) ; } - LAGraph_Free ((void **) &Cset) ; - LAGraph_Free ((void **) &ntris) ; - LAGraph_Free ((void **) &nedges) ; - LAGraph_Free ((void **) &nsteps) ; + LAGraph_Free ((void **) &Cset, NULL) ; + LAGraph_Free ((void **) &ntris, NULL) ; + LAGraph_Free ((void **) &nedges, NULL) ; + LAGraph_Free ((void **) &nsteps, NULL) ; - LAGraph_Free ((void **) &Cset2) ; - LAGraph_Free ((void **) &ntris2) ; - LAGraph_Free ((void **) &nedges2) ; - LAGraph_Free ((void **) &nsteps2) ; + LAGraph_Free ((void **) &Cset2, NULL) ; + LAGraph_Free ((void **) &ntris2, NULL) ; + LAGraph_Free ((void **) &nedges2, NULL) ; + LAGraph_Free ((void **) &nsteps2, NULL) ; OK (LAGraph_Delete (&G, msg)) ; } @@ -205,10 +209,12 @@ void test_allktruss_errors (void) GrB_Index n ; int64_t kmax ; OK (GrB_Matrix_nrows (&n, G->A)) ; - GrB_Matrix *Cset = (GrB_Matrix *) LAGraph_Calloc (n, sizeof (GrB_Matrix)) ; - int64_t *ntris = LAGraph_Malloc (n, sizeof (int64_t)) ; - int64_t *nedges = LAGraph_Malloc (n, sizeof (int64_t)) ; - int64_t *nsteps = LAGraph_Malloc (n, sizeof (int64_t)) ; + int64_t *ntris, *nedges, *nsteps ; + GrB_Matrix *Cset ; + OK (LAGraph_Calloc ((void **) &Cset , n, sizeof (GrB_Matrix), msg)) ; + OK (LAGraph_Malloc ((void **) &ntris , n, sizeof (int64_t), msg)) ; + OK (LAGraph_Malloc ((void **) &nedges, n, sizeof (int64_t), msg)) ; + OK (LAGraph_Malloc ((void **) &nsteps, n, sizeof (int64_t), msg)) ; // kmax is NULL int result = LAGraph_AllKTruss (Cset, NULL, ntris, nedges, nsteps, G, msg) ; @@ -234,10 +240,10 @@ void test_allktruss_errors (void) printf ("\nresult: %d %s\n", result, msg) ; TEST_CHECK (result == -1005) ; - LAGraph_Free ((void **) &Cset) ; - LAGraph_Free ((void **) &ntris) ; - LAGraph_Free ((void **) &nedges) ; - LAGraph_Free ((void **) &nsteps) ; + LAGraph_Free ((void **) &Cset, NULL) ; + LAGraph_Free ((void **) &ntris, NULL) ; + LAGraph_Free ((void **) &nedges, NULL) ; + LAGraph_Free ((void **) &nsteps, NULL) ; OK (LAGraph_Delete (&G, msg)) ; LAGraph_Finalize (msg) ; diff --git a/experimental/test/test_BF.c b/experimental/test/test_BF.c index d9dc04280d..6d72035bf8 100644 --- a/experimental/test/test_BF.c +++ b/experimental/test/test_BF.c @@ -115,11 +115,11 @@ void test_BF (void) OK (GrB_Matrix_nrows (&nrows, A_orig)) ; OK (GrB_Matrix_ncols (&ncols, A_orig)) ; GrB_Index n = nrows ; + OK (LAGraph_Malloc ((void **) &I, nvals, sizeof (GrB_Index), msg)) ; + OK (LAGraph_Malloc ((void **) &J, nvals, sizeof (GrB_Index), msg)) ; + OK (LAGraph_Malloc ((void **) &W, nvals, sizeof (double), msg)) ; + OK (LAGraph_Malloc ((void **) &W_int32, nvals, sizeof (int32_t), msg)) ; - I = (GrB_Index *) LAGraph_Malloc (nvals, sizeof (GrB_Index)) ; - J = (GrB_Index *) LAGraph_Malloc (nvals, sizeof (GrB_Index)) ; - W = (double *) LAGraph_Malloc (nvals, sizeof (double)) ; - W_int32 = (int32_t *) LAGraph_Malloc (nvals, sizeof (int32_t)) ; OK (GrB_Matrix_extractTuples_FP64 (I, J, W, &nvals, A_orig)) ; if (has_integer_weights) { @@ -294,8 +294,8 @@ void test_BF (void) for (int trial = 0 ; trial < ntrials ; trial++) { - LAGraph_Free ((void **) &d) ; - LAGraph_Free ((void **) &pi) ; + LAGraph_Free ((void **) &d, NULL) ; + LAGraph_Free ((void **) &pi, NULL) ; result = LAGraph_BF_pure_c_double (&d, &pi, s, n, nvals, (const int64_t *) I, (const int64_t *) J, W) ; TEST_CHECK (result == valid) ; @@ -312,8 +312,8 @@ void test_BF (void) if (has_integer_weights) { printf ("pure_c integer:\n") ; - LAGraph_Free ((void **) &d10) ; - LAGraph_Free ((void **) &pi10) ; + LAGraph_Free ((void **) &d10, NULL) ; + LAGraph_Free ((void **) &pi10, NULL) ; result = LAGraph_BF_pure_c (&d10, &pi10, s, n, nvals, (const int64_t *) I, (const int64_t *) J, W_int32) ; TEST_CHECK (result == valid) ; @@ -478,12 +478,12 @@ void test_BF (void) GrB_free (&A) ; GrB_free (&A_orig) ; GrB_free (&AT) ; - LAGraph_Free ((void **) &I) ; - LAGraph_Free ((void **) &J) ; - LAGraph_Free ((void **) &W) ; - LAGraph_Free ((void **) &W_int32) ; - LAGraph_Free ((void **) &d) ; - LAGraph_Free ((void **) &pi) ; + LAGraph_Free ((void **) &I, NULL) ; + LAGraph_Free ((void **) &J, NULL) ; + LAGraph_Free ((void **) &W, NULL) ; + LAGraph_Free ((void **) &W_int32, NULL) ; + LAGraph_Free ((void **) &d, NULL) ; + LAGraph_Free ((void **) &pi, NULL) ; GrB_free (&d1) ; GrB_free (&pi1) ; GrB_free (&h1) ; diff --git a/experimental/test/test_SSaveSet.c b/experimental/test/test_SSaveSet.c index fe384eead7..f0c62bbe9b 100644 --- a/experimental/test/test_SSaveSet.c +++ b/experimental/test/test_SSaveSet.c @@ -93,8 +93,8 @@ void test_SSaveSet (void) #endif // load all matrices into a single set - GrB_Matrix *Set = LAGraph_Malloc (NFILES, sizeof (GrB_Matrix)) ; - TEST_CHECK (Set != NULL) ; + GrB_Matrix *Set = NULL ; + OK (LAGraph_Malloc ((void **) &Set, NFILES, sizeof (GrB_Matrix), msg)) ; for (int k = 0 ; k < NFILES ; k++) { @@ -150,7 +150,7 @@ void test_SSaveSet (void) // free all matrices LAGraph_SFreeSet (&Set, NFILES) ; LAGraph_SFreeSet (&Set2, NFILES) ; - LAGraph_Free ((void **) &collection) ; + LAGraph_Free ((void **) &collection, NULL) ; OK (GrB_free (&desc)) ; LAGraph_Finalize (msg) ; diff --git a/experimental/test/test_SWrite.c b/experimental/test/test_SWrite.c index bfc5e8983a..002956df48 100644 --- a/experimental/test/test_SWrite.c +++ b/experimental/test/test_SWrite.c @@ -142,7 +142,6 @@ void test_SWrite (void) // serialize the matrix // GxB_set (GxB_BURBLE, true) ; - bool ok ; void *blob = NULL ; GrB_Index blob_size = 0 ; #if LAGRAPH_SUITESPARSE @@ -157,12 +156,12 @@ void test_SWrite (void) // try GrB version OK (GrB_Matrix_serializeSize (&blob_size, A)) ; GrB_Index blob_size_old = blob_size ; - blob = LAGraph_Malloc (blob_size, sizeof (uint8_t)) ; + OK (LAGraph_Malloc ((void **) &blob, blob_size, + sizeof (uint8_t), msg)) ; TEST_CHECK (blob != NULL) ; OK (GrB_Matrix_serialize (blob, &blob_size, A)) ; - blob = LAGraph_Realloc (blob_size, blob_size_old, - sizeof (uint8_t), blob, &ok) ; - TEST_CHECK (ok) ; + OK (LAGraph_Realloc ((void **) &blob, blob_size, + blob_size_old, sizeof (uint8_t), msg)) ; } // deserialize the matrix @@ -176,6 +175,7 @@ void test_SWrite (void) // ensure the matrices A and B are the same // GxB_print (A,3) ; // GxB_print (B,3) ; + bool ok = false ; OK (LAGraph_Matrix_IsEqual (&ok, A, B, msg)) ; TEST_CHECK (ok) ; OK (GrB_free (&B)) ; @@ -188,7 +188,7 @@ void test_SWrite (void) // write the binary blob to the file then free the blob OK (LAGraph_SWrite_Item (f, blob, blob_size, msg)) ; - LAGraph_Free (&blob) ; + LAGraph_Free (&blob, NULL) ; // open the file and load back the contents rewind (f) ; @@ -223,13 +223,13 @@ void test_SWrite (void) OK (GrB_free (&B)) ; // free the contents: todo make this a utility function - LAGraph_Free ((void **) &collection) ; + LAGraph_Free ((void **) &collection, NULL) ; for (int i = 0 ; i < ncontents ; i++) { LAGraph_Contents *Item = &(Contents [i]) ; - LAGraph_Free ((void **) &(Item->blob)) ; + LAGraph_Free ((void **) &(Item->blob), NULL) ; } - LAGraph_Free ((void **) &Contents) ; + LAGraph_Free ((void **) &Contents, NULL) ; } OK (GrB_free (&A)) ; @@ -267,12 +267,11 @@ void test_SWrite_errors (void) // use GrB version OK (GrB_Matrix_serializeSize (&blob_size, A)) ; GrB_Index blob_size_old = blob_size ; - blob = LAGraph_Malloc (blob_size, sizeof (uint8_t)) ; + OK (LAGraph_Malloc ((void **) &blob, blob_size, sizeof (uint8_t), msg)); TEST_CHECK (blob != NULL) ; OK (GrB_Matrix_serialize (blob, &blob_size, A)) ; - blob = LAGraph_Realloc (blob_size, blob_size_old, - sizeof (uint8_t), blob, &ok) ; - TEST_CHECK (ok) ; + OK (LAGraph_Realloc ((void **) &blob, blob_size, + blob_size_old, sizeof (uint8_t), msg)) ; } #endif @@ -314,7 +313,7 @@ void test_SWrite_errors (void) // write the binary blob to the file then free the blob OK (LAGraph_SWrite_Item (f, blob, blob_size, msg)) ; - LAGraph_Free (&blob) ; + LAGraph_Free (&blob, NULL) ; result = LAGraph_SWrite_Item (NULL, blob, blob_size, msg) ; TEST_CHECK (result == GrB_NULL_POINTER) ; @@ -360,7 +359,7 @@ void test_SWrite_errors (void) // free everything LAGraph_SFreeSet (&Set, nmatrices) ; - LAGraph_Free ((void **) &collection) ; + LAGraph_Free ((void **) &collection, NULL) ; fclose (f) ; // read garbage with LAGraph_SRead diff --git a/experimental/utility/LAGraph_Random_Matrix.c b/experimental/utility/LAGraph_Random_Matrix.c index c9cbb63784..49eae154e9 100644 --- a/experimental/utility/LAGraph_Random_Matrix.c +++ b/experimental/utility/LAGraph_Random_Matrix.c @@ -21,24 +21,24 @@ // This could be fixed by using the GxB_IGNORE_DUP operator, but this would // require SuiteSparse:GraphBLAS. -#define LG_FREE_WORK \ -{ \ - LAGraph_Free ((void **) &I) ; \ - LAGraph_Free ((void **) &J) ; \ - LAGraph_Free ((void **) &ignore) ; \ - LAGraph_Free (&X) ; \ - GrB_free (&Mod) ; \ - GrB_free (&Rows) ; \ - GrB_free (&Cols) ; \ - GrB_free (&Values) ; \ - GrB_free (&Seed) ; \ - GrB_free (&T) ; \ +#define LG_FREE_WORK \ +{ \ + LAGraph_Free ((void **) &I, NULL) ; \ + LAGraph_Free ((void **) &J, NULL) ; \ + LAGraph_Free ((void **) &ignore, NULL) ; \ + LAGraph_Free (&X, NULL) ; \ + GrB_free (&Mod) ; \ + GrB_free (&Rows) ; \ + GrB_free (&Cols) ; \ + GrB_free (&Values) ; \ + GrB_free (&Seed) ; \ + GrB_free (&T) ; \ } -#define LG_FREE_ALL \ -{ \ - LG_FREE_WORK ; \ - GrB_free (A) ; \ +#define LG_FREE_ALL \ +{ \ + LG_FREE_WORK ; \ + GrB_free (A) ; \ } #include "LG_internal.h" @@ -144,11 +144,10 @@ GrB_Info LAGraph_Random_Matrix // random matrix of any built-in type #if !LAGRAPH_SUITESPARSE { - ignore = LAGraph_Malloc (nvals, sizeof (GrB_Index)) ; - I = LAGraph_Malloc (nvals, sizeof (GrB_Index)) ; - J = LAGraph_Malloc (nvals, sizeof (GrB_Index)) ; - LG_ASSERT (I != NULL && J != NULL && ignore != NULL, - GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &ignore, nvals, sizeof (GrB_Index), + msg)) ; + LG_TRY (LAGraph_Malloc ((void **) &I, nvals, sizeof (GrB_Index), msg)) ; + LG_TRY (LAGraph_Malloc ((void **) &J, nvals, sizeof (GrB_Index), msg)) ; } #endif @@ -286,82 +285,81 @@ GrB_Info LAGraph_Random_Matrix // random matrix of any built-in type // this takes O(nvals) time and space if (type == GrB_BOOL) { - X = LAGraph_Malloc (nvals, sizeof (bool)) ; - LG_ASSERT (X != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &X, nvals, sizeof (bool), msg)) ; GRB_TRY (GrB_Vector_extractTuples_BOOL (ignore, X, &nvals, Values)) ; } else if (type == GrB_INT8) { - X = LAGraph_Malloc (nvals, sizeof (int8_t)) ; - LG_ASSERT (X != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &X, nvals, sizeof (int8_t), + msg)) ; GRB_TRY (GrB_Vector_extractTuples_INT8 (ignore, X, &nvals, Values)) ; } else if (type == GrB_INT16) { - X = LAGraph_Malloc (nvals, sizeof (int16_t)) ; - LG_ASSERT (X != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &X, nvals, sizeof (int16_t), + msg)) ; GRB_TRY (GrB_Vector_extractTuples_INT16 (ignore, X, &nvals, Values)) ; } else if (type == GrB_INT32) { - X = LAGraph_Malloc (nvals, sizeof (int32_t)) ; - LG_ASSERT (X != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &X, nvals, sizeof (int32_t), + msg)) ; GRB_TRY (GrB_Vector_extractTuples_INT32 (ignore, X, &nvals, Values)) ; } else if (type == GrB_INT64) { - X = LAGraph_Malloc (nvals, sizeof (int64_t)) ; - LG_ASSERT (X != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &X, nvals, sizeof (int64_t), + msg)) ; GRB_TRY (GrB_Vector_extractTuples_INT64 (ignore, X, &nvals, Values)) ; } else if (type == GrB_UINT8) { - X = LAGraph_Malloc (nvals, sizeof (uint8_t)) ; - LG_ASSERT (X != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &X, nvals, sizeof (uint8_t), + msg)) ; GRB_TRY (GrB_Vector_extractTuples_UINT8 (ignore, X, &nvals, Values)) ; } else if (type == GrB_UINT16) { - X = LAGraph_Malloc (nvals, sizeof (uint16_t)) ; - LG_ASSERT (X != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &X, nvals, sizeof (uint16_t), + msg)) ; GRB_TRY (GrB_Vector_extractTuples_UINT16 (ignore, X, &nvals, Values)) ; } else if (type == GrB_UINT32) { - X = LAGraph_Malloc (nvals, sizeof (uint32_t)) ; - LG_ASSERT (X != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &X, nvals, sizeof (uint32_t), + msg)) ; GRB_TRY (GrB_Vector_extractTuples_UINT32 (ignore, X, &nvals, Values)) ; } else if (type == GrB_UINT64) { - X = LAGraph_Malloc (nvals, sizeof (uint64_t)) ; - LG_ASSERT (X != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &X, nvals, sizeof (uint64_t), + msg)) ; GRB_TRY (GrB_Vector_extractTuples_UINT64 (ignore, X, &nvals, Values)) ; } else if (type == GrB_FP32) { - X = LAGraph_Malloc (nvals, sizeof (float)) ; - LG_ASSERT (X != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &X, nvals, sizeof (float), + msg)) ; GRB_TRY (GrB_Vector_extractTuples_FP32 (ignore, X, &nvals, Values)) ; } else // if (type == GrB_FP64) { - X = LAGraph_Malloc (nvals, sizeof (double)) ; - LG_ASSERT (X != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Malloc ((void **) &X, nvals, sizeof (double), + msg)) ; GRB_TRY (GrB_Vector_extractTuples_FP64 (ignore, X, &nvals, Values)) ; } - LAGraph_Free ((void **) &ignore) ; + LAGraph_Free ((void **) &ignore, NULL) ; } #endif diff --git a/experimental/utility/LAGraph_SFreeContents.c b/experimental/utility/LAGraph_SFreeContents.c index 1df31c3d3c..4a3b0a8955 100644 --- a/experimental/utility/LAGraph_SFreeContents.c +++ b/experimental/utility/LAGraph_SFreeContents.c @@ -28,10 +28,10 @@ void LAGraph_SFreeContents // free the Contents returned by LAGraph_SRead { for (GrB_Index i = 0 ; i < ncontents ; i++) { - LAGraph_Free ((void **) &(Contents [i].blob)) ; + LAGraph_Free ((void **) &(Contents [i].blob), NULL) ; } } - LAGraph_Free ((void **) Contents_handle) ; + LAGraph_Free ((void **) Contents_handle, NULL) ; } } diff --git a/experimental/utility/LAGraph_SFreeSet.c b/experimental/utility/LAGraph_SFreeSet.c index 307ef00401..b9a1f97309 100644 --- a/experimental/utility/LAGraph_SFreeSet.c +++ b/experimental/utility/LAGraph_SFreeSet.c @@ -31,7 +31,7 @@ void LAGraph_SFreeSet // free a set of matrices GrB_free (&(Set [i])) ; } } - LAGraph_Free ((void **) Set_handle) ; + LAGraph_Free ((void **) Set_handle, NULL) ; } } diff --git a/experimental/utility/LAGraph_SLoadSet.c b/experimental/utility/LAGraph_SLoadSet.c index 7fba52fefc..0b3fcf4425 100644 --- a/experimental/utility/LAGraph_SLoadSet.c +++ b/experimental/utility/LAGraph_SLoadSet.c @@ -17,7 +17,7 @@ // texts. The caller is responsible for freeing the output of this method, // via: -// LAGraph_Free ((void **) &collection) ; +// LAGraph_Free ((void **) &collection, NULL) ; // LAGraph_SFreeSet (&Set, nmatrices) ; // See also LAGraph_SRead, which just reads in the serialized objects and @@ -37,7 +37,7 @@ { \ LG_FREE_WORK ; \ LAGraph_SFreeSet (&Set, nmatrices) ; \ - LAGraph_Free ((void **) &collection) ; \ + LAGraph_Free ((void **) &collection, NULL) ; \ } #include "LG_internal.h" @@ -128,8 +128,8 @@ int LAGraph_SLoadSet // load a set of matrices from a *.lagraph file // convert all the matrices (skip vectors and text content for now) //-------------------------------------------------------------------------- - Set = LAGraph_Calloc (nmatrices, sizeof (GrB_Matrix)) ; - LG_ASSERT (Set != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Calloc ((void **) &Set, nmatrices, sizeof (GrB_Matrix), + msg)) ; GrB_Index kmatrices = 0 ; for (GrB_Index i = 0 ; i < ncontents ; i++) @@ -153,7 +153,7 @@ int LAGraph_SLoadSet // load a set of matrices from a *.lagraph file // else if (Content [i].kind == LAGraph_text_kind) ... // free the ith blob - LAGraph_Free ((void **) &(Contents [i].blob)) ; + LAGraph_Free ((void **) &(Contents [i].blob), NULL) ; } //-------------------------------------------------------------------------- diff --git a/experimental/utility/LAGraph_SRead.c b/experimental/utility/LAGraph_SRead.c index ab9000ba17..919ac40f72 100644 --- a/experimental/utility/LAGraph_SRead.c +++ b/experimental/utility/LAGraph_SRead.c @@ -16,7 +16,7 @@ // objects. The user application is responsible for freeing the output of this // method, via: -// LAGraph_Free ((void **) &collection) ; +// LAGraph_Free ((void **) &collection, NULL) ; // LAGraph_SFreeContents (&Contents, ncontents) ; // See also LAGraph_SLoadSet, which calls this function and then converts all @@ -82,14 +82,14 @@ static int get_int_array_3 (json_arr arr, int *x, char *msg) { \ if (root != NULL) { free (root) ; } \ root = NULL ; \ - LAGraph_Free ((void **) &json_string) ; \ + LAGraph_Free ((void **) &json_string, NULL) ; \ } #undef LG_FREE_ALL #define LG_FREE_ALL \ { \ LG_FREE_WORK ; \ - LAGraph_Free ((void **) &collection) ; \ + LAGraph_Free ((void **) &collection, NULL) ; \ LAGraph_SFreeContents (&Contents, ncontents) ; \ } @@ -126,16 +126,15 @@ int LAGraph_SRead // read a set of matrices from a *.lagraph file //-------------------------------------------------------------------------- size_t s = 256, k = 0 ; - json_string = LAGraph_Malloc (s, sizeof (char)) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &json_string, s, sizeof (char), + msg)) ; while (true) { if (k == s) { // json_string is full; double its size - bool ok = true ; - json_string = LAGraph_Realloc (2*s, s, sizeof (char), json_string, - &ok) ; - LG_ASSERT (ok, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Realloc ((void **) &json_string, 2*s, s, + sizeof (char), msg)) ; s = 2*s ; } // get the next character from the file @@ -155,7 +154,7 @@ int LAGraph_SRead // read a set of matrices from a *.lagraph file root = json_parse (json_string, k) ; LG_ASSERT (root != NULL, GrB_OUT_OF_MEMORY) ; - LAGraph_Free ((void **) &json_string) ; + LAGraph_Free ((void **) &json_string, NULL) ; //-------------------------------------------------------------------------- // process the JSON header @@ -217,8 +216,7 @@ int LAGraph_SRead // read a set of matrices from a *.lagraph file o = o->next ; OK (o->value->type == json_type_array) ; size_t len = o->name->string_size ; - collection = LAGraph_Calloc (len+1, sizeof (char)) ; - OK (collection != NULL) ; + LG_TRY (LAGraph_Calloc ((void **) &collection, len+1, sizeof (char), msg)) ; strncpy (collection, o->name->string, len) ; //-------------------------------------------------------------------------- @@ -230,8 +228,8 @@ int LAGraph_SRead // read a set of matrices from a *.lagraph file a = arr->start ; len = arr->length ; // allocate an Contents array of size len to hold the contents - Contents = LAGraph_Calloc (len, sizeof (LAGraph_Contents)) ; - LG_ASSERT (Contents != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Calloc ((void **) &Contents, len, sizeof (LAGraph_Contents), + msg)) ; for (int i = 0 ; i < len && a != NULL ; i++, a = a->next) { @@ -339,8 +337,8 @@ int LAGraph_SRead // read a set of matrices from a *.lagraph file // allocate the blob and read it from the file //---------------------------------------------------------------------- - Item->blob = LAGraph_Malloc (Item->blob_size, sizeof (uint8_t)) ; - OK (Item->blob != NULL) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &(Item->blob), Item->blob_size, + sizeof (uint8_t), msg)) ; size_t bytes_read = fread (Item->blob, sizeof (uint8_t), Item->blob_size, f) ; OK (bytes_read == Item->blob_size) ; diff --git a/experimental/utility/LAGraph_SSaveSet.c b/experimental/utility/LAGraph_SSaveSet.c index 557b1abb94..ab68e1ae30 100644 --- a/experimental/utility/LAGraph_SSaveSet.c +++ b/experimental/utility/LAGraph_SSaveSet.c @@ -81,8 +81,8 @@ int LAGraph_SSaveSet // save a set of matrices from a *.lagraph file //-------------------------------------------------------------------------- // allocate an Contents array of size nmatrices to hold the contents - Contents = LAGraph_Calloc (nmatrices, sizeof (LAGraph_Contents)) ; - LG_ASSERT (Contents != NULL, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Calloc ((void **) &Contents, nmatrices, + sizeof (LAGraph_Contents), msg)) ; for (GrB_Index i = 0 ; i < nmatrices ; i++) { @@ -96,14 +96,12 @@ int LAGraph_SSaveSet // save a set of matrices from a *.lagraph file GrB_Index estimate ; GRB_TRY (GrB_Matrix_serializeSize (&estimate, Set [i])) ; Contents [i].blob_size = estimate ; - Contents [i].blob = LAGraph_Malloc (estimate, sizeof (uint8_t)) ; - LG_ASSERT (Contents [i].blob != NULL, GrB_OUT_OF_MEMORY) ; + LAGRAPH_TRY (LAGraph_Malloc ((void **) &(Contents [i].blob), + estimate, sizeof (uint8_t), msg)) ; GRB_TRY (GrB_Matrix_serialize (Contents [i].blob, (GrB_Index *) &(Contents [i].blob_size), Set [i])) ; - bool ok ; - Contents [i].blob = LAGraph_Realloc (&(Contents [i].blob_size), - estimate, sizeof (uint8_t), Contents [i].blob, &ok) ; - LG_ASSERT (ok, GrB_OUT_OF_MEMORY) ; + LG_TRY (LAGraph_Realloc (&(Contents [i].blob_size), + estimate, sizeof (uint8_t), msg)) ; } #endif } diff --git a/include/LAGraph.h b/include/LAGraph.h index b50dd9fcd7..8852b67965 100644 --- a/include/LAGraph.h +++ b/include/LAGraph.h @@ -33,10 +33,10 @@ // See also the LAGraph_Version utility method, which returns these values. // These definitions must match the same definitions in LAGraph/CMakeLists.txt. // FIXME: use config to create include/LAGraph.h from LAGraph/CMakeLists.txt -#define LAGRAPH_DATE "Mar 11, 2022" +#define LAGRAPH_DATE "Mar 16, 2022" #define LAGRAPH_VERSION_MAJOR 0 #define LAGRAPH_VERSION_MINOR 9 -#define LAGRAPH_VERSION_UPDATE 13 +#define LAGRAPH_VERSION_UPDATE 14 //============================================================================== // include files and helper macros @@ -111,19 +111,17 @@ // LAGraph error handling //============================================================================== -// All LAGraph functions that return an int use it to return an error status -// (described below), where zero (GrB_SUCCESS) denotes success, negative values -// indicate an error, and positive values denote success but with some kind of -// algorithm-specific note or warning. The only LAGraph functions that do not -// return an int status are the memory management functions: LAGraph_Malloc, -// LAGraph_Calloc, LAGraph_Realloc, and LAGraph_Free. +// All LAGraph functions return an int to indicate an error status (described +// below), where zero (GrB_SUCCESS) denotes success, negative values indicate +// an error, and positive values denote success but with some kind of +// algorithm-specific note or warning. -// In addition, all LAGraph functions that return an int also have a final -// parameter that is a pointer to a user-allocated string in which an -// algorithm-specific error message can be returned. If NULL, no error message -// is returned. This is not itself an error condition, it just indicates that -// the caller does not need the message returned. If the message string is -// provided but no error occurs, an empty string is returned. +// In addition, all LAGraph functions also have a final parameter that is a +// pointer to a user-allocated string in which an algorithm-specific error +// message can be returned. If NULL, no error message is returned. This is +// not itself an error condition, it just indicates that the caller does not +// need the message returned. If the message string is provided but no error +// occurs, an empty string is returned. // LAGRAPH_MSG_LEN: The maximum required length of a message string #define LAGRAPH_MSG_LEN 256 @@ -147,11 +145,10 @@ // LAGraph error status: //------------------------------------------------------------------------------ -// All LAGraph methods that return an int use this return value to denote their -// status: zero if they are successful (which is the value of GrB_SUCCESS), -// negative on error, or positive for an informational value (such as -// GrB_NO_VALUE). Integers in the range -999 to 999 are reserved for GraphBLAS -// GrB_Info return values: +// All LAGraph methods return an int to denote their status: zero if they are +// successful (which is the value of GrB_SUCCESS), negative on error, or +// positive for an informational value (such as GrB_NO_VALUE). Integers in the +// range -999 to 999 are reserved for GraphBLAS GrB_Info return values: // successful results: // GrB_SUCCESS = 0 // all is well @@ -218,9 +215,6 @@ #define LAGRAPH_NO_SELF_EDGES_ALLOWED (-1004) #define LAGRAPH_CONVERGENCE_FAILURE (-1005) -// The following return values and defintion of msg apply to all LAGraph -// functions that return an int: - // @retval GrB_SUCCESS if successful // @retval a negative GrB_Info value on error (in range -999 to -1) // @retval a positive GrB_Info value if successful but with extra information @@ -266,7 +260,7 @@ /* free any internal workspace and return the status */ \ GrB_free (*parent) ; \ GrB_free (workvector) ; \ - LAGraph_Free ((void **) &W) ; \ + LAGraph_Free ((void **) &W, NULL) ; \ return (status) ; \ } @@ -326,15 +320,9 @@ //============================================================================== // LAGraph provides wrappers for the malloc/calloc/realloc/free set of memory -// management functions, initialized by LAGraph_Init or LAGr_Init. By -// default, they are pointers to the ANSI C11 malloc/calloc/realloc/free -// functions. Unlike all other LAGraph utility functions, these methods do not -// return an int, and do not have a final char *msg parameter. Instead, they -// closely (but not exactly) follow the sytax of malloc/calloc/realloc/free. -// LAGraph_Calloc and LAGraph_free have the same syntax as calloc and free. -// LAGraph_Malloc has the syntax of calloc instead of malloc. LAGraph_Realloc -// is very different from realloc, since the ANSI C11 realloc syntax is -// difficult to use safely. +// management functions, initialized by LAGraph_Init or LAGr_Init. By default, +// the following are pointers to the ANSI C11 malloc/calloc/realloc/free +// functions. LAGRAPH_PUBLIC void * (* LAGraph_Malloc_function ) (size_t) ; LAGRAPH_PUBLIC void * (* LAGraph_Calloc_function ) (size_t, size_t) ; @@ -346,11 +334,14 @@ LAGRAPH_PUBLIC void (* LAGraph_Free_function ) (void *) ; //------------------------------------------------------------------------------ LAGRAPH_PUBLIC -void *LAGraph_Malloc // returns pointer to allocated block of memory -( // or NULL if the allocation fails +int LAGraph_Malloc +( + // output: + void **p, // pointer to allocated block of memory // input: size_t nitems, // number of items - size_t size_of_item // size of each item + size_t size_of_item, // size of each item + char *msg ) ; //------------------------------------------------------------------------------ @@ -358,11 +349,14 @@ void *LAGraph_Malloc // returns pointer to allocated block of memory //------------------------------------------------------------------------------ LAGRAPH_PUBLIC -void *LAGraph_Calloc // returns pointer to allocated block of memory -( // or NULL if the allocation fails +int LAGraph_Calloc +( + // output: + void **p, // pointer to allocated block of memory // input: size_t nitems, // number of items - size_t size_of_item // size of each item + size_t size_of_item, // size of each item + char *msg ) ; //------------------------------------------------------------------------------ @@ -370,32 +364,32 @@ void *LAGraph_Calloc // returns pointer to allocated block of memory //------------------------------------------------------------------------------ LAGRAPH_PUBLIC -void *LAGraph_Realloc // returns pointer to reallocated block of memory, -( // or original block if reallocation fails. +int LAGraph_Realloc +( + // input/output: + void **p, // old block to reallocate // input: size_t nitems_new, // new number of items in the object size_t nitems_old, // old number of items in the object size_t size_of_item, // size of each item - // input/output: - void *p, // old block to reallocate - // output: - bool *ok // true if successful, false otherwise + char *msg ) ; //------------------------------------------------------------------------------ // LAGraph_Free: free a block of memory (wrapper for free) //------------------------------------------------------------------------------ -// If p = LAGraph_Malloc (...) is the pointer to the allocated block of memory, -// LAGraph_Free (&p) is the method to free it. The parameter is passed as &p -// so that p can be set to NULL on return, to guard against double-free. +// If LAGraph_Malloc (&p, ...) is the pointer to the allocated block of memory, +// LAGraph_Free (&p, ...) is the method to free it. The parameter is passed as +// &p so that p can be set to NULL on return, to guard against double-free. // LAGraph_Free does nothing if &p or p are NULL on input. LAGRAPH_PUBLIC -void LAGraph_Free // free a block of memory and set p to NULL +int LAGraph_Free // free a block of memory and set p to NULL ( // input/output: - void **p // pointer to object to free, does nothing if NULL + void **p, // pointer to object to free, does nothing if NULL + char *msg ) ; //==============================================================================