### Set up venv Virtual Environment for Documentation Source: https://github.com/graphblas/lagraph/blob/stable/rtdocs/README.md Creates and activates a Python virtual environment, installs Sphinx and related themes, and then deactivates the environment. This is a one-time setup. ```bash cd LAGraph/rtdocs python -m venv .venv source .venv/bin/activate pip install sphinx==4.0.3 pip install sphinx_rtd_theme==0.5.2 pip install breathe deactivate ``` -------------------------------- ### Basic LAGraph Example Source: https://github.com/graphblas/lagraph/blob/stable/rtdocs/index.md This example demonstrates initializing LAGraph, reading a graph from a Matrix Market file, computing node out-degrees, calculating PageRank, printing the results, and finalizing LAGraph. Error checking is omitted for brevity. ```C #include "LAGraph.h" int main (void) { // initialize LAGraph char msg [LAGRAPH_MSG_LEN] ; LAGraph_Init (msg) ; GrB_Matrix A = NULL ; GrB_Vector centrality = NULL ; LAGraph_Graph G = NULL ; // read a Matrix Market file from stdin and create a graph LAGraph_MMRead (&A, stdin, msg) ; LAGraph_New (&G, &A, LAGraph_ADJACENCY_UNDIRECTED, msg) ; // compute the out-degree of every node LAGraph_Cached_OutDegree (G, msg) ; // compute the pagerank int niters = 0 ; LAGr_PageRank (¢rality, &niters, G, 0.85, 1e-4, 100, msg) ; // print the result LAGraph_Vector_Print (centrality, LAGraph_COMPLETE, stdout, msg) ; // free the graph, the pagerank, and finish LAGraph LAGraph_Delete (&G, msg) ; GrB_free (¢rality) ; LAGraph_Finalize (msg) ; } ``` -------------------------------- ### Custom Installation Prefix with CMake Source: https://github.com/graphblas/lagraph/blob/stable/README.md Instructions for compiling and installing LAGraph to a custom directory using CMake, bypassing the default Makefile installation. ```bash cd build cmake -DCMAKE_INSTALL_PREFIX="/home/me/mystuff" .. make make install ``` -------------------------------- ### Compile, Test, and Install LAGraph (Linux/Mac) Source: https://github.com/graphblas/lagraph/blob/stable/README.md Standard commands to build, test, and install LAGraph on Linux and macOS systems using the provided Makefile. ```bash make make test sudo make install ``` -------------------------------- ### Set up Conda Virtual Environment for Documentation Source: https://github.com/graphblas/lagraph/blob/stable/rtdocs/README.md Creates a new conda environment with Python 3.9, installs Doxygen, CMake, Sphinx, and related themes. It then deactivates the environment. ```bash conda create -n lagraph python=3.9 conda activate lagraph conda install -y -c conda-forge doxygen cmake sphinx==4.0.3 conda install -y -c conda-forge sphinx_rtd_theme==0.5.2 breathe conda deactivate ``` -------------------------------- ### Configure Package Config File (Install) Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt Generates the LAGraphConfig.cmake file for installation, making it available for external projects using `find_package`. This ensures the package configuration is correctly installed. ```cmake set ( SUITESPARSE_IN_BUILD_TREE OFF ) configure_package_config_file ( Config/LAGraphConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/target/LAGraphConfig.cmake INSTALL_DESTINATION ${SUITESPARSE_PKGFILEDIR}/cmake/LAGraph ) ``` -------------------------------- ### Install Package Configuration Files Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt Installs the generated package configuration files (Config.cmake, ConfigVersion.cmake) and the FindGraphBLAS.cmake module. These files are necessary for other projects to find and use LAGraph via `find_package`. ```cmake install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/target/LAGraphConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/LAGraphConfigVersion.cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindGraphBLAS.cmake DESTINATION ${SUITESPARSE_PKGFILEDIR}/cmake/LAGraph ) ``` -------------------------------- ### Install LAGraph on Linux/Mac Source: https://github.com/graphblas/lagraph/blob/stable/rtdocs/installation.md If you have system administrator privileges, use this command to install LAGraph after compilation and testing. This command requires sudo access. ```bash sudo make install ``` -------------------------------- ### Install Static Libraries Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt Installs static LAGraph libraries and headers. This snippet is conditional on BUILD_STATIC_LIBS being enabled. ```cmake install ( TARGETS LAGraph_static LAGraphX_static EXPORT LAGraphTargets_static ARCHIVE DESTINATION ${SUITESPARSE_LIBDIR} PUBLIC_HEADER DESTINATION ${SUITESPARSE_INCLUDEDIR} ) ``` -------------------------------- ### Install Shared Libraries Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt Installs shared LAGraph libraries and headers. This snippet is conditional on BUILD_SHARED_LIBS being enabled. ```cmake install ( TARGETS LAGraph LAGraphX EXPORT LAGraphTargets LIBRARY DESTINATION ${SUITESPARSE_LIBDIR} ARCHIVE DESTINATION ${SUITESPARSE_LIBDIR} RUNTIME DESTINATION ${SUITESPARSE_BINDIR} PUBLIC_HEADER DESTINATION ${SUITESPARSE_INCLUDEDIR} ) ``` -------------------------------- ### Find GraphBLAS Installation Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt This snippet attempts to find the GraphBLAS library. It first checks for a predefined SuiteSparse root and then falls back to using the FindGraphBLAS.cmake module if not found. ```cmake if ( SUITESPARSE_ROOT_CMAKELISTS ) message ( STATUS "Looking for GraphBLAS in SuiteSparse" ) if ( TARGET GraphBLAS ) add_library ( GraphBLAS::GraphBLAS ALIAS GraphBLAS ) else ( ) add_library ( GraphBLAS::GraphBLAS ALIAS GraphBLAS_static ) endif ( ) if ( TARGET GraphBLAS_static ) add_library ( GraphBLAS::GraphBLAS_static ALIAS GraphBLAS_static ) endif ( ) else ( ) # If GraphBLAS is not in a standard installation location, either # export GRAPHBLAS_ROOT # or # GRAPHBLAS_ROOT= cmake .. # or uncomment the next line: # set ( ENV{GRAPHBLAS_ROOT} ${PROJECT_SOURCE_DIR}/../GraphBLAS ) # The ../GraphBLAS folder is considered by default, if it exists. # message ( STATUS "GraphBLAS_ROOT: ${GraphBLAS_ROOT} $ENV{GRAPHBLAS_ROOT}" ) # message ( STATUS "GRAPHBLAS_ROOT: ${GRAPHBLAS_ROOT} $ENV{GRAPHBLAS_ROOT}" ) # No package version is explicitly stated here; an arbitrary GraphBLAS # library can have any version number. For SuiteSparse:GraphBLAS, LAGraph # requires v7.1.0 or later, which is checked in LAGraph.h. message ( STATUS "Looking for GraphBLAS with FindGraphBLAS.cmake" ) find_package ( GraphBLAS MODULE REQUIRED ) endif ( ) ``` -------------------------------- ### Define Test Library Sources Source: https://github.com/graphblas/lagraph/blob/stable/src/test/CMakeLists.txt Globally finds all C source files starting with 'LG_' in the current directory to be used for the lagraphtest library. ```cmake file ( GLOB LAGRAPHTEST_LIB_SOURCES "LG_*.c" ) ``` -------------------------------- ### Export Static Targets Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt Creates and installs export target files for static libraries, enabling `find_package` for consumers. This snippet is conditional on BUILD_STATIC_LIBS being enabled. ```cmake export ( EXPORT LAGraphTargets_static NAMESPACE SuiteSparse:: FILE ${CMAKE_CURRENT_BINARY_DIR}/LAGraphTargets_static.cmake ) install ( EXPORT LAGraphTargets_static NAMESPACE SuiteSparse:: DESTINATION ${SUITESPARSE_PKGFILEDIR}/cmake/LAGraph ) ``` -------------------------------- ### Configure pkg-config File for LAGraph Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt This snippet configures and generates the LAGraph.pc file, which is used by pkg-config to provide build information for the LAGraph library. It sets up installation paths for libraries and include files based on build configurations. ```cmake if ( NOT MSVC ) if ( BUILD_STATIC_LIBS ) if ( NOT NO_LIBM ) list ( APPEND LAGRAPH_STATIC_LIBS "m" ) endif ( ) endif ( ) # This might be something like: # /usr/lib/libgomp.so;/usr/lib/libpthread.a;m # convert to -l flags for pkg-config, i.e.: "-lgomp -lpthread -lm" set ( LAGRAPH_STATIC_LIBS_LIST ${LAGRAPH_STATIC_LIBS} ) set ( LAGRAPH_STATIC_LIBS "" ) foreach ( _lib ${LAGRAPH_STATIC_LIBS_LIST} ) string ( FIND ${_lib} "." _pos REVERSE ) if ( ${_pos} EQUAL "-1" ) set ( LAGRAPH_STATIC_LIBS "${LAGRAPH_STATIC_LIBS} -l${_lib}" ) continue () endif ( ) set ( _kinds "SHARED" "STATIC" ) if ( WIN32 ) list ( PREPEND _kinds "IMPORT" ) endif ( ) foreach ( _kind IN LISTS _kinds ) set ( _regex ".*\/(lib)?([^\\.]*)(${CMAKE_${_kind}_LIBRARY_SUFFIX})" ) if ( ${_lib} MATCHES ${_regex} ) string ( REGEX REPLACE ${_regex} "\\2" _libname ${_lib} ) if ( NOT "${_libname}" STREQUAL "" ) set ( LAGRAPH_STATIC_LIBS "${LAGRAPH_STATIC_LIBS} -l${_libname}" ) break () endif ( ) endif ( ) endforeach ( ) endforeach ( ) if ( BUILD_STATIC_LIBS ) set ( LAGRAPH_STATIC_LIBS "-l$ ${LAGRAPH_STATIC_LIBS}" ) endif ( ) set ( prefix "${CMAKE_INSTALL_PREFIX}" ) set ( exec_prefix "\${prefix}" ) cmake_path ( IS_ABSOLUTE SUITESPARSE_LIBDIR SUITESPARSE_LIBDIR_IS_ABSOLUTE ) if ( SUITESPARSE_LIBDIR_IS_ABSOLUTE ) set ( libdir "${SUITESPARSE_LIBDIR}") else ( ) set ( libdir "\${exec_prefix}/${SUITESPARSE_LIBDIR}") endif ( ) cmake_path ( IS_ABSOLUTE SUITESPARSE_INCLUDEDIR SUITESPARSE_INCLUDEDIR_IS_ABSOLUTE ) if ( SUITESPARSE_INCLUDEDIR_IS_ABSOLUTE ) set ( includedir "${SUITESPARSE_INCLUDEDIR}") else ( ) set ( includedir "\${prefix}/${SUITESPARSE_INCLUDEDIR}") endif ( ) if ( BUILD_SHARED_LIBS ) set ( SUITESPARSE_LIB_BASE_NAME $ ) else ( ) set ( SUITESPARSE_LIB_BASE_NAME $ ) endif ( ) configure_file ( Config/LAGraph.pc.in LAGraph.pc.out @ONLY NEWLINE_STYLE LF ) file ( GENERATE OUTPUT LAGraph.pc INPUT ${CMAKE_CURRENT_BINARY_DIR}/LAGraph.pc.out NEWLINE_STYLE LF ) install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/LAGraph.pc DESTINATION ${SUITESPARSE_PKGFILEDIR}/pkgconfig ) endif ( ) ``` -------------------------------- ### Export Shared Targets Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt Creates and installs export target files for shared libraries, enabling `find_package` for consumers. This snippet is conditional on BUILD_SHARED_LIBS being enabled. ```cmake export ( EXPORT LAGraphTargets NAMESPACE SuiteSparse:: FILE ${CMAKE_CURRENT_BINARY_DIR}/LAGraphTargets.cmake ) install ( EXPORT LAGraphTargets NAMESPACE SuiteSparse:: DESTINATION ${SUITESPARSE_PKGFILEDIR}/cmake/LAGraph ) ``` -------------------------------- ### Run GAP Benchmarks with Custom Directory and Matrix Market Files Source: https://github.com/graphblas/lagraph/blob/stable/src/benchmark/README.md Execute the GAP benchmarks using Matrix Market (.mtx) files located in a specified directory. The 'mtx' argument indicates the file format, followed by the path to the GAP directory. Output is redirected to 'myoutput.txt'. ```bash ./do_gap_all mtx /my/big/filestuff/GAP > myoutput.txt ``` -------------------------------- ### Run GAP Benchmarks with Custom Directory and Binary .grb Files Source: https://github.com/graphblas/lagraph/blob/stable/src/benchmark/README.md Execute the GAP benchmarks using binary (.grb) files located in a specified directory. The 'grb' argument indicates the file format, followed by the path to the GAP directory. Output is redirected to 'myoutput.txt'. ```bash ./do_gap_all grb /my/big/filestuff/GAP > myoutput.txt ``` -------------------------------- ### Run GAP Benchmarks with Binary .grb Files Source: https://github.com/graphblas/lagraph/blob/stable/src/benchmark/README.md This command runs all GAP benchmarks using the pre-converted binary (.grb) files. This is generally faster than using .mtx files. Output is redirected to 'myoutput.txt'. ```bash ./do_gap_all grb > myoutput.txt ``` -------------------------------- ### Run GAP Benchmarks with Matrix Market Files Source: https://github.com/graphblas/lagraph/blob/stable/src/benchmark/README.md This command runs all GAP benchmarks using the original Matrix Market (.mtx) files. Output is redirected to 'myoutput.txt'. ```bash ./do_gap_all > myoutput.txt ``` -------------------------------- ### Discover and Build Benchmark Executables Source: https://github.com/graphblas/lagraph/blob/stable/src/benchmark/CMakeLists.txt This snippet finds all C files ending in '_demo.c' in the benchmark directory, creates an executable for each, sets the C standard to 11, and links the appropriate LAGraph and GraphBLAS libraries based on whether shared libraries are enabled. ```cmake include_directories ( ${PROJECT_SOURCE_DIR}/src/test/include ${PROJECT_SOURCE_DIR}/src/algorithm ) file( GLOB DEMO_SOURCES LIST_DIRECTORIES false *_demo.c ) foreach( demosourcefile ${DEMO_SOURCES} ) get_filename_component(justname ${demosourcefile} NAME) string( REPLACE ".c" "" demoname ${justname} ) # message("Adding: ${demoname}") add_executable( ${demoname} ${demosourcefile} ) set_target_properties ( ${demoname} PROPERTIES C_STANDARD_REQUIRED ON C_STANDARD 11 ) if ( BUILD_SHARED_LIBS ) target_link_libraries( ${demoname} LAGraph LAGraphX lagraphtest GraphBLAS::GraphBLAS ) else ( ) target_link_libraries( ${demoname} LAGraph_static LAGraphX_static lagraphtest_static GraphBLAS::GraphBLAS ) endif ( ) if ( NOT NO_LIBM ) target_link_libraries ( ${demoname} m ) endif ( ) endforeach( demosourcefile ${DEMO_SOURCES} ) ``` -------------------------------- ### Run BFS Demo on bcsstk13.mtx Source: https://github.com/graphblas/lagraph/blob/stable/src/benchmark/README.md This command runs the Breadth-First Search (BFS) demo on the bcsstk13.mtx file, selecting 64 random source nodes. The input matrix is piped from the data folder. ```bash ../../build/src/demo/bfs_demo < ../data/bcsstk13.mtx ``` -------------------------------- ### Uninstall LAGraph Source: https://github.com/graphblas/lagraph/blob/stable/README.md Command to remove LAGraph from the system after it has been installed. ```bash make uninstall ``` -------------------------------- ### Build LAGraph Documentation with venv Source: https://github.com/graphblas/lagraph/blob/stable/rtdocs/README.md Activates the previously set up venv environment and executes the documentation build script. Ensure you are in the correct directory. ```bash cd LAGraph/rtdocs source .venv/bin/activate ./make_docs.sh ``` -------------------------------- ### Discover and Build Benchmark Executables Source: https://github.com/graphblas/lagraph/blob/stable/experimental/benchmark/CMakeLists.txt This snippet discovers C source files ending with '_demo.c' in the project's source directory. It then creates an executable for each discovered file, sets the C standard to 11, and links the necessary LAGraph and GraphBLAS libraries. Conditional linking is used based on whether shared or static libraries are being built. ```cmake file( GLOB DEMO_SOURCES LIST_DIRECTORIES false *_demo.c ) foreach( demosourcefile ${DEMO_SOURCES} ) get_filename_component(justname ${demosourcefile} NAME) string( REPLACE ".c" "" demoname ${justname} ) # message("Adding: ${demoname}") add_executable( ${demoname} ${demosourcefile} ) set_target_properties ( ${demoname} PROPERTIES C_STANDARD_REQUIRED ON C_STANDARD 11 ) if ( BUILD_SHARED_LIBS ) target_link_libraries( ${demoname} LAGraphX LAGraph lagraphtest lagraphxtest GraphBLAS::GraphBLAS ) else ( ) target_link_libraries( ${demoname} LAGraphX_static LAGraph_static lagraphtest_static lagraphxtest_static GraphBLAS::GraphBLAS ) endif ( ) if ( NOT NO_LIBM ) target_link_libraries ( ${demoname} m ) endif ( ) endforeach( demosourcefile ${DEMO_SOURCES} ) ``` -------------------------------- ### Enable Testing and Add Subdirectories Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt Includes CTest for testing and adds source, experimental, and optionally rtdocs subdirectories. ```cmake set ( MEMORYCHECK_COMMAND_OPTIONS "--show-reachable=no" ) include ( CTest ) add_subdirectory ( src ) add_subdirectory ( experimental ) if ( DEFINED ENV{READTHEDOCS} ) add_subdirectory ( rtdocs ) endif ( ) ``` -------------------------------- ### Add Subdirectories for Testing and Benchmarking Source: https://github.com/graphblas/lagraph/blob/stable/experimental/CMakeLists.txt Includes the 'test' and 'benchmark' subdirectories if testing is enabled. ```cmake if ( BUILD_TESTING ) add_subdirectory ( test ) add_subdirectory ( benchmark ) endif ( ) ``` -------------------------------- ### Configure Static Test Library Source: https://github.com/graphblas/lagraph/blob/stable/src/test/CMakeLists.txt Builds a static library for the test suite if BUILD_STATIC_LIBS is enabled. Sets versioning, output name, and C standard, then links necessary libraries. ```cmake if ( BUILD_STATIC_LIBS ) add_library ( lagraphtest_static STATIC ${LAGRAPHTEST_LIB_SOURCES} ) set_target_properties ( lagraphtest_static PROPERTIES VERSION ${LAGraph_VERSION_MAJOR}.${LAGraph_VERSION_MINOR}.${LAGraph_VERSION_SUB} OUTPUT_NAME lagraphtest POSITION_INDEPENDENT_CODE OFF SOVERSION ${LAGraph_VERSION_MAJOR} C_STANDARD_REQUIRED ON C_STANDARD 11 ) if ( MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") ) set_target_properties ( lagraphtest_static PROPERTIES OUTPUT_NAME lagraphtest_static ) endif ( ) target_link_libraries ( lagraphtest_static PRIVATE LAGraph_static GraphBLAS::GraphBLAS ) endif ( ) ``` -------------------------------- ### Build Individual Test Executables Source: https://github.com/graphblas/lagraph/blob/stable/experimental/test/CMakeLists.txt Finds all C source files ending in '_test.c' or 'test*.c', adds them as executables, sets C standard, and links them to the appropriate LAGraph and GraphBLAS libraries (shared or static). Also adds a test case for each executable. ```cmake file( GLOB TEST_SOURCES LIST_DIRECTORIES false "*_test.c" "test*.c" ) foreach( testsourcefile ${TEST_SOURCES} ) get_filename_component(justname ${testsourcefile} NAME) string( REPLACE ".c" "" testname ${justname} ) # message("Adding: ${testname}") add_executable( ${testname} ${testsourcefile} ) set_target_properties ( ${testname} PROPERTIES C_STANDARD_REQUIRED ON C_STANDARD 11 ) if ( BUILD_SHARED_LIBS ) target_link_libraries( ${testname} LAGraphX LAGraph lagraphxtest lagraphtest GraphBLAS::GraphBLAS ) else ( ) target_link_libraries( ${testname} LAGraphX_static LAGraph_static lagraphxtest_static lagraphtest_static GraphBLAS::GraphBLAS ) endif ( ) if ( NOT NO_LIBM ) # add libm target_link_libraries ( ${testname} m ) endif ( ) string( REPLACE "test_" "LAGraphX_" ctestname ${testname}) add_test( NAME ${ctestname} COMMAND $ ) endforeach() ``` -------------------------------- ### Convert Matrix Market Files to Binary .grb Source: https://github.com/graphblas/lagraph/blob/stable/src/benchmark/README.md Execute this script to convert Matrix Market (.mtx) files to binary (.grb) format. This is recommended for faster loading times with SuiteSparse:GraphBLAS when running benchmarks multiple times. The script can take an optional argument for the GAP directory if it's not in the default relative path. ```bash ./do_gap_binary ``` ```bash ./do_gap_binary /my/big/filestuff/GAP ``` -------------------------------- ### Build LAGraph Documentation with Conda Source: https://github.com/graphblas/lagraph/blob/stable/rtdocs/README.md Activates the conda environment and runs the documentation build script. This command should be executed from the LAGraph/rtdocs directory. ```bash cd LAGraph/rtdocs conda activate lagraph ./make_docs.sh ``` -------------------------------- ### Create Symbolic Link Source: https://github.com/graphblas/lagraph/blob/stable/src/benchmark/README.md Use this command to create a symbolic link to your GAP matrix directory. This is useful if your GAP folder is not located alongside LAGraph and GraphBLAS. ```bash ln -s /my/big/filestuff/GAP ``` -------------------------------- ### Add Individual Test Executables Source: https://github.com/graphblas/lagraph/blob/stable/src/test/CMakeLists.txt Finds all C source files named 'test_*.c', adds them as separate executables, sets C standard, and links the appropriate test libraries based on build type. ```cmake file( GLOB TEST_SOURCES LIST_DIRECTORIES false test_*.c ) foreach( testsourcefile ${TEST_SOURCES} ) get_filename_component(justname ${testsourcefile} NAME) string( REPLACE ".c" "" testname ${justname} ) # message("Adding: ${testname}") add_executable( ${testname} ${testsourcefile}) set_target_properties ( ${testname} PROPERTIES C_STANDARD_REQUIRED ON C_STANDARD 11 ) if ( BUILD_SHARED_LIBS ) target_link_libraries( ${testname} LAGraph LAGraphX lagraphtest GraphBLAS::GraphBLAS ) else ( ) target_link_libraries( ${testname} LAGraph_static LAGraphX_static lagraphtest_static GraphBLAS::GraphBLAS ) endif ( ) string( REPLACE "test_" "LAGraph_" ctestname ${testname}) add_test( NAME ${ctestname} COMMAND $ ) endforeach() ``` -------------------------------- ### Build Static LAGraphXTest Library Source: https://github.com/graphblas/lagraph/blob/stable/experimental/test/CMakeLists.txt Configures the static library for the LAGraphX test suite. It sets version information, C standard, and output name. Links against static versions of LAGraph, lagraphtest, and GraphBLAS. ```cmake if ( BUILD_STATIC_LIBS ) add_library ( lagraphxtest_static STATIC ${LAGRAPHXTEST_LIB_SOURCES} ) set_target_properties ( lagraphxtest_static PROPERTIES VERSION ${LAGraph_VERSION_MAJOR}.${LAGraph_VERSION_MINOR}.${LAGraph_VERSION_SUB} OUTPUT_NAME lagraphxtest POSITION_INDEPENDENT_CODE OFF SOVERSION ${LAGraph_VERSION_MAJOR} C_STANDARD_REQUIRED ON C_STANDARD 11 ) if ( MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") ) set_target_properties ( lagraphxtest_static PROPERTIES OUTPUT_NAME lagraphxtest_static ) endif ( ) target_link_libraries ( lagraphxtest_static PRIVATE LAGraph_static lagraphtest_static GraphBLAS::GraphBLAS ) endif ( ) ``` -------------------------------- ### Report Build Status Information Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt This section prints various build configuration details to the console during the CMake configuration process, aiding in debugging and verification. ```cmake message ( STATUS "CMAKE build type: " ${CMAKE_BUILD_TYPE} ) message ( STATUS "CMAKE source directory: " ${PROJECT_SOURCE_DIR} ) message ( STATUS "CMAKE build directory: " ${PROJECT_BINARY_DIR} ) if ( ${CMAKE_BUILD_TYPE} STREQUAL "Debug") message ( STATUS "CMAKE C Flags debug: " ${CMAKE_C_FLAGS_DEBUG} ) else ( ) message ( STATUS "CMAKE C Flags release: " ${CMAKE_C_FLAGS_RELEASE} ) endif ( ) message ( STATUS "CMAKE compiler ID: " ${CMAKE_C_COMPILER_ID} ) message ( STATUS "CMAKE thread library: " ${CMAKE_THREAD_LIBS_INIT} ) message ( STATUS "CMAKE have pthreads: " ${CMAKE_USE_PTHREADS_INIT} ) message ( STATUS "CMAKE have Win32 pthreads: " ${CMAKE_USE_WIN32_THREADS_INIT} ) message ( STATUS "CMAKE have OpenMP: " ${OPENMP_C_FOUND} ) ``` -------------------------------- ### Configure Shared Test Library Source: https://github.com/graphblas/lagraph/blob/stable/src/test/CMakeLists.txt Builds a shared library for the test suite if BUILD_SHARED_LIBS is enabled. Sets versioning, C standard, and output directory, then links necessary libraries. ```cmake if ( BUILD_SHARED_LIBS ) add_library ( lagraphtest SHARED ${LAGRAPHTEST_LIB_SOURCES} ) set_target_properties ( lagraphtest PROPERTIES VERSION ${LAGraph_VERSION_MAJOR}.${LAGraph_VERSION_MINOR}.${LAGraph_VERSION_SUB} SOVERSION ${LAGraph_VERSION_MAJOR} C_STANDARD_REQUIRED ON C_STANDARD 11 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/dlls ) target_link_libraries ( lagraphtest PRIVATE LAGraph GraphBLAS::GraphBLAS ) target_compile_definitions ( lagraphtest PRIVATE LG_TEST_LIBRARY ) target_compile_definitions ( lagraphtest PUBLIC LG_TEST_DLL ) endif ( ) ``` -------------------------------- ### Iterating JSON DOM with Helper Functions Source: https://github.com/graphblas/lagraph/blob/stable/deps/json_h/README.md Uses helper functions like json_value_as_object and json_value_is_true for more convenient DOM traversal. Remember to free the allocated memory. ```c const char json[] = "{\"a\" : true, \"b\" : [false, null, \"foo\"]}"; struct json_value_s* root = json_parse(json, strlen(json)); struct json_object_s* object = json_value_as_object(root); assert(object != NULL); assert(object->length == 2); struct json_object_element_s* a = object->start; struct json_string_s* a_name = a->name; assert(0 == strcmp(a_name->string, "a")); assert(a_name->string_size == strlen("a")); struct json_value_s* a_value = a->value; assert(json_value_is_true(a_value)); struct json_object_element_s* b = a->next; assert(b->next == NULL); struct json_string_s* b_name = b->name; assert(0 == strcmp(b_name->string, "b")); assert(b_name->string_size == strlen("b")); struct json_array_s* array = json_value_as_array(b->value); assert(array->length == 3); struct json_array_element_s* b_1st = array->start; struct json_value_s* b_1st_value = b_1st->value; assert(json_value_is_false(b_1st_value)); struct json_array_element_s* b_2nd = b_1st->next; struct json_value_s* b_2nd_value = b_2nd->value; assert(json_value_is_null(b_2nd_value)); struct json_array_element_s* b_3rd = b_2nd->next; assert(b_3rd->next == NULL); struct json_string_s* string = json_value_as_string(b_3rd->value); assert(string != NULL); assert(0 == strcmp(string->string, "foo")); assert(string->string_size == strlen("foo")); /* Don't forget to free the one allocation! */ free(root); ``` -------------------------------- ### Compile and Test LAGraph on Linux/Mac Source: https://github.com/graphblas/lagraph/blob/stable/rtdocs/installation.md Navigate to the LAGraph directory and use make to compile and test the library. This is the primary build command for Linux and Mac systems. ```bash cd LAGraph make make test ``` -------------------------------- ### Set Environment for Static Libraries on Windows Source: https://github.com/graphblas/lagraph/blob/stable/experimental/test/CMakeLists.txt Configures the test environment on Windows to prepend the directory of the GraphBLAS shared library to the PATH. This is used when BUILD_SHARED_LIBS is disabled (implying static libraries). ```cmake set_tests_properties ( ${ctestname} PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$>" ``` -------------------------------- ### Glob Sources for LAGraphX Library Source: https://github.com/graphblas/lagraph/blob/stable/experimental/CMakeLists.txt Finds C source files for the LAGraphX library from utility and algorithm directories. ```cmake file ( GLOB LAGRAPHX_LIB_SOURCES "utility/*.c" "algorithm/*.c" ) ``` -------------------------------- ### Include Directories for LAGraphX Source: https://github.com/graphblas/lagraph/blob/stable/experimental/CMakeLists.txt Specifies include directories for the LAGraphX library, including utility and JSON dependencies. ```cmake include_directories ( ${PROJECT_SOURCE_DIR}/src/utility ${PROJECT_SOURCE_DIR}/deps/json_h ) ``` -------------------------------- ### Build Shared LAGraphXTest Library Source: https://github.com/graphblas/lagraph/blob/stable/experimental/test/CMakeLists.txt Configures the shared library for the LAGraphX test suite. It sets version information, C standard, and output directory. Links against LAGraph, lagraphtest, and GraphBLAS. Defines LGX_TEST_LIBRARY and LGX_TEST_DLL. ```cmake if ( BUILD_SHARED_LIBS ) add_library ( lagraphxtest SHARED ${LAGRAPHXTEST_LIB_SOURCES} ) set_target_properties ( lagraphxtest PROPERTIES VERSION ${LAGraph_VERSION_MAJOR}.${LAGraph_VERSION_MINOR}.${LAGraph_VERSION_SUB} SOVERSION ${LAGraph_VERSION_MAJOR} C_STANDARD_REQUIRED ON C_STANDARD 11 RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/dlls ) target_link_libraries ( lagraphxtest PRIVATE LAGraph lagraphtest GraphBLAS::GraphBLAS ) target_compile_definitions ( lagraphxtest PRIVATE LGX_TEST_LIBRARY ) target_compile_definitions ( lagraphxtest PUBLIC LGX_TEST_DLL ) endif ( ) ``` -------------------------------- ### Configure Package Config File (Build Tree) Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt Generates the LAGraphConfig.cmake file for use within the build tree. This ensures the package configuration is available during the build process. ```cmake set ( SUITESPARSE_IN_BUILD_TREE ON ) configure_package_config_file ( Config/LAGraphConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/LAGraphConfig.cmake INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/LAGraphConfig.cmake ) ``` -------------------------------- ### Set Environment for Shared Libraries on Windows Source: https://github.com/graphblas/lagraph/blob/stable/experimental/test/CMakeLists.txt Configures the test environment on Windows to prepend the directory of the GraphBLAS shared library and the lagrahxtest shared library to the PATH. This is used when BUILD_SHARED_LIBS is enabled. ```cmake set_tests_properties ( ${ctestname} PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$>;PATH=path_list_prepend:$" ) ``` -------------------------------- ### Run Test Coverage Source: https://github.com/graphblas/lagraph/blob/stable/README.md Command to compile LAGraph with test coverage enabled. After running, open the coverage report in a browser. Remember to clean up afterwards. ```bash make cov ``` -------------------------------- ### Print Final C Flags Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt Outputs the final configured C compiler flags to the build log. ```cmake message ( STATUS "CMAKE C flags: " ${CMAKE_C_FLAGS} ) ``` -------------------------------- ### Configure Static LAGraph Library Source: https://github.com/graphblas/lagraph/blob/stable/src/CMakeLists.txt Defines properties for building a static LAGraph library. This configuration sets output names, position-independent code, C standard compliance, and links against GraphBLAS and the math library. ```cmake if ( BUILD_STATIC_LIBS ) add_library ( LAGraph_static STATIC ${LAGRAPH_LIB_SOURCES} ) SET_TARGET_PROPERTIES ( LAGraph_static PROPERTIES OUTPUT_NAME lagraph POSITION_INDEPENDENT_CODE OFF C_STANDARD_REQUIRED ON C_STANDARD 11 PUBLIC_HEADER "include/LAGraph.h" ) if ( MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") ) set_target_properties ( LAGraph_static PROPERTIES OUTPUT_NAME lagraph_static ) endif ( ) if ( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25" ) set_target_properties ( LAGraph_static PROPERTIES EXPORT_NO_SYSTEM ON ) endif ( ) if ( TARGET GraphBLAS::GraphBLAS_static ) target_link_libraries ( LAGraph_static PUBLIC GraphBLAS::GraphBLAS_static ) else ( ) target_link_libraries ( LAGraph_static PUBLIC GraphBLAS::GraphBLAS ) endif ( ) if ( NOT NO_LIBM ) target_link_libraries ( LAGraph_static PUBLIC "m" ) endif ( ) target_include_directories ( LAGraph_static PUBLIC $ $ ) endif ( ) ``` -------------------------------- ### Clean Build Artifacts Source: https://github.com/graphblas/lagraph/blob/stable/README.md Command to remove generated files and clean the build directory for LAGraph. ```bash make clean ``` -------------------------------- ### Add Static LAGraphX Library Source: https://github.com/graphblas/lagraph/blob/stable/experimental/CMakeLists.txt Defines the static LAGraphX library with output name, position independence, C standard, and public header. ```cmake add_library ( LAGraphX_static STATIC ${LAGRAPHX_LIB_SOURCES} ) set_target_properties ( LAGraphX_static PROPERTIES OUTPUT_NAME lagraphx POSITION_INDEPENDENT_CODE OFF C_STANDARD_REQUIRED ON C_STANDARD 11 PUBLIC_HEADER "include/LAGraphX.h" ) if ( MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") ) set_target_properties ( LAGraphX_static PROPERTIES OUTPUT_NAME lagraphx_static ) endif ( ) if ( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25" ) set_target_properties ( LAGraphX_static PROPERTIES EXPORT_NO_SYSTEM ON ) endif ( ) if ( TARGET GraphBLAS::GraphBLAS_static ) target_link_libraries ( LAGraphX_static PRIVATE GraphBLAS::GraphBLAS_static ) else ( ) target_link_libraries ( LAGraphX_static PRIVATE GraphBLAS::GraphBLAS ) endif ( ) target_include_directories ( LAGraphX_static PUBLIC $ $ ) ``` -------------------------------- ### Set C Flags for Vanilla Build Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt Enables the LAGRAPH_VANILLA build by setting the corresponding C flag. Prints build type status. ```cmake if ( LAGRAPH_VANILLA ) set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLAGRAPH_VANILLA=1 " ) message ( STATUS "Vanilla build: not relying on any GxB extensions" ) else ( ) message ( STATUS "GxB build: relying on SuiteSparse GxB extensions" ) endif ( ) ``` -------------------------------- ### Write Package Version File Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt Generates the LAGraphConfigVersion.cmake file, which specifies the version compatibility for the package configuration. This is essential for `find_package` to correctly identify the library version. ```cmake write_basic_package_version_file ( ${CMAKE_CURRENT_BINARY_DIR}/LAGraphConfigVersion.cmake COMPATIBILITY SameMajorVersion ) ``` -------------------------------- ### Define LAGraph Source Directory Macro Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt This sets a C preprocessor macro LGDIR to the project's source directory. This is used by LAGraph to locate its own data files. ```cmake set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLGDIR=${PROJECT_SOURCE_DIR}" ) ``` -------------------------------- ### Link libm for LAGraphX Libraries Source: https://github.com/graphblas/lagraph/blob/stable/experimental/CMakeLists.txt Links the math library (libm) to LAGraphX shared and static libraries if not explicitly disabled. ```cmake if ( NOT NO_LIBM ) if ( BUILD_SHARED_LIBS ) target_link_libraries ( LAGraphX PRIVATE m ) endif ( ) if ( BUILD_STATIC_LIBS ) target_link_libraries ( LAGraphX_static PUBLIC m ) endif ( ) endif ( ) ``` -------------------------------- ### Add Shared LAGraphX Library Source: https://github.com/graphblas/lagraph/blob/stable/experimental/CMakeLists.txt Defines the shared LAGraphX library with versioning, output name, C standard, and public header. ```cmake add_library ( LAGraphX SHARED ${LAGRAPHX_LIB_SOURCES} ) set_target_properties ( LAGraphX PROPERTIES VERSION ${LAGraph_VERSION_MAJOR}.${LAGraph_VERSION_MINOR}.${LAGraph_VERSION_SUB} SOVERSION ${LAGraph_VERSION_MAJOR} OUTPUT_NAME lagraphx C_STANDARD_REQUIRED ON C_STANDARD 11 PUBLIC_HEADER "include/LAGraphX.h" RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/dlls ) if ( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25" ) set_target_properties ( LAGraphX PROPERTIES EXPORT_NO_SYSTEM ON ) endif ( ) target_link_libraries ( LAGraphX PRIVATE LAGraph GraphBLAS::GraphBLAS ) target_include_directories ( LAGraphX PUBLIC $ $ ) target_compile_definitions ( LAGraphX PRIVATE LGX_LIBRARY ) target_compile_definitions ( LAGraphX PUBLIC LGX_DLL ) ``` -------------------------------- ### Configure OpenMP Threading Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt This section configures the use of OpenMP for threading. It checks for OpenMP availability and integrates it with static library builds and the Threads package. ```cmake option ( LAGRAPH_USE_OPENMP "ON: Use OpenMP in LAGraph if available. OFF: Do not use OpenMP. (Default: SUITESPARSE_USE_OPENMP)" ${SUITESPARSE_USE_OPENMP} ) if ( COVERAGE ) set ( LAGRAPH_USE_OPENMP "OFF" CACHE STRING "" FORCE ) # OK: test coverage is enabled message ( STATUS "OpenMP disabled for test coverage" ) else ( ) if ( LAGRAPH_USE_OPENMP ) if ( CMAKE_VERSION VERSION_LESS 3.24 ) find_package ( OpenMP COMPONENTS C ) else ( ) find_package ( OpenMP COMPONENTS C GLOBAL ) endif ( ) if ( OpenMP_C_FOUND AND BUILD_STATIC_LIBS ) list ( APPEND LAGRAPH_STATIC_LIBS ${OpenMP_C_LIBRARIES} ) endif ( ) find_package ( Threads ) else ( ) set ( OpenMP_C_FOUND OFF ) endif ( ) endif ( ) ``` -------------------------------- ### Configure Shared LAGraph Library Source: https://github.com/graphblas/lagraph/blob/stable/src/CMakeLists.txt Defines properties for building a shared LAGraph library. This includes versioning, output naming, C standard compliance, and linking against GraphBLAS and the math library. ```cmake if ( BUILD_SHARED_LIBS ) add_library ( LAGraph SHARED ${LAGRAPH_LIB_SOURCES} ) set_target_properties ( LAGraph PROPERTIES VERSION ${LAGraph_VERSION_MAJOR}.${LAGraph_VERSION_MINOR}.${LAGraph_VERSION_SUB} SOVERSION ${LAGraph_VERSION_MAJOR} OUTPUT_NAME lagraph C_STANDARD_REQUIRED ON C_STANDARD 11 PUBLIC_HEADER "include/LAGraph.h" RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/dlls ) if ( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25" ) set_target_properties ( LAGraph PROPERTIES EXPORT_NO_SYSTEM ON ) endif ( ) target_link_libraries ( LAGraph PRIVATE GraphBLAS::GraphBLAS ) if ( NOT NO_LIBM ) target_link_libraries ( LAGraph PRIVATE "m" ) endif ( ) target_include_directories ( LAGraph PUBLIC $ $ ) target_compile_definitions ( LAGraph PRIVATE LG_LIBRARY ) target_compile_definitions ( LAGraph PUBLIC LG_DLL ) endif ( ) ``` -------------------------------- ### Link OpenMP for LAGraphX Libraries Source: https://github.com/graphblas/lagraph/blob/stable/experimental/CMakeLists.txt Links the OpenMP library to LAGraphX shared and static libraries if OpenMP is enabled. ```cmake if ( LAGRAPH_HAS_OPENMP ) if ( BUILD_SHARED_LIBS ) target_link_libraries ( LAGraphX PRIVATE OpenMP::OpenMP_C ) endif ( ) if ( BUILD_STATIC_LIBS ) target_link_libraries ( LAGraphX_static PRIVATE OpenMP::OpenMP_C ) endif ( ) endif ( ) ``` -------------------------------- ### Add OpenMP Support Source: https://github.com/graphblas/lagraph/blob/stable/experimental/test/CMakeLists.txt Conditionally links the OpenMP library to the LAGraphX test libraries (shared or static) if OpenMP is enabled. ```cmake if ( LAGRAPH_HAS_OPENMP ) if ( BUILD_SHARED_LIBS ) target_link_libraries ( lagraphxtest PRIVATE OpenMP::OpenMP_C ) endif ( ) if ( BUILD_STATIC_LIBS ) target_link_libraries ( lagraphxtest_static PRIVATE OpenMP::OpenMP_C ) endif ( ) endif ( ) ``` -------------------------------- ### Include Directories for LAGraph Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt This command adds several directories to the include path for the LAGraph library, allowing it to find its header files during compilation. ```cmake include_directories ( ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src/utility ${PROJECT_SOURCE_DIR}/src/algorithm ${PROJECT_SOURCE_DIR}/test/include ) ``` -------------------------------- ### Set C Flags for Clang Source: https://github.com/graphblas/lagraph/blob/stable/CMakeLists.txt Sets optimization level to O3 for Clang compiler. Ensure Clang version is at least 3.3. ```cmake set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 " ) #if ( CMAKE_C_COMPILER_VERSION VERSION_LESS 3.3 ) # message ( FATAL_ERROR "clang version must be at least 3.3" ) #endif ( ) ``` -------------------------------- ### Extended JSON Parsing Source: https://github.com/graphblas/lagraph/blob/stable/deps/json_h/README.md Use `json_parse_ex` for more control over JSON parsing, including custom allocation and error handling. It accepts flags, an allocation function, user data, and a result structure. ```c struct json_value_s *json_parse_ex( const void *src, size_t src_size, size_t flags_bitset, void*(*alloc_func_ptr)(void *, size_t), void *user_data, struct json_parse_result_s *result); ``` -------------------------------- ### Parsing JSON String with json_parse Source: https://github.com/graphblas/lagraph/blob/stable/deps/json_h/README.md Demonstrates parsing a JSON string into a DOM structure and accessing its elements directly. Ensure to free the allocated memory after use. ```c const char json[] = "{\"a\" : true, \"b\" : [false, null, \"foo\"]}"; struct json_value_s* root = json_parse(json, strlen(json)); assert(root->type == json_type_object); struct json_object_s* object = (struct json_object_s*)root->payload; assert(object->length == 2); struct json_object_element_s* a = object->start; struct json_string_s* a_name = a->name; assert(0 == strcmp(a_name->string, "a")); assert(a_name->string_size == strlen("a")); struct json_value_s* a_value = a->value; assert(a_value->type == json_type_true); assert(a_value->payload == NULL); struct json_object_element_s* b = a->next; assert(b->next == NULL); struct json_string_s* b_name = b->name; assert(0 == strcmp(b_name->string, "b")); assert(b_name->string_size == strlen("b")); struct json_value_s* b_value = b->value; assert(b_value->type == json_type_array); struct json_array_s* array = (struct json_array_s*)b_value->payload; assert(array->length == 3); struct json_array_element_s* b_1st = array->start; struct json_value_s* b_1st_value = b_1st->value; assert(b_1st_value->type == json_type_false); assert(b_1st_value->payload == NULL); struct json_array_element_s* b_2nd = b_1st->next; struct json_value_s* b_2nd_value = b_2nd->value; assert(b_2nd_value->type == json_type_null); assert(b_2nd_value->payload == NULL); struct json_array_element_s* b_3rd = b_2nd->next; assert(b_3rd->next == NULL); struct json_value_s* b_3rd_value = b_3rd->value; assert(b_3rd_value->type == json_type_string); struct json_string_s* string = (struct json_string_s*)b_3rd_value->payload; assert(0 == strcmp(string->string, "foo")); assert(string->string_size == strlen("foo")); /* Don't forget to free the one allocation! */ free(root); ``` -------------------------------- ### json_parse_ex Source: https://github.com/graphblas/lagraph/blob/stable/deps/json_h/README.md Provides extended functionality for parsing JSON strings into a DOM, allowing for custom flags and memory allocation. ```APIDOC ## json_parse_ex ### Description Provides extended functionality for parsing JSON strings into a DOM, allowing for custom flags and memory allocation. This function enables finer control over the parsing process. ### Function Signature ```c struct json_value_s *json_parse_ex( const void *src, size_t src_size, size_t flags_bitset, void*(*alloc_func_ptr)(void *, size_t), void *user_data, struct json_parse_result_s *result); ``` ### Parameters #### Path Parameters * `src` (const void*) - A UTF-8 JSON string to parse. * `src_size` (size_t) - The size of `src` in bytes. * `flags_bitset` (size_t) - Extra parsing flags, a bitset of flags specified in `enum json_parse_flags_e`. * `alloc_func_ptr` (void*(*)(void *, size_t)) - A callback function to use for doing the single allocation. If NULL, `malloc()` is used. * `user_data` (void*) - User data to be passed as the first argument to `alloc_func_ptr`. * `result` (struct json_parse_result_s*) - The result of the parsing. If a parsing error occurred, this will contain the error type and its location in the source. Can be NULL. ### Returns Returns a `struct json_value_s*` pointing to the root of the JSON DOM. Returns NULL on error. ### Remarks This function offers more control over memory allocation and parsing behavior compared to `json_parse`. ```