Skip to content

Commit 0d45227

Browse files
Merge pull request #372 from GraphBLAS/with_GraphBLAS_v10
msf: add new output parameter, and testing
2 parents 5e9cc46 + a0fc810 commit 0d45227

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

experimental/algorithm/LAGraph_msf.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ void LG_MSF_tupleEq_fp (bool *z, const LG_MSF_tuple_fp *x, const LG_MSF_tuple_fp
359359
LAGraph_Free ((void **) &context_int.parent, msg); \
360360
LAGraph_Free ((void **) &context_fp.parent, msg); \
361361
GrB_free (&f); \
362+
GrB_free (&w); \
362363
GrB_free (&I); \
363364
GrB_free (&t); \
364365
GrB_free (&edge); \
@@ -452,6 +453,7 @@ int LAGraph_msf
452453
(
453454
GrB_Matrix *forest_edges, // output: an unsymmetrical matrix, containing
454455
// the edges in the spanning forest
456+
GrB_Vector *componentId, // output: The connected component of each node
455457
GrB_Matrix A, // input matrix
456458
bool sanitize, // if true, ensure A is symmetric
457459
char *msg
@@ -707,19 +709,17 @@ int LAGraph_msf
707709
{
708710
LG_TRY (LAGraph_Malloc
709711
((void **) &context_int.parent, n, sizeof (uint64_t), msg)) ;
710-
for (uint64_t i = 0; i < n; i++)
711-
context_int.parent[i] = i;
712+
GRB_TRY (GrB_Vector_extractTuples (NULL, context_int.parent, &n, f)) ;
712713
GRB_TRY (GxB_Vector_load(parent_v, (void **) &context_int.parent,
713-
GrB_UINT64, n, 3 * n * sizeof (uint64_t), GxB_IS_READONLY, NULL)) ;
714+
GrB_UINT64, n, n * sizeof (uint64_t), GxB_IS_READONLY, NULL)) ;
714715
}
715716
else
716717
{
717718
LG_TRY (LAGraph_Malloc
718-
((void **) &context_fp.parent, n, sizeof (uint64_t), msg)) ;
719-
for (uint64_t i = 0; i < n; i++)
720-
context_fp.parent[i] = i;
719+
((void **) &context_fp.parent, n, sizeof (double), msg)) ;
720+
GRB_TRY (GrB_Vector_extractTuples (NULL, context_fp.parent, &n, f)) ;
721721
GRB_TRY (GxB_Vector_load(parent_v, (void **) &context_fp.parent,
722-
GrB_UINT64, n, 3 * n * sizeof (uint64_t), GxB_IS_READONLY, NULL)) ;
722+
GrB_UINT64, n, n * sizeof (double), GxB_IS_READONLY, NULL)) ;
723723
}
724724

725725
//--------------------------------------------------------------------------
@@ -862,6 +862,13 @@ int LAGraph_msf
862862

863863
*forest_edges = T;
864864
T = NULL ;
865+
866+
if(componentId != NULL)
867+
{
868+
*componentId = f;
869+
f = NULL;
870+
}
871+
865872
LG_FREE_ALL;
866873
return (GrB_SUCCESS) ;
867874
#else

experimental/benchmark/msf_demo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int main (int argc, char **argv)
7979
LG_TRY (LAGraph_Cached_OutDegree (G, msg)) ;
8080
printf("Starting MSF\n\n") ;
8181
t = LAGraph_WallClockTime ( ) ;
82-
LG_TRY (LAGraph_msf (&A, G->A, false, msg)) ;
82+
LG_TRY (LAGraph_msf (&A, NULL, G->A, false, msg)) ;
8383
t = LAGraph_WallClockTime ( ) - t ;
8484
printf ("LAGraph_msf took %g sec\n", t) ;
8585

