Skip to content

Commit

Permalink
revise LAGraph memory wrappers: return int, add msg
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTimothyAldenDavis committed Mar 16, 2022
1 parent 0f7d17b commit d6e68b3
Show file tree
Hide file tree
Showing 22 changed files with 366 additions and 374 deletions.
31 changes: 16 additions & 15 deletions experimental/algorithm/LAGraph_BF_full.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <LAGraph.h>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ;
Expand Down
46 changes: 23 additions & 23 deletions experimental/algorithm/LAGraph_BF_full1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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));

Expand Down
44 changes: 21 additions & 23 deletions experimental/algorithm/LAGraph_BF_full1a.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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?

Expand Down
46 changes: 23 additions & 23 deletions experimental/algorithm/LAGraph_BF_full2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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));
Expand Down
46 changes: 23 additions & 23 deletions experimental/algorithm/LAGraph_BF_full_mxv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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));
Expand Down
17 changes: 8 additions & 9 deletions experimental/algorithm/LAGraph_BF_pure_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit d6e68b3

Please sign in to comment.