Skip to content

Commit

Permalink
enable LG_CC_Boruvka only on 64-bit platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTimothyAldenDavis committed Oct 27, 2023
1 parent 6d64ac6 commit b9a7496
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
8 changes: 5 additions & 3 deletions LAGraph/experimental/algorithm/LAGraph_cc_lacc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
{ \
free(I); \
free(V); \
GrB_free (&S2) ; \
GrB_free (&stars); \
GrB_free (&mask); \
GrB_free (&parents); \
Expand Down Expand Up @@ -91,6 +92,7 @@ int LAGraph_cc_lacc
GrB_Vector tmp = NULL, pNonstars = NULL, nsgp = NULL; // temporary
GrB_Index *I = NULL;
GrB_Index *V = NULL;
GrB_Matrix S = NULL, S2 = NULL ;

GrB_Index n ;
GRB_TRY (GrB_Matrix_nrows (&n, A)) ;
Expand All @@ -99,11 +101,11 @@ int LAGraph_cc_lacc
//printf ("number of nodes: %g\n", (double) n) ;
//printf ("number of edges: %g\n", (double) nnz) ;

GrB_Matrix S = NULL;
if (sanitize)
{
GRB_TRY (GrB_Matrix_new (&S, GrB_BOOL, n, n)) ;
GRB_TRY (GrB_eWiseAdd (S, NULL, NULL, GrB_LOR, A, A, GrB_DESC_T1)) ;
GRB_TRY (GrB_Matrix_new (&S2, GrB_BOOL, n, n)) ;
GRB_TRY (GrB_eWiseAdd (S2, NULL, NULL, GrB_LOR, A, A, GrB_DESC_T1)) ;
S = S2 ;
}
else
{
Expand Down
19 changes: 7 additions & 12 deletions LAGraph/src/algorithm/LG_CC_Boruvka.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void my_select_func (void *z, const void *x,
LAGraph_Free ((void **) &I, NULL) ; \
LAGraph_Free ((void **) &Px, NULL) ; \
LAGraph_Free ((void **) &mem, NULL) ; \
GrB_free (&S) ; \
GrB_free (&Parent_Type) ; \
GrB_free (&gp) ; \
GrB_free (&mnp) ; \
Expand Down Expand Up @@ -142,27 +143,20 @@ int LG_CC_Boruvka
LAGRAPH_SYMMETRIC_STRUCTURE_REQUIRED,
"G->A must be known to be symmetric") ;

#if 0
// determine the pointer size
#if defined (UINT64_MAX) && UINT64_MAX == UINTPTR_MAX
GrB_Type UintPtr_type = GrB_UINT64;
#elif defined (UINT32_MAX) && UINT32_MAX == UINTPTR_MAX
// 32-bit case: this works on all but Alpine Linux x86, so LG_CC_Boruvka is
// disabled for now (see the test above)
GrB_Type UintPtr_type = GrB_UINT32;
#if !(defined (UINT64_MAX) && UINT64_MAX == UINTPTR_MAX)

// FIXME: LG_CC_Boruvka method fails on an Alpine Linux x86 (32-bit) system
// with SIGILL, so it is disabled (for now) when using a 32-bit platform.
// When using SuiteSparse, LAGr_ConnectedComponents uses LG_CC_FastSV6
// instead anyway. It seems to work on other 32-bit platforms, but it
// might be fragile by depending upon undefined behavior that just happens
// to work on those platforms. So for now, this method is disabled on all
// 32-bit platforms.

LG_ASSERT_MSG (false, GrB_NOT_IMPLEMENTED, "LG_CC_Boruvka method: "
" not implemented on 32-bit platforms") ;
#else
# error "system has an unsupported sizeof (uintptr_t)"
#endif
#endif

#else

//--------------------------------------------------------------------------
// initializations
Expand Down Expand Up @@ -297,5 +291,6 @@ int LG_CC_Boruvka
(*component) = parent ;
LG_FREE_WORK ;
return (GrB_SUCCESS) ;
#endif
}

5 changes: 3 additions & 2 deletions LAGraph/src/algorithm/LG_CC_FastSV6.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ int LG_CC_FastSV6 // SuiteSparse:GraphBLAS method, with GxB extensions

LG_TRY (LAGraph_CheckGraph (G, msg)) ;
LG_ASSERT (component != NULL, GrB_NULL_POINTER) ;
(*component) = NULL ;

LG_ASSERT_MSG ((G->kind == LAGraph_ADJACENCY_UNDIRECTED ||
(G->kind == LAGraph_ADJACENCY_DIRECTED &&
Expand Down Expand Up @@ -474,7 +475,7 @@ int LG_CC_FastSV6 // SuiteSparse:GraphBLAS method, with GxB extensions
// find the connected components of T
//----------------------------------------------------------------------

GRB_TRY (fastsv (T, parent, mngp, &gp, &gp_new, t, eq, min, min_2nd,
LG_TRY (fastsv (T, parent, mngp, &gp, &gp_new, t, eq, min, min_2nd,
C, &Cp, &Px, &Cx, msg)) ;

//----------------------------------------------------------------------
Expand Down Expand Up @@ -654,7 +655,7 @@ int LG_CC_FastSV6 // SuiteSparse:GraphBLAS method, with GxB extensions
// final phase
//--------------------------------------------------------------------------

GRB_TRY (fastsv (A, parent, mngp, &gp, &gp_new, t, eq, min, min_2nd,
LG_TRY (fastsv (A, parent, mngp, &gp, &gp_new, t, eq, min, min_2nd,
C, &Cp, &Px, &Cx, msg)) ;

//--------------------------------------------------------------------------
Expand Down
10 changes: 8 additions & 2 deletions LAGraph/src/test/test_ConnectedComponents.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ void test_cc_matrices (void)

// check the result
OK (LG_check_cc (C, G, msg)) ;
OK (GrB_free (&C)) ;

// find the connected components with LG_CC_FastSV5
#if LAGRAPH_SUITESPARSE
Expand All @@ -136,11 +137,17 @@ void test_cc_matrices (void)
// find the connected components with LG_CC_Boruvka
int result = GrB_SUCCESS ;
printf ("\n------ CC_BORUVKA:\n") ;
OK (LG_CC_Boruvka (&C2, G, msg)) ;
result = LG_CC_Boruvka (&C2, G, msg) ;

#if (defined (UINT64_MAX) && UINT64_MAX == UINTPTR_MAX)
OK (result) ;
ncomponents = count_connected_components (C2) ;
TEST_CHECK (ncomponents == ncomp) ;
OK (LG_check_cc (C2, G, msg)) ;
OK (GrB_free (&C2)) ;
#else
TEST_CHECK (result == GrB_NOT_IMPLEMENTED) ;
#endif

result = LG_CC_Boruvka (NULL, G, msg) ;
TEST_CHECK (result == GrB_NULL_POINTER) ;
Expand Down Expand Up @@ -168,7 +175,6 @@ void test_cc_matrices (void)
}

OK (LAGraph_Delete (&G, msg)) ;
OK (GrB_free (&C)) ;
}

OK (LAGraph_Finalize (msg)) ;
Expand Down

0 comments on commit b9a7496

Please sign in to comment.