experimental/test/test_msf.c

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const matrix_info files [ ] =
7070
//****************************************************************************
7171
void test_msf (void)
7272
{
73+
#if LG_SUITESPARSE_GRAPHBLAS_V10
7374
LAGraph_Init (msg) ;
7475
bool burble = false ;
7576
GrB_Scalar zeroB = NULL;
@@ -112,13 +113,18 @@ void test_msf (void)
112113
for (int jit = 0 ; jit <= 1 ; jit++)
113114
{
114115
if (jit) printf ("\nJIT is enabled\n") ; else printf ("\nJIT is disabled\n") ;
116+
117+
// connected components
118+
GrB_Vector cc0 = NULL, cc1 = NULL, cc2 = NULL;
119+
115120
OK (GxB_Global_Option_set (GxB_JIT_C_CONTROL,
116121
jit ? GxB_JIT_ON : GxB_JIT_OFF)) ;
117122
// compute the min spanning forest
118123
C = NULL ;
119124
OK (LG_SET_BURBLE (burble)) ;
120-
int result = LAGraph_msf (&C, A, sanitize, msg) ;
125+
int result = LAGraph_msf (&C, &cc0, A, sanitize, msg) ;
121126
OK (LG_SET_BURBLE (false)) ;
127+
122128
printf ("result: %d\n", result) ;
123129
OK(result);
124130
GrB_Matrix_nvals(&branches, C);
@@ -133,22 +139,24 @@ void test_msf (void)
133139
OK (GrB_Matrix_eWiseAdd_BinaryOp(
134140
S, NULL, NULL, GxB_ANY_BOOL, S, S, GrB_DESC_T1)) ;
135141
}
136-
OK (GrB_Matrix_new(&S_C, GrB_BOOL, n, n)) ;
137-
OK (GrB_Matrix_assign_BOOL(
138-
S_C, C, NULL, (bool) true, GrB_ALL, n, GrB_ALL, n, GrB_DESC_S)) ;
139-
OK (GrB_Matrix_eWiseAdd_BinaryOp(
140-
S_C, NULL, NULL, GxB_ANY_BOOL, S_C, S_C, GrB_DESC_T1)) ;
141142
OK(LAGraph_New(&G, &S, LAGraph_ADJACENCY_UNDIRECTED, msg));
142-
OK(LAGraph_New(&G_C, &S_C, LAGraph_ADJACENCY_UNDIRECTED, msg));
143-
144-
143+
145144
//Check that the graph has all the same ccs.
146-
GrB_Vector cc0 = NULL, cc1 = NULL;
147-
OK (LAGr_ConnectedComponents(&cc0, G, msg));
148-
OK (LAGr_ConnectedComponents(&cc1, G_C, msg));
145+
OK (LAGr_ConnectedComponents(&cc1, G, msg)) ;
149146
bool ok = false ;
150-
OK (LAGraph_Vector_IsEqual(&ok, cc0, cc1, msg));
151-
TEST_CHECK(ok);
147+
OK (GrB_Vector_new(&cc2, GrB_UINT64, n)) ;
148+
// cc1 and cc0 should have the same structure as cc2.
149+
// make their values equal and then compare them.
150+
// msf does not guarentee that the lower node is used as componentId
151+
OK (GxB_Vector_extract_Vector(cc2, NULL, NULL, cc0, cc1, NULL)) ;
152+
OK (LAGraph_Vector_IsEqual(&ok, cc2, cc0, msg)) ;
153+
154+
// if(!ok)
155+
// {
156+
// GxB_print(cc2, GxB_SHORT);
157+
// GxB_print(cc0, GxB_SHORT);
158+
// }
159+
TEST_ASSERT(ok) ;
152160
// check result C for A.mtx
153161
if (files[k].ans_i && files[k].ans_j)
154162
{
@@ -169,9 +177,9 @@ void test_msf (void)
169177
fabs(tot_weight - ans_w) <= 1E-10 * fabs(ans_w)) ;
170178
OK (LAGraph_Matrix_Print (C, pr, stdout, msg)) ;
171179
OK (LAGraph_Delete (&G, msg)) ;
172-
OK (LAGraph_Delete (&G_C, msg)) ;
173180
OK (GrB_free (&cc0)) ;
174181
OK (GrB_free (&cc1)) ;
182+
OK (GrB_free (&cc2)) ;
175183
OK (GrB_free (&C)) ;
176184

177185
printf ("JIT test is done\n") ;
@@ -181,6 +189,7 @@ void test_msf (void)
181189
}
182190
GrB_free(&zeroB);
183191
LAGraph_Finalize (msg) ;
192+
#endif
184193
}
185194

186195
//------------------------------------------------------------------------------
@@ -219,13 +228,13 @@ void test_inf_msf (void)
219228
// compute the min spanning forest
220229
S_C = C = NULL ;
221230
OK (LG_SET_BURBLE (burble)) ;
222-
int result = LAGraph_msf (&C, A, false, msg) ;
231+
int result = LAGraph_msf (&C, NULL, A, false, msg) ;
223232
OK (LG_SET_BURBLE (false)) ;
224233
printf ("result: %d\n", result) ;
225234
OK(result);
226235

227236
OK (LG_SET_BURBLE (burble)) ;
228-
result = LAGraph_msf (&S_C, S, false, msg) ;
237+
result = LAGraph_msf (&S_C, NULL, S, false, msg) ;
229238
OK (LG_SET_BURBLE (false)) ;
230239
printf ("result: %d\n", result) ;
231240
OK(result);
@@ -252,24 +261,24 @@ void test_errors (void)
252261

253262
#if LG_SUITESPARSE_GRAPHBLAS_V10
254263
// C and A are NULL
255-
int result = LAGraph_msf (NULL, NULL, true, msg) ;
264+
int result = LAGraph_msf (NULL, NULL, NULL, true, msg) ;
256265
TEST_CHECK (result == GrB_NULL_POINTER) ;
257266

258267
// A must be square
259268
OK (GrB_Matrix_new (&A, GrB_UINT64, 3, 4)) ;
260-
result = LAGraph_msf (&C, A, true, msg) ;
269+
result = LAGraph_msf (&C, NULL, A, true, msg) ;
261270
TEST_CHECK (result == GrB_DIMENSION_MISMATCH) ;
262271
OK (GrB_free (&A)) ;
263272

264273
// A must real
265274
OK (GrB_Matrix_new (&A, GxB_FC32, 4, 4)) ;
266-
result = LAGraph_msf (&C, A, true, msg) ;
275+
result = LAGraph_msf (&C, NULL, A, true, msg) ;
267276
TEST_CHECK (result == GrB_DOMAIN_MISMATCH) ;
268277

269278
#else
270279
// Not implemented
271280
OK (GrB_Matrix_new (&A, GrB_BOOL, 4, 4)) ;
272-
int result = LAGraph_msf (&C, A, true, msg) ;
281+
int result = LAGraph_msf (&C, NULL, A, true, msg) ;
273282
TEST_CHECK (result == GrB_NOT_IMPLEMENTED) ;
274283
#endif
275284

include/LAGraphX.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,9 @@ int LAGraph_lcc // compute lcc for all nodes in A
815815
LAGRAPHX_PUBLIC
816816
int LAGraph_msf
817817
(
818-
GrB_Matrix *result, // output: an unsymmetrical matrix, the spanning forest
818+
GrB_Matrix *forest_edges, // output: an unsymmetrical matrix, containing
819+
// the edges in the spanning forest
820+
GrB_Vector *componentId, // output: The connected component of each node
819821
GrB_Matrix A, // input matrix
820822
bool sanitize, // if true, ensure A is symmetric
821823
char *msg

0 commit comments

Comments
 (0)