Skip to content

Commit

Permalink
SPEX matlab interface
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTimothyAldenDavis committed Mar 5, 2024
1 parent 04c5764 commit f68b699
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
17 changes: 17 additions & 0 deletions SPEX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,23 @@ install ( FILES
${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindMPFR.cmake
DESTINATION ${SUITESPARSE_PKGFILEDIR}/cmake/SPEX )

#-------------------------------------------------------------------------------
# configure MATLAB
#-------------------------------------------------------------------------------

cmake_path ( IS_ABSOLUTE SUITESPARSE_LIBDIR SUITESPARSE_LIBDIR_IS_ABSOLUTE )
if (SUITESPARSE_LIBDIR_IS_ABSOLUTE)
set ( matlab_libdir "${SUITESPARSE_LIBDIR}")
else ( )
set ( matlab_libdir "${CMAKE_INSTALL_PREFIX}/${SUITESPARSE_LIBDIR}")
endif ( )
cmake_path ( IS_ABSOLUTE SUITESPARSE_INCLUDEDIR SUITESPARSE_INCLUDEDIR_IS_ABSOLUTE )
if (SUITESPARSE_INCLUDEDIR_IS_ABSOLUTE)
set ( matlab_includedir "${SUITESPARSE_INCLUDEDIR}")
else ( )
set ( matlab_includedir "${CMAKE_INSTALL_PREFIX}/${SUITESPARSE_INCLUDEDIR}")
endif ( )

#-------------------------------------------------------------------------------
# create pkg-config file
#-------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions SPEX/Config/spex_deps.m.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ function [suitesparse_libdir, suitesparse_incdir, gmp_lib, gmp_include, mpfr_lib
% On Linux you may need to add the following to your shell script (typically
% .bashrc), start a new shell, and then start MATLAB again.
%
% LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@SUITESPARSE_LIBDIR@
% LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@matlab_libdir@

% SPEX: (c) 2022-2023, Chris Lourenco, Jinhao Chen,
% SPEX: (c) 2022-2024, Chris Lourenco, Jinhao Chen,
% Lorena Mejia Domenzain, Timothy A. Davis, and Erick Moreno-Centeno.
% All Rights Reserved.
% SPDX-License-Identifier: GPL-2.0-or-later or LGPL-3.0-or-later

suitesparse_libdir = '@libdir@' ;
suitesparse_incdir = '@includedir@' ;
suitesparse_libdir = '@matlab_libdir@' ;
suitesparse_incdir = '@matlab_includedir@' ;
gmp_lib = '@GMP_LIBRARY@' ;
gmp_include = '@GMP_INCLUDE_DIR@' ;
mpfr_lib = '@MPFR_LIBRARY@' ;
Expand Down
36 changes: 24 additions & 12 deletions SPEX/MATLAB/spex_mex_install.m
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
function spex_mex_install(run_demo)
% spex_mex_INSTALL: install and test the MATLAB interface to SPEX MATLAB functions.
% spex_mex_install: install and test the MATLAB interface to SPEX MATLAB functions.
%
% Usage: spex_mex_install
%
% Required Libraries: GMP, MPFR, AMD, COLAMD, SPEX. If -lamd and -lcolamd are
% not available, install them with 'make install' first, in the top-level
% SuiteSparse folder.
% Required Libraries: GMP, MPFR, AMD, COLAMD, SuiteSparse_config, SPEX. If
% -lamd, -lcolamd, and -lsuitesparseconfig are not available, install them with
% 'make install' first, in the top-level SuiteSparse folder.
%
% You may need to add the top-level lib folder (SPEX/lib, or SuiteSparse/lib
% if SPEX is inside SuiteSparse) to your LD_LIBRARY_PATH (DYLD_LIBRARY_PATH
% on the Mac). See instructions in the spex_deps.m file.

% SPEX: (c) 2022, Chris Lourenco, Jinhao Chen,
% SPEX: (c) 2022-2024, Chris Lourenco, Jinhao Chen,
% Lorena Mejia Domenzain, Timothy A. Davis, and Erick Moreno-Centeno.
% All Rights Reserved.
% SPDX-License-Identifier: GPL-2.0-or-later or LGPL-3.0-or-later


if (nargin < 1)
run_demo = true ;
end

fprintf ('Compiling the SPEX mexFunctions for use:\n') ;
fprintf ('Compiling the SPEX for use in MATLAB:\n') ;

% Find all source files and add them to the src string
src = '';
Expand Down Expand Up @@ -63,12 +62,17 @@ function spex_mex_install(run_demo)
src = [src, tmp];
end

% Compiler flags
flags = 'CFLAGS=''-std=c99 -fPIC'' LDFLAGS=''-Wl,-rpath=''../../lib''''';

% External libraries: GMP, MPRF, AMD, and COLAMD
[suitesparse_libdir, suitesparse_incdir, gmp_lib, gmp_include, mpfr_lib, mpfr_include] = spex_deps ;

% Compiler flags
openmp = '' ;
if (~ismac && isunix)
openmp = ' -fopenmp' ;
end
flags = sprintf ('CFLAGS=''-std=c11 -fPIC %s'' LDFLAGS=''-Wl,-rpath=''%s''''', ...
openmp, suitesparse_libdir) ;

% libraries:
if (isempty (suitesparse_libdir))
suitesparse_libdir = ' ' ;
Expand Down Expand Up @@ -105,13 +109,21 @@ function spex_mex_install(run_demo)
m2 = ['mex ', verbose, ' -R2018a ', includes, ' spex_cholesky_mex_soln.c ' , src, ' ', flags, ' ', libs];
m3 = ['mex ', verbose, ' -R2018a ', includes, ' spex_backslash_mex_soln.c ' , src, ' ', flags, ' ', libs];

% Now, we evaluate each one
if (~isempty (verbose))
fprintf ('%s\n', m1) ;
end

% Now, we evaluate each one
fprintf ('Compiling MATLAB interface to SPEX LU:\n') ;
eval (m1) ;
if (~isempty (verbose))
fprintf ('%s\n', m2) ;
end
fprintf ('Compiling MATLAB interface to SPEX Cholesky:\n') ;
eval (m2) ;
if (~isempty (verbose))
fprintf ('%s\n', m3) ;
end
fprintf ('Compiling MATLAB interface to SPEX Backslash:\n') ;
eval (m3) ;

if (run_demo)
Expand Down
2 changes: 1 addition & 1 deletion SPEX/MATLAB/spex_mex_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
fprintf ('\nmaxerr: %g\n', maxerr) ;

if (maxerr < 1e-6)
fprintf('\nLeft LU installation successful\n')
fprintf('\nSPEX LU installation successful\n')
else
error ('\nTesting failure! error too high please reinstall\n')
end
Expand Down

0 comments on commit f68b699

Please sign in to comment.