diff --git a/cmake_modules/FindGraphBLAS.cmake b/cmake_modules/FindGraphBLAS.cmake index 2c93dcd2f1..228f835cf7 100644 --- a/cmake_modules/FindGraphBLAS.cmake +++ b/cmake_modules/FindGraphBLAS.cmake @@ -68,8 +68,10 @@ message ( STATUS "Looking for SuiteSparse GraphBLAS" ) find_package ( GraphBLAS ${GraphBLAS_FIND_VERSION} CONFIG PATHS ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/../GraphBLAS/build NO_DEFAULT_PATH ) +set ( _lagraph_gb_common_tree ON ) if ( NOT TARGET SuiteSparse::GraphBLAS ) find_package ( GraphBLAS ${GraphBLAS_FIND_VERSION} CONFIG ) + set ( _lagraph_gb_common_tree OFF ) endif ( ) if ( GraphBLAS_FOUND ) @@ -83,11 +85,14 @@ if ( GraphBLAS_FOUND ) else ( ) add_library ( GraphBLAS::GraphBLAS ALIAS ${_graphblas_aliased} ) endif ( ) - if ( GRAPHBLAS_VERSION LESS "8.3.0" ) - # workaround for SuiteSparse:GraphBLAS 8.2.x (did not have "/Include") + if ( GRAPHBLAS_VERSION LESS "8.3.0" AND _lagraph_gb_common_tree ) + # workaround for incorrect INTERFACE_INCLUDE_DIRECTORIES of + # SuiteSparse:GraphBLAS 8.2.x before installation + # (did not have "/Include") get_property ( _inc TARGET GraphBLAS::GraphBLAS PROPERTY INTERFACE_INCLUDE_DIRECTORIES ) - include_directories ( ${_inc}/Include ) + target_include_directories ( GraphBLAS::GraphBLAS INTERFACE + ${_inc}/Include ) message ( STATUS "additional include: ${_inc}/Include" ) endif ( ) endif ( ) @@ -101,12 +106,15 @@ if ( GraphBLAS_FOUND ) else ( ) add_library ( GraphBLAS::GraphBLAS_static ALIAS ${_graphblas_aliased} ) endif ( ) - if ( GRAPHBLAS_VERSION LESS "8.3.0" ) - # workaround for SuiteSparse:GraphBLAS 8.2.x (did not have "/Include") + if ( GRAPHBLAS_VERSION LESS "8.3.0" AND _lagraph_gb_common_tree ) + # workaround for incorrect INTERFACE_INCLUDE_DIRECTORIES of + # SuiteSparse:GraphBLAS 8.2.x before installation + # (did not have "/Include") get_property ( _inc TARGET GraphBLAS::GraphBLAS_static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ) - include_directories ( ${_inc}/Include ) - message ( STATUS "additional include: ${_inc}/Include" ) + target_include_directories ( GraphBLAS::GraphBLAS_static INTERFACE + ${_inc}/Include ) + message ( STATUS "additional include: ${_inc}/Include" ) endif ( ) endif ( ) return ( ) diff --git a/include/LAGraphX.h b/include/LAGraphX.h index f194732f84..b5b8dd180d 100644 --- a/include/LAGraphX.h +++ b/include/LAGraphX.h @@ -49,8 +49,6 @@ extern "C" // development, and is intended only for illustration or testing, not // benchmarking. Do not use for benchmarking without asking the authors. -int LAGr_Reset (char *msg) ; // primarily for testing - //------------------------------------------------------------------------------ // LAGraph_Random_*: Random number generator //------------------------------------------------------------------------------ diff --git a/src/test/test_Xinit.c b/src/test/test_Xinit.c index e9c8b6dee4..9981e0d701 100644 --- a/src/test/test_Xinit.c +++ b/src/test/test_Xinit.c @@ -2,7 +2,7 @@ // LAGraph/src/test/test_Xinit.c: test LAGr_Init and LAGraph_Global //------------------------------------------------------------------------------ -// LAGraph, (c) 2019-2022 by The LAGraph Contributors, All Rights Reserved. +// LAGraph, (c) 2019-2023 by The LAGraph Contributors, All Rights Reserved. // SPDX-License-Identifier: BSD-2-Clause // // For additional details (including references to third party source code and @@ -17,6 +17,7 @@ #include "LAGraph_test.h" #include "LAGraphX.h" +#include "LG_init.h" //------------------------------------------------------------------------------ // global variables @@ -47,6 +48,7 @@ void test_Xinit (void) OK (LAGr_Init (GrB_NONBLOCKING, malloc, calloc, realloc, free, msg)) ; printf ("msg: [%s]\n", msg) ; + TEST_CHECK (LG_get_LAGr_Init_has_been_called ( ) == true) ; // LAGr_Init cannot be called twice int status = LAGr_Init (GrB_NONBLOCKING, @@ -56,14 +58,17 @@ void test_Xinit (void) OK (LAGraph_Finalize (msg)) ; + // the flag is still set after LAGraph_Finalize has been called, + // per LAGraph policy + TEST_CHECK (LG_get_LAGr_Init_has_been_called ( ) == true) ; + // reset and try again - OK (LAGr_Reset (msg)) ; + LG_set_LAGr_Init_has_been_called (false) ; + TEST_CHECK (LG_get_LAGr_Init_has_been_called ( ) == false) ; OK (LAGr_Init (GrB_NONBLOCKING, malloc, calloc, realloc, free, msg)) ; - - // test the failure mode in LAGr_Reset - status = LAGr_Reset (msg) ; - printf ("msg: [%s]\n", msg) ; - TEST_CHECK (status == GrB_INVALID_VALUE) ; + TEST_CHECK (LG_get_LAGr_Init_has_been_called ( ) == true) ; + OK (LAGraph_Finalize (msg)) ; + TEST_CHECK (LG_get_LAGr_Init_has_been_called ( ) == true) ; } //------------------------------------------------------------------------------ @@ -136,12 +141,15 @@ void test_Xinit_brutal (void) } } + TEST_CHECK (LG_get_LAGr_Init_has_been_called ( ) == true) ; + for (int nbrutal = 0 ; nbrutal < 1000 ; nbrutal++) { LG_brutal = nbrutal ; // reset both GraphBLAS and LAGraph GB_Global_GrB_init_called_set (false) ; - OK (LAGr_Reset (msg)) ; + LG_set_LAGr_Init_has_been_called (false) ; + TEST_CHECK (LG_get_LAGr_Init_has_been_called ( ) == false) ; // try to initialize GraphBLAS and LAGraph int result = LAGr_Init (GrB_NONBLOCKING, LG_brutal_malloc, LG_brutal_calloc, diff --git a/src/utility/LAGr_Init.c b/src/utility/LAGr_Init.c index a8dabdb0d3..7fdfde8c26 100644 --- a/src/utility/LAGr_Init.c +++ b/src/utility/LAGr_Init.c @@ -2,7 +2,7 @@ // LAGr_Init: start GraphBLAS and LAGraph, and set malloc/etc functions //------------------------------------------------------------------------------ -// LAGraph, (c) 2019-2022 by The LAGraph Contributors, All Rights Reserved. +// LAGraph, (c) 2019-2023 by The LAGraph Contributors, All Rights Reserved. // SPDX-License-Identifier: BSD-2-Clause // // For additional details (including references to third party source code and @@ -20,10 +20,33 @@ #include "LG_internal.h" //------------------------------------------------------------------------------ -// LG_init_has_been_called: a static value accessible within this file only +// LG_LAGr_Init_has_been_called: a static value only accessible within this file //------------------------------------------------------------------------------ -static bool LG_init_has_been_called = false ; +// LG_LAGr_Init_has_been_called indicates if LAGr_Init has been called. +// LAGr_Init (or LAGraph_Init) can be called only once, even after +// LAGraph_Finalize has been called. For testing purposes, the flag can be +// cleared by src/test/test_Xinit, to allow LAGr_Init or LAGraph_Init to be +// called again. + +static bool LG_LAGr_Init_has_been_called = false ; + +// LG_LAGr_Init_has_been_called is only modified or accessed by these two +// routines (even in this file): + +#include "LG_init.h" + +LAGRAPH_PUBLIC +void LG_set_LAGr_Init_has_been_called (bool setting) +{ + LG_LAGr_Init_has_been_called = setting ; +} + +LAGRAPH_PUBLIC +bool LG_get_LAGr_Init_has_been_called (void) +{ + return (LG_LAGr_Init_has_been_called) ; +} //------------------------------------------------------------------------------ // LAGraph global objects @@ -113,7 +136,7 @@ int LAGr_Init GrB_Info info ; // ensure LAGr_Init has not already been called - LG_ASSERT_MSG (!LG_init_has_been_called, GrB_INVALID_VALUE, + LG_ASSERT_MSG (!LG_get_LAGr_Init_has_been_called ( ), GrB_INVALID_VALUE, "LAGr*_Init can only be called once") ; //-------------------------------------------------------------------------- @@ -297,37 +320,10 @@ int LAGr_Init GrB_MIN_MONOID_UINT64 , GrB_ONEB_UINT64)) ; GRB_TRY (GrB_Semiring_new (&LAGraph_any_one_fp32, GrB_MIN_MONOID_FP32 , GrB_ONEB_FP32 )) ; - // LAGraph_any_one_fp64 is the last object created: GRB_TRY (GrB_Semiring_new (&LAGraph_any_one_fp64, GrB_MIN_MONOID_FP64 , GrB_ONEB_FP64 )) ; - LG_init_has_been_called = true ; - return (GrB_SUCCESS) ; -} - -//------------------------------------------------------------------------------ -// LAGr_Reset -//------------------------------------------------------------------------------ - -// This method is meant primarily for testing. It can be only called after -// LAGraph_Finalize has been called; it returns GrB_INVALID otherwise. The -// method allows the testing framework to reset the internal flag that says -// LAGr_Init has been called, so that LAGr_Init can be called again within the -// test. - -int LAGr_Reset (char *msg) -{ - LG_CLEAR_MSG ; - // check if the last created object has been freed - if (LAGraph_any_one_fp64 != NULL) - { - LG_ASSERT_MSG (false, GrB_INVALID_VALUE, - "LAGr_Reset can only be called after LAGraph_Finalize" - " or before LAGr_Init") ; - } - // only set it to false if the object has been cleared. - LG_init_has_been_called = false ; - // now LAGr_Init can be called again. + LG_set_LAGr_Init_has_been_called (true) ; return (GrB_SUCCESS) ; } diff --git a/src/utility/LG_init.h b/src/utility/LG_init.h new file mode 100644 index 0000000000..73ac9ff8aa --- /dev/null +++ b/src/utility/LG_init.h @@ -0,0 +1,32 @@ +//------------------------------------------------------------------------------ +// LG_init.h: include file for use within LAGraph itself +//------------------------------------------------------------------------------ + +// LAGraph, (c) 2019-2023 by The LAGraph Contributors, All Rights Reserved. +// SPDX-License-Identifier: BSD-2-Clause +// +// For additional details (including references to third party source code and +// other files) see the LICENSE file or contact permission@sei.cmu.edu. See +// Contributors.txt for a full list of contributors. Created, in part, with +// funding and support from the U.S. Government (see Acknowledgments.txt file). +// DM22-0790 + +// Contributed by Timothy A. Davis, Texas A&M University + +//------------------------------------------------------------------------------ + +// These definitions are not meant for the user application that relies on +// LAGraph and/or GraphBLAS. LG_* methods are for internal use in LAGraph. + +#ifndef LG_INIT_H +#define LG_INIT_H + +//------------------------------------------------------------------------------ +// definitions used in LAGr_Init.c and for testing +//------------------------------------------------------------------------------ + +LAGRAPH_PUBLIC void LG_set_LAGr_Init_has_been_called (bool setting) ; +LAGRAPH_PUBLIC bool LG_get_LAGr_Init_has_been_called (void) ; + +#endif +