~ubuntu-branches/ubuntu/natty/suitesparse/natty

« back to all changes in this revision

Viewing changes to UMFPACK/MATLAB/umfpack_make.m

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2007-05-29 09:36:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529093629-zowquo0b7slkk6nc
Tags: 3.0.0-2
* suitesparse builds properly twice in a row
* Bug fix: "suitesparse - FTBFS: Broken build depens: libgfortran1-dev",
  thanks to Bastian Blank (Closes: #426349).
* Bug fix: "suitesparse_3.0.0-1: FTBFS: build-depends on
  libgfortran1-dev", thanks to Steve Langasek (Closes: #426354).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
function umfpack_make
2
 
% UMFPACK_MAKE
3
 
%
4
 
% Compiles the UMFPACK mexFunction and then runs a simple demo.
5
 
%
6
 
% See also: umfpack, umfpack_details, umfpack_report, umfpack_demo, and
7
 
% umfpack_simple.
8
 
%
9
 
% UMFPACK Version 5.0, Copyright (c) 1995-2006 by Timothy A. Davis.
10
 
% All Rights Reserved.  Type umfpack_details for License.
11
 
 
12
 
help umfpack_make
13
 
 
 
1
function umfpack_make (lapack)
 
2
%UMFPACK_MAKE to compile umfpack2 for use in MATLAB
 
3
%
 
4
% Compiles the umfpack2 mexFunction and then runs a simple demo.
 
5
%
 
6
% Example:
 
7
%   umfpack_make                                % use default LAPACK and BLAS
 
8
%   umfpack_make ('lcc_lib/libmwlapack.lib')    % try this if umfpack_make fails
 
9
%
 
10
% See also: umfpack, umfpack2, umfpack_details, umfpack_report, umfpack_demo,
 
11
% and umfpack_simple.
 
12
 
 
13
% Copyright 1995-2007 by Timothy A. Davis.
 
14
 
 
15
details = 0 ;
 
16
 
 
17
d = '' ;
14
18
if (~isempty (strfind (computer, '64')))
15
 
    error ('64-bit version not yet supported') ;
16
 
end
17
 
 
18
 
fprintf ('\n--------------------------------------------------------------\n') ;
19
 
fprintf ('Now compiling the UMFPACK and AMD mexFunctions.\n') ;
20
 
fprintf ('--------------------------------------------------------------\n') ;
21
 
 
22
 
try
23
 
    % ispc does not appear in MATLAB 5.3
24
 
    pc = ispc ;
25
 
catch
26
 
    % if ispc fails, assume we aren't on a Windows PC.
27
 
    pc = 0 ;
28
 
end
29
 
 
30
 
obj = 'o' ;
31
 
blas_lib = '' ;
 
19
    d = ' -largeArrayDims' ;
 
20
end
 
21
 
 
22
[v,pc] = getversion ;
 
23
fprintf ('Compiling UMFPACK for MATLAB Version %g\n', v) ;
 
24
 
32
25
if (pc)
33
26
    obj = 'obj' ;
 
27
else
 
28
    obj = 'o' ;
34
29
end
35
30
 
 
31
kk = 0 ;
 
32
 
36
33
%-------------------------------------------------------------------------------
37
34
% BLAS option
38
35
%-------------------------------------------------------------------------------
39
36
 
40
 
% msg = [ ...
41
 
%     '\nUsing the BLAS is faster, but might not compile correctly.\n', ...
42
 
%     'If you get an error stating that dgemm, dgemv, dger, zgemm,\n', ...
43
 
%     'zgemv, and/or zger are not defined, then recompile without the\n', ...
44
 
%     'BLAS.  You can ignore warnings that these routines are implicitly\n', ...
45
 
%     'declared.\n\nPlease select one of the following options: \n', ...
46
 
%     '   1:  attempt to compile with the BLAS (default)\n', ...
47
 
%     '   2:  do not use the BLAS (UMFPACK will be slow)\n'] ;
48
 
% fprintf (msg) ;
49
 
% blas = input (': ') ;
50
 
% if (isempty (blas))
51
 
%     blas = 1 ;
52
 
% end
53
 
 
54
 
% if (blas == 1)
55
 
 
56
 
    % try to link to MATLAB's built-in BLAS
57
 
    blas = '' ;
 
37
if (nargin < 1)
58
38
    if (pc)
59
 
        % the default lcc compiler needs this library to access the BLAS
60
 
        blas_lib = ' libmwlapack.lib' ;
 
39
        if (v < 6.5)
 
40
            % MATLAB 6.1 and earlier: use the version supplied here
 
41
            lapack = 'lcc_lib/libmwlapack.lib' ;
 
42
            fprintf ('Using %s.  If this fails with dgemm and others\n',lapack);
 
43
            fprintf ('undefined, then edit umfpack_make.m and modify the') ;
 
44
            fprintf (' statement:\nlapack = ''%s'' ;\n', lapack) ;
 
45
        else
 
46
            lapack = 'libmwlapack.lib' ;
 
47
        end
 
48
    else
 
49
        % For other systems, mex should find lapack on its own, but this has
 
50
        % been broken in MATLAB R2007a; the following is now required.
 
51
        lapack = '-lmwlapack' ;
61
52
    end
62
 
 
63
 
%    fprintf ('\nUsing the BLAS (recommended).\n') ;
64
 
% else
65
 
%    % No BLAS
66
 
%    fprintf ('\nNot using the BLAS.  UMFPACK will be slow.\n') ;
67
 
%    blas = ' -DNBLAS' ;
68
 
% end
 
53
end
69
54
 
70
55
%-------------------------------------------------------------------------------
71
56
% -DNPOSIX option (for sysconf and times timer routines)
86
71
%    '    1:  use POSIX sysconf and times routines (default)\n', ...
87
72
%    '    2:  do not use POSIX routines\n'] ;
88
73
%    fprintf (msg) ;
89
 
