Skip to content

Commit

Permalink
UMFPACK: add octave support
Browse files Browse the repository at this point in the history
  • Loading branch information
homka122 committed May 10, 2024
1 parent 31f2a24 commit 5d4127f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 21 deletions.
66 changes: 48 additions & 18 deletions UMFPACK/MATLAB/umfpack_make.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@
% UMFPACK, Copyright (c) 2005-2022, Timothy A. Davis, All Rights Reserved.
% SPDX-License-Identifier: GPL-2.0+

have_octave = (exist ('OCTAVE_VERSION', 'builtin') == 5) ;

metis_path = '../../CHOLMOD/SuiteSparse_metis' ;
with_cholmod = exist (metis_path, 'dir') ;

details = 0 ; % set to 1 to print out each mex command as it's executed

flags = '' ;
is64 = ~isempty (strfind (computer, '64')) ;
if (is64)
if (is64 && ~have_octave)
flags = ' -largeArrayDims' ;
end

% MATLAB 8.3.0 now has a -silent option to keep 'mex' from burbling too much
if (~verLessThan ('matlab', '8.3.0'))
if (have_octave)
flags = ['--silent', flags] ;
elseif (~verLessThan ('matlab', '8.3.0'))
% MATLAB 8.3.0 now has a -silent option to keep 'mex' from burbling too much
flags = ['-silent ' flags] ;
end

Expand All @@ -41,7 +45,11 @@

v = version ;

fprintf ('Compiling UMFPACK for MATLAB Version %s\n', v) ;
if (have_octave)
fprintf ('Compiling UMFPACK for Octave Version %s\n', v) ;
else
fprintf ('Compiling UMFPACK for MATLAB Version %s\n', v) ;
end

if (ispc)
obj = 'obj' ;
Expand All @@ -57,41 +65,63 @@

% This is exceedingly ugly. The MATLAB mex command needs to be told where to
% find the LAPACK and BLAS libraries, which is a real portability nightmare.

if (ispc)
% BLAS/LAPACK functions have no underscore on Windows
flags = [flags ' -DBLAS_NO_UNDERSCORE'] ;
if (verLessThan ('matlab', '7.5'))
lapack = 'libmwlapack.lib' ;
elseif (verLessThan ('matlab', '9.5'))
lapack = 'libmwlapack.lib libmwblas.lib' ;

if (have_octave)
lapack = '-llapack -lblas' ;
else
lapack = '-lmwlapack -lmwblas' ;
if (verLessThan ('matlab', '7.5'))
lapack = 'libmwlapack.lib' ;
elseif (verLessThan ('matlab', '9.5'))
lapack = 'libmwlapack.lib libmwblas.lib' ;
else
lapack = '-lmwlapack -lmwblas' ;
end
end

else
% BLAS/LAPACK functions have an underscore suffix
flags = [flags ' -DBLAS_UNDERSCORE'] ;
if (verLessThan ('matlab', '7.5'))
lapack = '-lmwlapack' ;

if (have_octave)
lapack = '-llapack -lblas' ;
else
lapack = '-lmwlapack -lmwblas' ;
if (verLessThan ('matlab', '7.5'))
lapack = '-lmwlapack' ;
else
lapack = '-lmwlapack -lmwblas' ;
end
end
end

if (is64 && ~verLessThan ('matlab', '7.8'))
% versions 7.8 and later on 64-bit platforms use a 64-bit BLAS
fprintf ('with 64-bit BLAS\n') ;
flags = [flags ' -DBLAS64'] ;
if (is64)

if (have_octave)
fprintf ('with 64-bit BLAS\n') ;
flags = [flags ' -DBLAS64'] ;
elseif (~verLessThan ('matlab', '7.8'))
% versions 7.8 and later on 64-bit platforms use a 64-bit BLAS
fprintf ('with 64-bit BLAS\n') ;
flags = [flags ' -DBLAS64'] ;
else
% other versions of MATLAB use a 32-bit BLAS
flags = [flags ' -DBLAS32'] ;
end
else
% other versions of MATLAB use a 32-bit BLAS
flags = [flags ' -DBLAS32'] ;
end

if (have_octave)
flags = [flags ' -DOCTAVE -DNRECIPROCAL']
end

if (~(ispc || ismac))
% for POSIX timing routine
lapack = [lapack ' -lrt'] ;
end

%-------------------------------------------------------------------------------
% Source and include directories
%-------------------------------------------------------------------------------
Expand Down
24 changes: 22 additions & 2 deletions UMFPACK/MATLAB/umfpack_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ function umfpack_test (nmat)
% UMFPACK, Copyright (c) 2005-2022, Timothy A. Davis, All Rights Reserved.
% SPDX-License-Identifier: GPL-2.0+

index = ssget ;
have_octave = (exist ('OCTAVE_VERSION', 'builtin') == 5) ;

index = ssget('refresh') ;

f = find (index.nrows == index.ncols) ;
[ignore, i] = sort (index.nrows (f)) ;
Expand Down Expand Up @@ -42,6 +44,12 @@ function umfpack_test (nmat)

Prob = ssget (i) ;
A = Prob.A ;

% Octave cannot process matrices whose version is 7.3
if (have_octave && ~issparse(A))
continue ;
end

n = size (A,1) ;

b = rand (1,n) ;
Expand All @@ -57,7 +65,19 @@ function umfpack_test (nmat)
title ('A')

subplot (2,2,2)
treeplot (Fr (1:end-1,2)') ;

Fr_slice = Fr(1:end-1, 2)'
if (~have_octave)
treeplot(Fr_slice)
else
% Octave don't support treeplot with empty vector
if (~isempty(Fr_slice))
treeplot(Fr_slice)
else
plot([])
end
end

title ('supercolumn etree')

%-----------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion UMFPACK/MATLAB/umfpackmex.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@

#include "umfpack.h"
#include "mex.h"
#include "matrix.h"
#include <string.h>
#include <math.h>
#include <float.h>
#include <stdio.h>

#ifndef OCTAVE
#include "matrix.h"
#endif

#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
Expand Down

0 comments on commit 5d4127f

Please sign in to comment.