Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suitesparse-colamd: new recipe #23545

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/suitesparse-colamd/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"3.3.3":
url: "https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/refs/tags/v7.7.0.tar.gz"
sha256: "529b067f5d80981f45ddf6766627b8fc5af619822f068f342aab776e683df4f3"
94 changes: 94 additions & 0 deletions recipes/suitesparse-colamd/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
8 changes: 8 additions & 0 deletions recipes/suitesparse-colamd/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions recipes/suitesparse-colamd/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
202 changes: 202 additions & 0 deletions recipes/suitesparse-colamd/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -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 <colamd.h>

#include <stdio.h>

#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) ;
}
3 changes: 3 additions & 0 deletions recipes/suitesparse-colamd/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"3.3.3":
folder: all
Loading