%    posix = input (': ') ;
 
74
%    posix = str2num (input (': ', 's')) ;
90
75
%    if (isempty (posix))
91
76
%       posix = 1 ;
92
77
%    end
106
91
umfdir = '../Source/' ;
107
92
amddir = '../../AMD/Source/' ;
108
93
incdir = ' -I../Include -I../Source -I../../AMD/Include -I../../UFconfig' ;
109
 
 
110
 
mx = sprintf ('mex -inline -O%s%s%s', blas, posix, incdir) ;
111
 
msg = [ ...
112
 
    '--------------------------------------------------------------\n', ...
113
 
    '\nCompile options:\n%s\nNow compiling.  Please wait.\n'] ;
114
 
fprintf (msg, mx) ;
115
 
 
116
 
% The following is adapted from GNUmakefile
 
94
mx = sprintf ('mex -O%s%s%s ', posix, incdir, d) ;
 
95
% fprintf ('compile options:\n%s\n', mx) ;
117
96
 
118
97
%-------------------------------------------------------------------------------
119
98
% source files
141
120
        'singletons' } ;
142
121
 
143
122
% non-user-callable and user-callable amd_*.[ch] files (int versions only):
144
 
amd = { 'aat', '1', '2', 'dump', 'postorder', 'post_tree', 'defaults', ...
 
123
amdsrc = { 'aat', '1', '2', 'dump', 'postorder', 'post_tree', 'defaults', ...
145
124
        'order', 'control', 'info', 'valid', 'preprocess', 'global' } ;
146
125
 
147
126
% user-callable umfpack_*.[ch] files (real/complex):
161
140
M = cell (0) ;
162
141
 
163
142
%-------------------------------------------------------------------------------
164
 
% Create the umfpack and amd mexFunctions for MATLAB (int versions only)
 
143
% Create the umfpack2 and amd2 mexFunctions for MATLAB (int versions only)
165
144
%-------------------------------------------------------------------------------
166
145
 
167
146
for k = 1:length(umfint)
168
 
    M = make (M, '%s -DDINT -c %sumf_%s.c', 'umf_%s.%s', 'umf_%s_%s.%s', ...
169
 
        mx, umfint {k}, umfint {k}, 'm', obj, umfdir) ;
 
147
    [M, kk] = make (M, '%s -DDLONG -c %sumf_%s.c', 'umf_%s.%s', ...
 
148
        'umf_%s_%s.%s', mx, umfint {k}, umfint {k}, 'm', obj, umfdir, ...
 
149
        kk, details) ;
170
150
end
171
151
 
172
 
rules = { [mx ' -DDINT'] , [mx ' -DZINT'] } ;
 
152
rules = { [mx ' -DDLONG'] , [mx ' -DZLONG'] } ;
173
153
kinds = { 'md', 'mz' } ;
174
154
 
175
155
for what = 1:2
177
157
    rule = rules {what} ;
178
158
    kind = kinds {what} ;
179
159
 
180
 
    M = make (M, '%s -DCONJUGATE_SOLVE -c %sumf_%s.c', 'umf_%s.%s', ...
181
 
        'umf_%s_%s.%s', rule, 'ltsolve', 'lhsolve', kind, obj, umfdir) ;
182
 
 
183
 
    M = make (M, '%s -DCONJUGATE_SOLVE -c %sumf_%s.c', 'umf_%s.%s', ...
184
 
        'umf_%s_%s.%s', rule, 'utsolve', 'uhsolve', kind, obj, umfdir) ;
185
 
 
186
 
    M = make (M, '%s -DDO_MAP -c %sumf_%s.c', 'umf_%s.%s', ...
187
 
        'umf_%s_%s_map_nox.%s', rule, 'triplet', 'triplet', kind, obj, umfdir) ;
188
 
 
189
 
    M = make (M, '%s -DDO_VALUES -c %sumf_%s.c', 'umf_%s.%s', ...
190
 
        'umf_%s_%s_nomap_x.%s', rule, 'triplet', 'triplet', kind, obj, umfdir) ;
191
 
 
192
 
    M = make (M, '%s -c %sumf_%s.c', 'umf_%s.%s',  ...
 
160
    [M, kk] = make (M, '%s -DCONJUGATE_SOLVE -c %sumf_%s.c', 'umf_%s.%s', ...
 
161
        'umf_%s_%s.%s', rule, 'ltsolve', 'lhsolve', kind, obj, umfdir, ...
 
162
        kk, details) ;
 
163
 
 
164
    [M, kk] = make (M, '%s -DCONJUGATE_SOLVE -c %sumf_%s.c', 'umf_%s.%s', ...
 
165
        'umf_%s_%s.%s', rule, 'utsolve', 'uhsolve', kind, obj, umfdir, ...
 
166
        kk, details) ;
 
167
 
 
168
    [M, kk] = make (M, '%s -DDO_MAP -c %sumf_%s.c', 'umf_%s.%s', ...
 
169
        'umf_%s_%s_map_nox.%s', rule, 'triplet', 'triplet', kind, obj, ...
 
170
        umfdir, kk, details) ;
 
171
 
 
172
    [M, kk] = make (M, '%s -DDO_VALUES -c %sumf_%s.c', 'umf_%s.%s', ...
 
173
        'umf_%s_%s_nomap_x.%s', rule, 'triplet', 'triplet', kind, obj, ...
 
174
        umfdir, kk, details) ;
 
175
 
 
176
    [M, kk] = make (M, '%s -c %sumf_%s.c', 'umf_%s.%s',  ...
193
177
        'umf_%s_%s_nomap_nox.%s', rule, 'triplet', 'triplet', kind, obj, ...
194
 
        umfdir) ;
195
 
 
196
 
    M = make (M, '%s -DDO_MAP -DDO_VALUES -c %sumf_%s.c', 'umf_%s.%s', ...
197
 
        'umf_%s_%s_map_x.%s', rule, 'triplet', 'triplet', kind, obj, umfdir) ;
198
 
 
199
 
    M = make (M, '%s -DFIXQ -c %sumf_%s.c', 'umf_%s.%s', ...
200
 
        'umf_%s_%s_fixq.%s', rule, 'assemble', 'assemble', kind, obj, umfdir) ;
201
 
 
202
 
    M = make (M, '%s -DDROP -c %sumf_%s.c', 'umf_%s.%s', ...
203
 
        'umf_%s_%s_drop.%s', rule, 'store_lu', 'store_lu', kind, obj, umfdir) ;
 
178
        umfdir, kk, details) ;
 
179
 
 
180
    [M, kk] = make (M, '%s -DDO_MAP -DDO_VALUES -c %sumf_%s.c', 'umf_%s.%s', ...
 
181
        'umf_%s_%s_map_x.%s', rule, 'triplet', 'triplet', kind, obj, ...
 
182
        umfdir, kk, details) ;
 
183
 
 
184
    [M, kk] = make (M, '%s -DFIXQ -c %sumf_%s.c', 'umf_%s.%s', ...
 
185
        'umf_%s_%s_fixq.%s', rule, 'assemble', 'assemble', kind, obj, ...
 
186
        umfdir, kk, details) ;
 
187
 
 
188
    [M, kk] = make (M, '%s -DDROP -c %sumf_%s.c', 'umf_%s.%s', ...
 
189
        'umf_%s_%s_drop.%s', rule, 'store_lu', 'store_lu', kind, obj, ...
 
190
        umfdir, kk, details) ;
204
191
 
205
192
    for k = 1:length(umfch)
206
 
        M = make (M, '%s -c %sumf_%s.c', 'umf_%s.%s', 'umf_%s_%s.%s', ...
207
 
            rule, umfch {k}, umfch {k}, kind, obj, umfdir) ;
 
193
        [M, kk] = make (M, '%s -c %sumf_%s.c', 'umf_%s.%s', 'umf_%s_%s.%s', ...
 
194
            rule, umfch {k}, umfch {k}, kind, obj, umfdir, kk, details) ;
208
195
    end
209
196
 
210
 
    M = make (M, '%s -DWSOLVE -c %sumfpack_%s.c', 'umfpack_%s.%s', ...
211
 
        'umfpack_%s_w%s.%s', rule, 'solve', 'solve', kind, obj, umfdir) ;
 
197
    [M, kk] = make (M, '%s -DWSOLVE -c %sumfpack_%s.c', 'umfpack_%s.%s', ...
 
198
        'umfpack_%s_w%s.%s', rule, 'solve', 'solve', kind, obj, umfdir, ...
 
199
        kk, details) ;
212
200
 
213
201
    for k = 1:length(user)
214
 
        M = make (M, '%s -c %sumfpack_%s.c', 'umfpack_%s.%s', ...
215
 
            'umfpack_%s_%s.%s', rule, user {k}, user {k}, kind, obj, umfdir) ;
 
202
        [M, kk] = make (M, '%s -c %sumfpack_%s.c', 'umfpack_%s.%s', ...
 
203
            'umfpack_%s_%s.%s', rule, user {k}, user {k}, kind, obj, ...
 
204
            umfdir, kk, details) ;
216
205
    end
217
206
end
218
207
 
219
208
for k = 1:length(generic)
220
 
    M = make (M, '%s -c %sumfpack_%s.c', 'umfpack_%s.%s', ...
221
 
        'umfpack_%s_%s.%s', mx, generic {k}, generic {k}, 'm', obj, umfdir) ;
 
209
    [M, kk] = make (M, '%s -c %sumfpack_%s.c', 'umfpack_%s.%s', ...
 
210
        'umfpack_%s_%s.%s', mx, generic {k}, generic {k}, 'm', obj, ...
 
211
        umfdir, kk, details) ;
222
212
end
223
213
 
224
214
%----------------------------------------
225
215
% AMD routines (int only)
226
216
%----------------------------------------
227
217
 
228
 
for k = 1:length(amd)
229
 
    M = make (M, '%s -DDINT -c %samd_%s.c', 'amd_%s.%s', 'amd_%s_%s.%s', ...
230
 
        mx, amd {k}, amd {k}, 'm', obj, amddir) ;
 
218
for k = 1:length(amdsrc)
 
219
    [M, kk] = make (M, '%s -DDLONG -c %samd_%s.c', 'amd_%s.%s', ...
 
220
        'amd_%s_%s.%s', mx, amdsrc {k}, amdsrc {k}, 'm', obj, amddir, ...
 
221
        kk, details) ;
231
222
end
232
223
 
233
224
%----------------------------------------
234
 
% compile the umfpack mexFunction
 
225
% compile the umfpack2 mexFunction
235
226
%----------------------------------------
236
227
 
237
 
C = sprintf ('%s -output umfpack umfpackmex.c', mx) ;
 
228
C = sprintf ('%s -output umfpack2 umfpackmex.c', mx) ;
238
229
for i = 1:length (M)
239
 
    C = [C ' ' (M {i})] ;
 
230
    C = [C ' ' (M {i})] ;   %#ok
240
231
end
241
 
C = [C ' ' blas_lib] ;
242
 
cmd (C) ;
 
232
C = [C ' ' lapack] ;
 
233
kk = cmd (C, kk, details) ;
243
234
 
244
235
%----------------------------------------
245
236
% delete the object files
253
244
% compile the luflop mexFunction
254
245
%----------------------------------------
255
246
 
256
 
cmd (sprintf ('%s -output luflop luflopmex.c', mx)) ;
257
 
 
258
 
%----------------------------------------
259
 
% compile the AMD mexFunction
260
 
%----------------------------------------
261
 
 
262
 
fprintf ('\n') ;
263
 
umfpack_path = pwd ;
264
 
cd ../../AMD/MATLAB
265
 
amd_make ;
266
 
amd_path = pwd ;
267
 
addpath (umfpack_path) ;
268
 
addpath (amd_path) ;
269
 
cd (umfpack_path)
270
 
 
271
 
fprintf ('\n\nCompilation has completed.  Now trying the umfpack_simple demo.\n');
272
 
umfpack_simple
273
 
 
274
 
 
275
 
fprintf ('Added the following directories to the path.  You may wish to add\n');
276
 
fprintf ('these permanently with the MATLAB pathtool command:\n') ;
277
 
fprintf ('%s\n', umfpack_path) ;
278
 
fprintf ('%s\n', amd_path) ;
 
247
cmd (sprintf ('%s -output luflop luflopmex.c', mx), kk, details) ;
 
248
 
 
249
fprintf ('\nUMFPACK successfully compiled\n') ;
279
250
 
280
251
%===============================================================================
281
252
% end of umfpack_make
283
254
 
284
255
 
285
256
%-------------------------------------------------------------------------------
 
257
 
 
258
function rmfile (file)
286
259
% rmfile:  delete a file, but only if it exists
287
 
%-------------------------------------------------------------------------------
288
 
 
289
 
function rmfile (file)
290
 
if (length (dir (file)) > 0)
 
260
if (length (dir (file)) > 0)                                                %#ok
291
261
    delete (file) ;
292
262
end
293
263
 
294
264
%-------------------------------------------------------------------------------
 
265
 
 
266
function cpfile (src, dst)
295
267
% cpfile:  copy the src file to the filename dst, overwriting dst if it exists
296
 
%-------------------------------------------------------------------------------
297
 
 
298
 
function cpfile (src, dst)
299
268
rmfile (dst)
300
 
if (length (dir (src)) == 0)
301
 
    help umfpack_make
302
 
    error (sprintf ('File does not exist: %s\n', src)) ;
 
269
if (length (dir (src)) == 0)    %#ok
 
270
    fprintf ('File does not exist: %s\n', src) ;
 
271
    error ('File does not exist') ;
303
272
end
304
273
copyfile (src, dst) ;
305
274
 
306
275
%-------------------------------------------------------------------------------
 
276
 
 
277
function mvfile (src, dst)
307
278
% mvfile:  move the src file to the filename dst, overwriting dst if it exists
308
 
%-------------------------------------------------------------------------------
309
 
 
310
 
function mvfile (src, dst)
311
279
cpfile (src, dst) ;
312
280
rmfile (src) ;
313
281
 
314
282
%-------------------------------------------------------------------------------
315
 
% cmd:  display and execute a command
316
 
%-------------------------------------------------------------------------------
317
283
 
318
 
function cmd (s)
319
 
fprintf ('.') ;
 
284
function kk = cmd (s, kk, details)
 
285
%CMD: evaluate a command, and either print it or print a "."
 
286
if (details)
 
287
    fprintf ('%s\n', s) ;
 
288
else
 
289
    if (mod (kk, 60) == 0)
 
290
        fprintf ('\n') ;
 
291
    end
 
292
    kk = kk + 1 ;
 
293
    fprintf ('.') ;
 
294
end
320
295
eval (s) ;
321
296
 
322
297
%-------------------------------------------------------------------------------
 
298
 
 
299
function [M, kk] = make (M, s, src, dst, rule, file1, file2, kind, obj, ...
 
300
    srcdir, kk, details)
323
301
% make:  execute a "make" command for a source file
324
 
%-------------------------------------------------------------------------------
325
 
 
326
 
function M = make (M, s, src, dst, rule, file1, file2, kind, obj, srcdir)
327
 
cmd (sprintf (s, rule, srcdir, file1)) ;
 
302
kk = cmd (sprintf (s, rule, srcdir, file1), kk, details) ;
328
303
src = sprintf (src, file1, obj) ;
329
304
dst = sprintf (dst, kind, file2, obj) ;
330
305
mvfile (src, dst) ;
331
306
M {end + 1} = dst ;
332
307
 
 
308
 
 
309
%-------------------------------------------------------------------------------
 
310
function [v,pc] = getversion
 
311
% determine the MATLAB version, and return it as a double.
 
312
% only the primary and secondary version numbers are kept.
 
313
% MATLAB 7.0.4 becomes 7.0, version 6.5.2 becomes 6.5, etc.
 
314
v = version ;
 
315
t = find (v == '.') ;
 
316
if (length (t) > 1)
 
317
    v = v (1:(t(2)-1)) ;
 
318
end
 
319
v = str2double (v) ;
 
320
try
 
321
    % ispc does not appear in MATLAB 5.3
 
322
    pc = ispc ;
 
323
catch
 
324
    % if ispc fails, assume we are on a Windows PC if it's not unix
 
325
    pc = ~isunix ;
 
326
end