From cfb0a65b1caa4d437ff362ecd0d1feb626c78e0b Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 15 Apr 2024 11:10:26 +0300 Subject: [PATCH] suitesparse-colamd: new recipe --- recipes/suitesparse-colamd/all/conandata.yml | 4 + recipes/suitesparse-colamd/all/conanfile.py | 94 ++++++++ .../all/test_package/CMakeLists.txt | 8 + .../all/test_package/conanfile.py | 26 +++ .../all/test_package/test_package.c | 202 ++++++++++++++++++ recipes/suitesparse-colamd/config.yml | 3 + 6 files changed, 337 insertions(+) create mode 100644 recipes/suitesparse-colamd/all/conandata.yml create mode 100644 recipes/suitesparse-colamd/all/conanfile.py create mode 100644 recipes/suitesparse-colamd/all/test_package/CMakeLists.txt create mode 100644 recipes/suitesparse-colamd/all/test_package/conanfile.py create mode 100644 recipes/suitesparse-colamd/all/test_package/test_package.c create mode 100644 recipes/suitesparse-colamd/config.yml diff --git a/recipes/suitesparse-colamd/all/conandata.yml b/recipes/suitesparse-colamd/all/conandata.yml new file mode 100644 index 0000000000000..e14d8a2b78174 --- /dev/null +++ b/recipes/suitesparse-colamd/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "3.3.3": + url: "https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/refs/tags/v7.7.0.tar.gz" + sha256: "529b067f5d80981f45ddf6766627b8fc5af619822f068f342aab776e683df4f3" diff --git a/recipes/suitesparse-colamd/all/conanfile.py b/recipes/suitesparse-colamd/all/conanfile.py new file mode 100644 index 0000000000000..1766bf04f686a --- /dev/null +++ b/recipes/suitesparse-colamd/all/conanfile.py @@ -0,0 +1,94 @@ +import os + +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.env import VirtualBuildEnv +from conan.tools.files import get, rm, rmdir, copy + +required_conan_version = ">=1.53.0" + + +class SuiteSparseColamdConan(ConanFile): + name = "suitesparse-colamd" + description = "COLAMD: Routines for column approximate minimum degree ordering algorithm in SuiteSparse" + license = "BSD-3-Clause" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://people.engr.tamu.edu/davis/suitesparse.html" + topics = ("mathematics", "sparse-matrix", "minimum-degree-ordering") + + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + self.settings.rm_safe("compiler.cppstd") + self.settings.rm_safe("compiler.libcxx") + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + # OpenBLAS and OpenMP are provided via suitesparse-config + self.requires("suitesparse-config/7.7.0", transitive_headers=True, transitive_libs=True) + + def build_requirements(self): + self.tool_requires("cmake/[>=3.22 <4]") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + venv = VirtualBuildEnv(self) + venv.generate() + + tc = CMakeToolchain(self) + tc.variables["BUILD_SHARED_LIBS"] = self.options.shared + tc.variables["BUILD_STATIC_LIBS"] = not self.options.shared + tc.variables["SUITESPARSE_USE_OPENMP"] = True + tc.variables["SUITESPARSE_USE_CUDA"] = False + tc.variables["SUITESPARSE_DEMOS"] = False + tc.variables["SUITESPARSE_USE_FORTRAN"] = False # Fortran sources are translated to C instead + tc.generate() + + deps = CMakeDeps(self) + deps.generate() + + def build(self): + cmake = CMake(self) + cmake.configure(build_script_folder=os.path.join(self.source_folder, "COLAMD")) + cmake.build() + + def package(self): + copy(self, "License.txt", os.path.join(self.source_folder, "COLAMD", "Doc"), os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "share")) + rm(self, "*.pdb", self.package_folder, recursive=True) + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "COLAMD") + self.cpp_info.set_property("cmake_target_name", "SuiteSparse::COLAMD") + if not self.options.shared: + self.cpp_info.set_property("cmake_target_aliases", ["SuiteSparse::COLAMD_static"]) + self.cpp_info.set_property("pkg_config_name", "COLAMD") + + self.cpp_info.libs = ["colamd"] + self.cpp_info.includedirs.append(os.path.join("include", "suitesparse")) + + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs.append("m") diff --git a/recipes/suitesparse-colamd/all/test_package/CMakeLists.txt b/recipes/suitesparse-colamd/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..ef974f53aaf32 --- /dev/null +++ b/recipes/suitesparse-colamd/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) + +find_package(COLAMD REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE SuiteSparse::COLAMD) +target_compile_features(${PROJECT_NAME} PRIVATE c_std_11) diff --git a/recipes/suitesparse-colamd/all/test_package/conanfile.py b/recipes/suitesparse-colamd/all/test_package/conanfile.py new file mode 100644 index 0000000000000..ef5d7042163ec --- /dev/null +++ b/recipes/suitesparse-colamd/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/suitesparse-colamd/all/test_package/test_package.c b/recipes/suitesparse-colamd/all/test_package/test_package.c new file mode 100644 index 0000000000000..019eea4d748da --- /dev/null +++ b/recipes/suitesparse-colamd/all/test_package/test_package.c @@ -0,0 +1,202 @@ +// https://github.com/DrTimothyAldenDavis/SuiteSparse/blob/v7.7.0/COLAMD/Demo/colamd_l_example.c + +//------------------------------------------------------------------------------ +// COLAMD/Demo/colamd_l_example.c: simple example for COLAMD (int64_t) +//------------------------------------------------------------------------------ + +// COLAMD, Copyright (c) 1998-2022, Timothy A. Davis and Stefan Larimore, +// All Rights Reserved. +// SPDX-License-Identifier: BSD-3-clause + +//------------------------------------------------------------------------------ + +/* COLAMD / SYMAMD example + + colamd example of use, to order the columns of a 5-by-4 matrix with + 11 nonzero entries in the following nonzero pattern, with default knobs. + + x 0 x 0 + x 0 x x + 0 x x 0 + 0 0 x x + x x 0 0 + + symamd example of use, to order the rows and columns of a 5-by-5 + matrix with 13 nonzero entries in the following nonzero pattern, + with default knobs. + + x x 0 0 0 + x x x x 0 + 0 x x 0 0 + 0 x 0 x x + 0 0 0 x x + + (where x denotes a nonzero value). +*/ + +/* ========================================================================== */ + +#include + +#include + +#define A_NNZ 11 +#define A_NROW 5 +#define A_NCOL 4 +#define ALEN 150 + +#define B_NNZ 4 +#define B_N 5 + +int main (void) +{ + + /* ====================================================================== */ + /* input matrix A definition */ + /* ====================================================================== */ + + int64_t A [ALEN] = { + + 0, 1, 4, /* row indices of nonzeros in column 0 */ + 2, 4, /* row indices of nonzeros in column 1 */ + 0, 1, 2, 3, /* row indices of nonzeros in column 2 */ + 1, 3} ; /* row indices of nonzeros in column 3 */ + + int64_t p [ ] = { + + 0, /* column 0 is in A [0..2] */ + 3, /* column 1 is in A [3..4] */ + 5, /* column 2 is in A [5..8] */ + 9, /* column 3 is in A [9..10] */ + A_NNZ} ; /* number of nonzeros in A */ + + /* ====================================================================== */ + /* input matrix B definition */ + /* ====================================================================== */ + + int64_t B [ ] = { /* Note: only strictly lower triangular part */ + /* is included, since symamd ignores the */ + /* diagonal and upper triangular part of B. */ + + 1, /* row indices of nonzeros in column 0 */ + 2, 3, /* row indices of nonzeros in column 1 */ + /* row indices of nonzeros in column 2 (none) */ + 4 /* row indices of nonzeros in column 3 */ + } ; /* row indices of nonzeros in column 4 (none) */ + + int64_t q [ ] = { + + 0, /* column 0 is in B [0] */ + 1, /* column 1 is in B [1..2] */ + 3, /* column 2 is empty */ + 3, /* column 3 is in B [3] */ + 4, /* column 4 is empty */ + B_NNZ} ; /* number of nonzeros in strictly lower B */ + + /* ====================================================================== */ + /* other variable definitions */ + /* ====================================================================== */ + + int64_t perm [B_N+1] ; /* note the size is N+1 */ + int64_t stats [COLAMD_STATS] ; /* for colamd and symamd output statistics */ + + int64_t row, col, pp, length ; + int ok ; + + //-------------------------------------------------------------------------- + // colamd version + //-------------------------------------------------------------------------- + + int version [3] ; + colamd_version (version) ; + printf ("COLAMD v%d.%d.%d\n", version [0], version [1], version [2]) ; + if ((version [0] != COLAMD_MAIN_VERSION) || + (version [1] != COLAMD_SUB_VERSION) || + (version [2] != COLAMD_SUBSUB_VERSION)) + { + fprintf (stderr, "version in header does not match library\n") ; + abort ( ) ; + } + + /* ====================================================================== */ + /* dump the input matrix A */ + /* ====================================================================== */ + + printf ("colamd %d-by-%d input matrix:\n", A_NROW, A_NCOL) ; + for (col = 0 ; col < A_NCOL ; col++) + { + length = p [col+1] - p [col] ; + printf ("Column %"PRId64", with %"PRId64" entries:\n", col, length) ; + for (pp = p [col] ; pp < p [col+1] ; pp++) + { + row = A [pp] ; + printf (" row %"PRId64"\n", row) ; + } + } + + /* ====================================================================== */ + /* order the matrix. Note that this destroys A and overwrites p */ + /* ====================================================================== */ + + ok = colamd_l (A_NROW, A_NCOL, ALEN, A, p, (double *) NULL, stats) ; + colamd_l_report (stats) ; + + if (!ok) + { + printf ("colamd error!\n") ; + exit (1) ; + } + + /* ====================================================================== */ + /* print the column ordering */ + /* ====================================================================== */ + + printf ("colamd_l column ordering:\n") ; + printf ("1st column: %"PRId64"\n", p [0]) ; + printf ("2nd column: %"PRId64"\n", p [1]) ; + printf ("3rd column: %"PRId64"\n", p [2]) ; + printf ("4th column: %"PRId64"\n", p [3]) ; + + /* ====================================================================== */ + /* dump the strictly lower triangular part of symmetric input matrix B */ + /* ====================================================================== */ + + printf ("\n\nsymamd_l %d-by-%d input matrix:\n", B_N, B_N) ; + printf ("Entries in strictly lower triangular part:\n") ; + for (col = 0 ; col < B_N ; col++) + { + length = q [col+1] - q [col] ; + printf ("Column %"PRId64", with %"PRId64" entries:\n", col, length) ; + for (pp = q [col] ; pp < q [col+1] ; pp++) + { + row = B [pp] ; + printf (" row %"PRId64"\n", row) ; + } + } + + /* ====================================================================== */ + /* order the matrix B. Note that this does not modify B or q. */ + /* ====================================================================== */ + + ok = symamd_l (B_N, B, q, perm, (double *) NULL, stats, &calloc, &free) ; + symamd_l_report (stats) ; + + if (!ok) + { + printf ("symamd error!\n") ; + exit (1) ; + } + + /* ====================================================================== */ + /* print the symmetric ordering */ + /* ====================================================================== */ + + printf ("symamd_l column ordering:\n") ; + printf ("1st row/column: %"PRId64"\n", perm [0]) ; + printf ("2nd row/column: %"PRId64"\n", perm [1]) ; + printf ("3rd row/column: %"PRId64"\n", perm [2]) ; + printf ("4th row/column: %"PRId64"\n", perm [3]) ; + printf ("5th row/column: %"PRId64"\n", perm [4]) ; + + exit (0) ; +} diff --git a/recipes/suitesparse-colamd/config.yml b/recipes/suitesparse-colamd/config.yml new file mode 100644 index 0000000000000..6747903d9d322 --- /dev/null +++ b/recipes/suitesparse-colamd/config.yml @@ -0,0 +1,3 @@ +versions: + "3.3.3": + folder: all