From b02ef0b3be0da6c494eddc0a189dac60e95d03a4 Mon Sep 17 00:00:00 2001 From: Tim Davis Date: Thu, 30 Nov 2023 07:20:25 -0600 Subject: [PATCH] CXSparse: date. Example: add LAGraph. LAGraph: *.h for C++ --- CXSparse/Config/cs.h.in | 4 +- CXSparse/Include/cs.h | 4 +- Example/CMakeLists.txt | 56 ++++++++++- Example/Demo/mydemo.out | 183 ---------------------------------- Example/Include/my.h | 6 +- Example/Include/my_internal.h | 4 + Example/README.md | 35 +++---- Example/Source/my.c | 20 +++- Example/Source/my_cxx.cc | 25 ++++- LAGraph/config/LAGraph.h.in | 13 +++ LAGraph/include/LAGraph.h | 13 +++ LAGraph/include/LAGraphX.h | 13 +++ 12 files changed, 161 insertions(+), 215 deletions(-) delete mode 100644 Example/Demo/mydemo.out diff --git a/CXSparse/Config/cs.h.in b/CXSparse/Config/cs.h.in index 6280e74673..db21c6a05a 100644 --- a/CXSparse/Config/cs.h.in +++ b/CXSparse/Config/cs.h.in @@ -2,7 +2,7 @@ // CXSparse/Include/cs.h: include file for CXSparse //------------------------------------------------------------------------------ -// CXSparse, Copyright (c) 2006-2022, Timothy A. Davis, All Rights Reserved +// CXSparse, Copyright (c) 2006-2023, Timothy A. Davis, All Rights Reserved // SPDX-License-Identifier: LGPL-2.1+ //------------------------------------------------------------------------------ @@ -39,7 +39,7 @@ #define CS_SUBVER @CXSPARSE_VERSION_MINOR@ #define CS_SUBSUB @CXSPARSE_VERSION_SUB@ #define CS_DATE "@CXSPARSE_DATE@" /* CXSparse release date */ -#define CS_COPYRIGHT "Copyright (c) Timothy A. Davis, 2006-2022" +#define CS_COPYRIGHT "Copyright (c) Timothy A. Davis, 2006-2023" #define CXSPARSE #include "SuiteSparse_config.h" diff --git a/CXSparse/Include/cs.h b/CXSparse/Include/cs.h index fe5061350c..1919a5a170 100644 --- a/CXSparse/Include/cs.h +++ b/CXSparse/Include/cs.h @@ -2,7 +2,7 @@ // CXSparse/Include/cs.h: include file for CXSparse //------------------------------------------------------------------------------ -// CXSparse, Copyright (c) 2006-2022, Timothy A. Davis, All Rights Reserved +// CXSparse, Copyright (c) 2006-2023, Timothy A. Davis, All Rights Reserved // SPDX-License-Identifier: LGPL-2.1+ //------------------------------------------------------------------------------ @@ -39,7 +39,7 @@ #define CS_SUBVER 3 #define CS_SUBSUB 0 #define CS_DATE "Dec 30, 2023" /* CXSparse release date */ -#define CS_COPYRIGHT "Copyright (c) Timothy A. Davis, 2006-2022" +#define CS_COPYRIGHT "Copyright (c) Timothy A. Davis, 2006-2023" #define CXSPARSE #include "SuiteSparse_config.h" diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt index 35ad1d2933..2bb1cc1723 100644 --- a/Example/CMakeLists.txt +++ b/Example/CMakeLists.txt @@ -5,16 +5,53 @@ # Copyright (c) 2022-2023, Timothy A. Davis, All Rights Reserved. # SPDX-License-Identifier: BSD-3-clause +# See the section below, "help with building this Example ..." for how to tell +# this Example library where to find SuiteSparse. + +cmake_minimum_required ( VERSION 3.20 ) + +#------------------------------------------------------------------------------- +# help with building this Example package and finding SuiteSparse +#------------------------------------------------------------------------------- + # To build this example, add the location of the CMake config files to -# CMAKE_PREFIX_PATH if the SuiteSparse libraries aren't installed at a -# default location. +# CMAKE_PREFIX_PATH if the SuiteSparse libraries aren't installed at a default +# location. For example, on Linux or Mac, if you have your own a compiled copy +# of SuiteSparse in /home/me/SuiteSparse that was compiled and installed with +# LOCAL_INSTALL set to ON, use the following: +# +# export CMAKE_PREFIX_PATH /home/me/SuiteSparse +# +# or uncomment and revise one of these examples, on any platform: +# +# set ( CMAKE_PREFIX_PATH /home/me/SuiteSparse ) +# set ( CMAKE_PREFIX_PATH /opt/SuiteSparse ) +# +# The following is added, just to simplify building this Example if it is +# located inside SuiteSparse itself and compiled with LOCAL_INSTALL set to ON. +# Normally you would not use this in a stand-alone library that relies on +# SuiteSparse: + + set ( CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_SOURCE_DIR}/.. ) + +# Next, to build and install this Example library, do the following: +# +# cd Example/build +# cmake .. +# cmake --build . --config Release +# sudo cmake --install . +# +# Alternatively, if you have "make", just do this in this directory: +# +# make +# sudo make install + +message ( STATUS "MY prefix path: ${CMAKE_PREFIX_PATH}" ) #------------------------------------------------------------------------------- # get the version #------------------------------------------------------------------------------- -cmake_minimum_required ( VERSION 3.20 ) - # cmake inserts the date and version number into Include/my.h: set ( MY_DATE "Dec 30, 2023" ) set ( MY_VERSION_MAJOR 1 ) @@ -596,3 +633,14 @@ if ( BUILD_STATIC_LIBS ) add_executable ( my_cxx_demo_static "Demo/my_demo.c" ) target_link_libraries ( my_cxx_demo_static PUBLIC my_cxx_static ) endif ( ) + +#------------------------------------------------------------------------------- +# report +#------------------------------------------------------------------------------- + +message ( STATUS "MY source: ${CMAKE_SOURCE_DIR} ") +message ( STATUS "MY build: ${CMAKE_BINARY_DIR} ") +message ( STATUS "MY install prefix: ${CMAKE_INSTALL_PREFIX}" ) +message ( STATUS "MY install rpath: ${CMAKE_INSTALL_RPATH}" ) +message ( STATUS "MY build rpath: ${CMAKE_BUILD_RPATH}" ) + diff --git a/Example/Demo/mydemo.out b/Example/Demo/mydemo.out deleted file mode 100644 index ac55d6f2e8..0000000000 --- a/Example/Demo/mydemo.out +++ /dev/null @@ -1,183 +0,0 @@ -My demo -Date from #include 'my.h': Sept 18, 2023 -Date from compiled library: Sept 18, 2023 -version from #include 'my.h.': 1.4.1 -version from compiled library: 1.4.1 -SuiteSparse: v7.2.1 (Sept 18, 2023) -SuiteSparse: v7.2.1 (in library) -CXSparse: v4.2.1 (Sept 18, 2023) -CXSparse Version 4.2.1, Sept 18, 2023. Copyright (c) Timothy A. Davis, 2006-2022 -2-by-2, nzmax: 4 nnz: 4, 1-norm: 34 - col 0 : locations 0 to 1 - 0 : 11 - 1 : 21 - col 1 : locations 2 to 3 - 0 : 12 - 1 : 22 -AMD: v3.2.1 (Sept 18, 2023) -P [0] = 0 -P [1] = 1 -BTF: v2.2.1 (Sept 18, 2023) -P [0] = 0 -P [1] = 1 -Q [0] = 0 -Q [1] = 1 -nblocks 1 -CAMD: v3.2.1 (Sept 18, 2023) -P [0] = 0 -P [1] = 1 -CCOLAMD: v3.2.1 (Sept 18, 2023) -P [0] = 0 -P [1] = 1 -COLAMD: v3.2.1 (Sept 18, 2023) -P [0] = 0 -P [1] = 1 -CHOLMOD: v4.2.1 (Sept 18, 2023) -CHOLMOD: v4.2.1 (in library) -GraphBLAS: v8.2.1 (Sept 18, 2023) -GraphBLAS: v8.2.1 (in library) -KLU: v2.2.1 (Sept 18, 2023) -x [0] = 36.4 -x [1] = -32.7 -error: 7.10543e-14 -LDL: v3.2.1 (Sept 18, 2023) -x2 [0] = 36.4 -x2 [1] = -32.7 -error: 0 -RBio: v4.2.1 (Sept 18, 2023) -njumbled 0, nzeros 0 -result 0 -mtype: iua -2-by-2 matrix |simple - 3 1 1 1 -iua 2 2 4 0 -(40I2) (40I2) (26I3) - 1 3 5 - 1 2 1 2 - 11 21 12 22 -SPEX: v2.2.1 (Sept 18, 2023) -SPQR: v4.2.1 (Sept 18, 2023) - -CHOLMOD dense: X from QR: 2-by-1, - leading dimension 2, nzmax 2, real, double - col 0: - 0: 36.4 - 1: -32.7 - OK - -UMFPACK: v6.2.1 (Sept 18, 2023) -UMFPACK V6.2.1 (Sept 18, 2023) -UMFPACK: Copyright (c) 2005-2023 by Timothy A. Davis. All Rights Reserved. - -UMFPACK License: SPDX-License-Identifier: GPL-2.0+ - UMFPACK is available under alternate licenses, - contact T. Davis for details. -BLAS used: Intel MKL 64lp BLAS (32-bit integers) -BLAS integer size: 4 bytes -x [0] = 36.4 -x [1] = -32.7 -error: 5.68434e-14 - -UMFPACK: Copyright (c) 2005-2023 by Timothy A. Davis. All Rights Reserved. - - -UMFPACK License: SPDX-License-Identifier: GPL-2.0+ - UMFPACK is available under alternate licenses, - contact T. Davis for details. - - -Availability: http://www.suitesparse.com -UMFPACK V6.2.1 (Sept 18, 2023): OK - -UMFPACK V6.2.1 (Sept 18, 2023), Info: - matrix entry defined as: double - Int (generic integer) defined as: int64_t - BLAS library used: Intel MKL 64lp BLAS (32-bit integers). size of BLAS integer: 4 - MATLAB: no. - CPU timer: SuiteSparse_time ( ) routine. - number of rows in matrix A: 2 - number of columns in matrix A: 2 - entries in matrix A: 4 - memory usage reported in: 16-byte Units - size of int32_t: 4 bytes - size of int64_t: 8 bytes - size of pointer: 8 bytes - size of numerical entry: 8 bytes - - strategy used: symmetric - ordering used: amd on A+A' - modify Q during factorization: no - prefer diagonal pivoting: yes - pivots with zero Markowitz cost: 0 - submatrix S after removing zero-cost pivots: - number of "dense" rows: 0 - number of "dense" columns: 0 - number of empty rows: 0 - number of empty columns 0 - submatrix S square and diagonal preserved - pattern of square submatrix S: - number rows and columns 2 - symmetry of nonzero pattern: 1.000000 - nz in S+S' (excl. diagonal): 2 - nz on diagonal of matrix S: 2 - fraction of nz on diagonal: 1.000000 - ordering statistics, for strict diagonal pivoting: - est. flops for LU factorization: 3.00000e+00 - est. nz in L+U (incl. diagonal): 4 - est. largest front (# entries): 4 - est. max nz in any column of L: 2 - number of "dense" rows/columns in S+S': 0 - symbolic factorization defragmentations: 0 - symbolic memory usage (Units): 81 - symbolic memory usage (MBytes): 0.0 - Symbolic size (Units): 40 - Symbolic size (MBytes): 0 - symbolic factorization wallclock time(sec): 0.00 - - matrix scaled: yes (divided each row by sum of abs values in each row) - minimum sum (abs (rows of A)): 2.30000e+01 - maximum sum (abs (rows of A)): 4.30000e+01 - - symbolic/numeric factorization: upper bound actual % - variable-sized part of Numeric object: - initial size (Units) 45 40 89% - peak size (Units) 638 636 100% - final size (Units) 3 5 167% - Numeric final size (Units) 50 51 102% - Numeric final size (MBytes) 0.0 0.0 102% - peak memory usage (Units) 758 756 100% - peak memory usage (MBytes) 0.0 0.0 100% - numeric factorization flops 3.00000e+00 3.00000e+00 100% - nz in L (incl diagonal) 3 3 100% - nz in U (incl diagonal) 3 3 100% - nz in L+U (incl diagonal) 4 4 100% - largest front (# entries) 6 4 67% - largest # rows in front 3 2 67% - largest # columns in front 2 2 100% - - initial allocation ratio used: 1.2 - # of forced updates due to frontal growth: 0 - number of off-diagonal pivots: 0 - nz in L (incl diagonal), if none dropped 3 - nz in U (incl diagonal), if none dropped 3 - number of small entries dropped 0 - nonzeros on diagonal of U: 2 - min abs. value on diagonal of U: 2.11e-02 - max abs. value on diagonal of U: 4.78e-01 - estimate of reciprocal of condition number: 4.42e-02 - indices in compressed pattern: 2 - numerical values stored in Numeric object: 4 - numeric factorization defragmentations: 0 - numeric factorization reallocations: 0 - costly numeric factorization reallocations: 0 - numeric factorization wallclock time (sec): 0.00 - - solve flops: 4.20000e+01 - iterative refinement steps taken: 0 - iterative refinement steps attempted: 0 - sparse backward error omega1: 7.44e-17 - sparse backward error omega2: 0.00e+00 - solve wall clock time (sec): 0.00 - - total symbolic + numeric + solve flops: 4.50000e+01 - diff --git a/Example/Include/my.h b/Example/Include/my.h index 71272afdef..3366eb8806 100644 --- a/Example/Include/my.h +++ b/Example/Include/my.h @@ -11,10 +11,10 @@ // file, since it is constructed from Config/my.h.in by cmake. // version and date for example user library -#define MY_DATE "Nov 30, 2023" +#define MY_DATE "Dec 30, 2023" #define MY_MAJOR_VERSION 1 -#define MY_MINOR_VERSION 4 -#define MY_PATCH_VERSION 4 +#define MY_MINOR_VERSION 5 +#define MY_PATCH_VERSION 0 #ifdef __cplusplus extern "C" { diff --git a/Example/Include/my_internal.h b/Example/Include/my_internal.h index e78d149cb4..54acc778bd 100644 --- a/Example/Include/my_internal.h +++ b/Example/Include/my_internal.h @@ -20,6 +20,10 @@ #if ! defined (NO_GRAPHBLAS) # include "GraphBLAS.h" #endif +#if ! defined (NO_LAGRAPH) +# include "LAGraph.h" +#endif +#include "klu.h" #include "klu.h" #include "ldl.h" #include "RBio.h" diff --git a/Example/README.md b/Example/README.md index f6263e9ad5..db9e20cc5b 100644 --- a/Example/README.md +++ b/Example/README.md @@ -6,30 +6,28 @@ SPDX-License-Identifier: BSD-3-clause An example of how to use the SuiteSparse `Find*.cmake` files in cmake to build a library that depends on SuiteSparse libraries. - README.md this file - CMakeLists.txt primary method for building the package - Makefile optional; relies on cmake to do the work - Include/my.h created by cmake from Config/my.h.in - Config/my.h.in input file for Include/my.h - Demo/my_demo.c demo program that uses 'my' package - Demo/mydemo.out output of my_demo - Source/my.c library source code - build where the 'my' package is built - cmake_modules/FindGMP.cmake how to find the GMP library - cmake_modules/FindMPFR.cmake how to find the MPFR library + README.md this file + License.txt license + CMakeLists.txt primary method for building the package + Makefile optional; relies on cmake to do the work + Include/my.h created by cmake from Config/my.h.in + Include/my_internal.h internal include file + Config/my.h.in input file for Include/my.h + Demo/my_demo.c demo program that uses 'my' package + Demo/my_demo.out output of my_demo + Source/my.c library source code (C) + Source/my_cxx.cc library source code (C++) + build where the 'my' package is built The 'my' library relies on the following SuiteSparse libraries, each of which has a cmake module to use in `find_package` that is installed alongside the compiled libraries (/usr/local/lib/cmake/SuiteSparse) `AMD`, `BTF`, `CAMD`, -`CCOLAMD`, `CHOLMOD`, `CHOLMOD_CUDA`, `COLAMD`, `CXSparse`, `GPUQREngine`, -`GraphBLAS`, `KLU`, `KLU_CHOLMOD`, `LDL`, `Mongoose`, `RBio`, `SPEX`, `SPQR`, +`CCOLAMD`, `CHOLMOD`, `COLAMD`, `CXSparse`, `GPUQREngine`, `GraphBLAS`, `KLU`, +`KLU_CHOLMOD`, `LAGraph`, `LDL`, `Mongoose`, `RBio`, `SPEX`, `SPQR`, `SPQR_CUDA`, `SuiteSparse_GPURuntime`, `SuiteSparse_config`, and `UMFPACK`. In addition, the 'my' package relies on the following external libraries: -`BLAS`, `LAPACK`, `OpenMP`, `GMP`, and `MPFR`. The latter two (GMP and MPFR) -do not have cmake `find_package` modules. These can be found in -`SuiteSparse/Example/cmake_modules`, or in `SuiteSparse/SPEX/cmake_modules`. -They are not installed in /usr/local/lib/cmake/SuiteSparse. +`BLAS`, `LAPACK`, `OpenMP`, `GMP`, and `MPFR`. To compile the `my` package and run a demo program: @@ -46,3 +44,6 @@ To remove all compiled files and folders, delete the contents of Example/build make clean +See the instructions in CMakeLists.txt for additional instructions (in +particular, if SuiteSparse is not found). + diff --git a/Example/Source/my.c b/Example/Source/my.c index c2bcd37148..73a9a9595d 100644 --- a/Example/Source/my.c +++ b/Example/Source/my.c @@ -144,11 +144,11 @@ void my_function (void) cholmod_common cc ; OK (cholmod_l_start (&cc)) ; -#if ! defined (NO_GRAPHBLAS) //-------------------------------------------------------------------------- // GraphBLAS //-------------------------------------------------------------------------- + #if ! defined (NO_GRAPHBLAS) OK (GrB_init (GrB_NONBLOCKING) == GrB_SUCCESS) ; printf ("GraphBLAS: v%d.%d.%d (%s)\n", GxB_IMPLEMENTATION_MAJOR, GxB_IMPLEMENTATION_MINOR, @@ -157,7 +157,23 @@ void my_function (void) printf ("GraphBLAS: v%d.%d.%d (in library)\n", version [0], version [1], version [2]) ; OK (GrB_finalize ( ) == GrB_SUCCESS) ; -#endif + #endif + + //-------------------------------------------------------------------------- + // LAGraph + //-------------------------------------------------------------------------- + + #if ! defined (NO_LAGRAPH) + char msg [LAGRAPH_MSG_LEN], verstring [LAGRAPH_MSG_LEN] ; + printf ("LAGraph: v%d.%d.%d (%s)\n", + LAGRAPH_VERSION_MAJOR, LAGRAPH_VERSION_MINOR, LAGRAPH_VERSION_UPDATE, + LAGRAPH_DATE) ; + OK (LAGraph_Init (msg) == GrB_SUCCESS) ; + OK (LAGraph_Version (version, verstring, msg) == GrB_SUCCESS) ; + printf ("LAGraph: v%d.%d.%d (%s) (in library)\n", + version [0], version [1], version [2], verstring) ; + OK (LAGraph_Finalize (msg) == GrB_SUCCESS) ; + #endif //-------------------------------------------------------------------------- // KLU diff --git a/Example/Source/my_cxx.cc b/Example/Source/my_cxx.cc index f72ac8c28b..f2935b6ec0 100644 --- a/Example/Source/my_cxx.cc +++ b/Example/Source/my_cxx.cc @@ -176,11 +176,11 @@ void my_function (void) cholmod_common cc ; OK (cholmod_l_start (&cc)) ; -#if ! defined (NO_GRAPHBLAS) //-------------------------------------------------------------------------- // GraphBLAS //-------------------------------------------------------------------------- + #if ! defined (NO_GRAPHBLAS) std::cout << "GraphBLAS: v" << GxB_IMPLEMENTATION_MAJOR << "." << GxB_IMPLEMENTATION_MINOR << "." @@ -194,7 +194,28 @@ void my_function (void) << version[2] << " " << "(in library)" << std::endl; OK (GrB_finalize ( ) == GrB_SUCCESS) ; -#endif + #endif + + //-------------------------------------------------------------------------- + // LAGraph + //-------------------------------------------------------------------------- + + #if ! defined (NO_LAGRAPH) + char msg [LAGRAPH_MSG_LEN], verstring [LAGRAPH_MSG_LEN] ; + std::cout << "LAGraph: v" + << LAGRAPH_VERSION_MAJOR << "." + << LAGRAPH_VERSION_MINOR << "." + << LAGRAPH_VERSION_UPDATE << " " + << "(" << LAGRAPH_DATE << ")" << std::endl; + OK (LAGraph_Init (msg) == GrB_SUCCESS) ; + OK (LAGraph_Version (version, verstring, msg) == GrB_SUCCESS) ; + std::cout << "LAGraph: v" + << version[0] << "." + << version[1] << "." + << version[2] << " " + << "(in library)" << std::endl; + OK (LAGraph_Finalize (msg) == GrB_SUCCESS) ; + #endif //-------------------------------------------------------------------------- // KLU diff --git a/LAGraph/config/LAGraph.h.in b/LAGraph/config/LAGraph.h.in index b506c7e14d..7ef78c2c53 100644 --- a/LAGraph/config/LAGraph.h.in +++ b/LAGraph/config/LAGraph.h.in @@ -370,6 +370,15 @@ } \ } +//============================================================================== +// for C++ applications: +//============================================================================== + +#if defined ( __cplusplus ) +extern "C" +{ +#endif + //============================================================================== // LAGraph memory management //============================================================================== @@ -2506,4 +2515,8 @@ int LAGr_TriangleCount char *msg ) ; +#if defined ( __cplusplus ) +} +#endif + #endif diff --git a/LAGraph/include/LAGraph.h b/LAGraph/include/LAGraph.h index 6d7f2d49bc..7bc41bdaab 100644 --- a/LAGraph/include/LAGraph.h +++ b/LAGraph/include/LAGraph.h @@ -370,6 +370,15 @@ } \ } +//============================================================================== +// for C++ applications: +//============================================================================== + +#if defined ( __cplusplus ) +extern "C" +{ +#endif + //============================================================================== // LAGraph memory management //============================================================================== @@ -2506,4 +2515,8 @@ int LAGr_TriangleCount char *msg ) ; +#if defined ( __cplusplus ) +} +#endif + #endif diff --git a/LAGraph/include/LAGraphX.h b/LAGraph/include/LAGraphX.h index c17b2fbbe7..fe3b29a9c9 100644 --- a/LAGraph/include/LAGraphX.h +++ b/LAGraph/include/LAGraphX.h @@ -32,6 +32,15 @@ #define LAGRAPHX_PUBLIC #endif +//============================================================================== +// for C++ applications: +//============================================================================== + +#if defined ( __cplusplus ) +extern "C" +{ +#endif + //============================================================================== // Experimental methods: in experimental/algorithm and experimental/utility //============================================================================== @@ -882,4 +891,8 @@ int LAGraph_HelloWorld // a simple algorithm, just for illustration char *msg ) ; +#if defined ( __cplusplus ) +} +#endif + #endif