Mercurial > octave-nkf
comparison liboctave/UMFPACK/UMFPACK/OCTAVE/umfpack_make.m @ 5164:57077d0ddc8e
[project @ 2005-02-25 19:55:24 by jwe]
author | jwe |
---|---|
date | Fri, 25 Feb 2005 19:55:28 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5163:9f3299378193 | 5164:57077d0ddc8e |
---|---|
1 function umfpack_make | |
2 % UMFPACK_MAKE | |
3 % | |
4 % Compiles the UMFPACK mexFunction and then runs a simple demo. | |
5 % | |
6 % UMFPACK Version 4.3 (Jan. 16, 2004), Copyright (c) 2004 by Timothy A. | |
7 % Davis. All Rights Reserved. Type umfpack_details for License. | |
8 % | |
9 % See also: umfpack, umfpack_details, umfpack_report, umfpack_demo, and | |
10 % umfpack_simple. | |
11 | |
12 help umfpack_make | |
13 | |
14 fprintf ('\n--------------------------------------------------------------\n') ; | |
15 fprintf ('Now compiling the UMFPACK and AMD mexFunctions.\n') ; | |
16 fprintf ('--------------------------------------------------------------\n') ; | |
17 | |
18 try | |
19 % ispc does not appear in MATLAB 5.3 | |
20 pc = ispc ; | |
21 catch | |
22 % if ispc fails, assume we aren't on a Windows PC. | |
23 pc = 0 ; | |
24 end | |
25 | |
26 obj = 'o' ; | |
27 blas_lib = '' ; | |
28 if (pc) | |
29 obj = 'obj' ; | |
30 end | |
31 | |
32 %------------------------------------------------------------------------------- | |
33 % BLAS option | |
34 %------------------------------------------------------------------------------- | |
35 | |
36 msg = [ ... | |
37 '\nUsing the BLAS is faster, but might not compile correctly.\n', ... | |
38 'If you get an error stating that dgemm, dgemv, dger, zgemm,\n', ... | |
39 'zgemv, and/or zger are not defined, then recompile without the\n', ... | |
40 'BLAS. You can ignore warnings that these routines are implicitly\n', ... | |
41 'declared.\n\nPlease select one of the following options: \n', ... | |
42 ' 1: attempt to compile with the BLAS (default)\n', ... | |
43 ' 2: do not use the BLAS\n'] ; | |
44 fprintf (msg) ; | |
45 blas = input (': ') ; | |
46 if (isempty (blas)) | |
47 blas = 1 ; | |
48 end | |
49 if (blas == 1) | |
50 % try to link to MATLAB's built-in BLAS | |
51 blas = '' ; | |
52 if (pc) | |
53 % the default lcc compiler needs this library to access the BLAS | |
54 blas_lib = ' libmwlapack.lib' ; | |
55 msg = [ ... | |
56 '\nCheck to see if you have a file called libmwlapack.lib in the\n', ... | |
57 '<matlab>\\extern\\lib\\win32\\lcc\\ directory, where <matlab> is ', ... | |
58 'the\ndirectory where MATLAB is installed. If a file of that ', ... | |
59 'name is already\nthere, then you don''t have to do anything. ', ... | |
60 'Otherwise, you must first\ncopy the libmwlapack.lib file from ', ... | |
61 'the umfpack\\lcc_lib\\ directory to the\n', ... | |
62 '<matlab>\\extern\\lib\\win32\\lcc\\ directory. Next, type\n\n', ... | |
63 ' mex -setup\n\n', ... | |
64 'at the MATLAB prompt, and ask MATLAB to select the lcc compiler. ',... | |
65 'You can skip\nall of this if you have already done it, or have ', ... | |
66 'configured mex to use\na different compiler. If you are using ', ... | |
67 'Norton anti-virus software on Windows\n98SE, then you need to ', ... | |
68 'exit MATLAB, turn off virus checking, and restart MATLAB\n', ... | |
69 'before you can use the mex command or compile UMFPACK.\n', ... | |
70 'You may also need to turn off virus checking in other cases.\n', ... | |
71 '\nHit enter to continue, or type control-C if you do not wish to '] ; | |
72 fprintf (msg) ; | |
73 input ('proceed: ') ; | |
74 end | |
75 fprintf ('\nUsing the BLAS (recommended).\n') ; | |
76 else | |
77 % No BLAS | |
78 fprintf ('\nNot using the BLAS. UMFPACK will be slow.\n') ; | |
79 blas = ' -DNBLAS' ; | |
80 end | |
81 | |
82 %------------------------------------------------------------------------------- | |
83 % -DNUTIL option (using utMalloc or mxMalloc) | |
84 %------------------------------------------------------------------------------- | |
85 | |
86 utils = '' ; | |
87 | |
88 if (~pc) | |
89 msg = [ ... | |
90 '--------------------------------------------------------------\n', ... | |
91 '\nUMFPACK uses MATLAB''s memory allocation routines. The internal', ... | |
92 '\nutMalloc, utFree, and utRealloc allow for better use of memory,', ... | |
93 '\nbut they are internal utility routines that are not documented.\n', ... | |
94 'Thus, they might not always work. Using mxMalloc, mxFree, and\n', ... | |
95 'mxRealloc works, but UMFPACK might run out of memory when solving\n', ... | |
96 'problems that it could otherwise solve. Try using the default.\n', ... | |
97 'If you get an error stating that utMalloc, utFree, and/or\n', ... | |
98 'utRealloc are not defined, then recompile with the mx* routines.\n', ... | |
99 '\nPlease select one of the following options:\n', ... | |
100 ' 1: attempt to use the ut* routines (default)\n', ... | |
101 ' 2: use the standard mx* routines\n'] ; | |
102 fprintf (msg) ; | |
103 utils = input (': ') ; | |
104 if (isempty (utils)) | |
105 utils = 1 ; | |
106 end | |
107 if (utils == 2) | |
108 fprintf ('\nNot using utMalloc, utFree, or utRealloc\n') ; | |
109 utils = ' -DNUTIL' ; | |
110 else | |
111 fprintf ('\nUsing utMalloc, utFree, and utRealloc\n') ; | |
112 utils = '' ; | |
113 end | |
114 end | |
115 | |
116 %------------------------------------------------------------------------------- | |
117 % -DNPOSIX option (for sysconf and times timer routines) | |
118 %------------------------------------------------------------------------------- | |
119 | |
120 posix = '' ; | |
121 | |
122 if (~pc) | |
123 msg = [ ... | |
124 '--------------------------------------------------------------\n', ... | |
125 '\nUMFPACK can use the POSIX routines sysconf () and times ()\n', ... | |
126 'to provide CPU time and wallclock time statistics. If you do not\n', ... | |
127 'have a POSIX-compliant operating system, then UMFPACK won''t\n', ... | |
128 'compile. If you don''t know which option to pick, try the\n', ... | |
129 'default. If you get an error saying that sysconf and/or times\n', ... | |
130 'are not defined, then recompile with the non-POSIX option.\n', ... | |
131 '\nPlease select one of the following options:\n', ... | |
132 ' 1: use POSIX sysconf and times routines (default)\n', ... | |
133 ' 2: do not use POSIX routines\n'] ; | |
134 fprintf (msg) ; | |
135 posix = input (': ') ; | |
136 if (isempty (posix)) | |
137 posix = 1 ; | |
138 end | |
139 if (posix == 2) | |
140 fprintf ('\nNot using POSIX sysconf and times routines.\n') ; | |
141 posix = ' -DNPOSIX' ; | |
142 else | |
143 fprintf ('\nUsing POSIX sysconf and times routines.\n') ; | |
144 posix = '' ; | |
145 end | |
146 end | |
147 | |
148 %------------------------------------------------------------------------------- | |
149 % mex command | |
150 %------------------------------------------------------------------------------- | |
151 | |
152 umfdir = sprintf ('..%sSource%s', filesep, filesep) ; | |
153 amddir = sprintf ('..%s..%sAMD%sSource%s', filesep, filesep, filesep, filesep) ; | |
154 incdir = sprintf ( ... | |
155 ' -I..%sInclude -I..%sSource -I..%s..%sAMD%sInclude -I..%s..%sAMD%sSource', ... | |
156 filesep,filesep, filesep, filesep, filesep, filesep, filesep, filesep) ; | |
157 | |
158 mx = sprintf ('mex -inline -O%s%s%s%s', blas, utils, posix, incdir) ; | |
159 msg = [ ... | |
160 '--------------------------------------------------------------\n', ... | |
161 '\nCompile options:\n%s\nNow compiling. Please wait.\n'] ; | |
162 fprintf (msg, mx) ; | |
163 | |
164 % The following is adapted from GNUmakefile | |
165 | |
166 %------------------------------------------------------------------------------- | |
167 % source files | |
168 %------------------------------------------------------------------------------- | |
169 | |
170 % non-user-callable umf_*.[ch] files: | |
171 umfch = { 'assemble', 'blas3_update', ... | |
172 'build_tuples', 'create_element', ... | |
173 'dump', 'extend_front', 'garbage_collection', ... | |
174 'get_memory', 'init_front', 'kernel', ... | |
175 'kernel_init', 'kernel_wrapup', ... | |
176 'local_search', 'lsolve', 'ltsolve', ... | |
177 'mem_alloc_element', 'mem_alloc_head_block', ... | |
178 'mem_alloc_tail_block', 'mem_free_tail_block', ... | |
179 'mem_init_memoryspace', ... | |
180 'report_vector', 'row_search', 'scale_column', ... | |
181 'set_stats', 'solve', 'symbolic_usage', 'transpose', ... | |
182 'tuple_lengths', 'usolve', 'utsolve', 'valid_numeric', ... | |
183 'valid_symbolic', 'grow_front', 'start_front', '2by2', ... | |
184 'store_lu', 'scale' } ; | |
185 | |
186 % non-user-callable umf_*.[ch] files, int versions only (no real/complex): | |
187 umfint = { 'analyze', 'apply_order', 'colamd', 'free', 'fsize', ... | |
188 'is_permutation', 'malloc', 'realloc', 'report_perm', ... | |
189 'singletons' } ; | |
190 | |
191 % non-user-callable and user-callable amd_*.[ch] files (int versions only): | |
192 amd = { 'aat', '1', '2', 'dump', 'postorder', 'post_tree', 'defaults', ... | |
193 'order', 'control', 'info', 'valid' } ; | |
194 | |
195 % user-callable umfpack_*.[ch] files (real/complex): | |
196 user = { 'col_to_triplet', 'defaults', 'free_numeric', ... | |
197 'free_symbolic', 'get_numeric', 'get_lunz', ... | |
198 'get_symbolic', 'numeric', 'qsymbolic', ... | |
199 'report_control', 'report_info', 'report_matrix', ... | |
200 'report_numeric', 'report_perm', 'report_status', ... | |
201 'report_symbolic', 'report_triplet', ... | |
202 'report_vector', 'solve', 'symbolic', ... | |
203 'transpose', 'triplet_to_col', 'scale' ... | |
204 'load_numeric', 'save_numeric', 'load_symbolic', 'save_symbolic' } ; | |
205 | |
206 % user-callable umfpack_*.[ch], only one version | |
207 generic = { 'timer', 'tictoc' } ; | |
208 | |
209 M = cell (0) ; | |
210 | |
211 %------------------------------------------------------------------------------- | |
212 % Create the umfpack and amd mexFunctions for MATLAB (int versions only) | |
213 %------------------------------------------------------------------------------- | |
214 | |
215 for k = 1:length(umfint) | |
216 M = make (M, '%s -DDINT -c %sumf_%s.c', 'umf_%s.%s', 'umf_%s_%s.%s', ... | |
217 mx, umfint {k}, umfint {k}, 'm', obj, umfdir) ; | |
218 end | |
219 | |
220 rules = { [mx ' -DDINT'] , [mx ' -DZINT'] } ; | |
221 kinds = { 'md', 'mz' } ; | |
222 | |
223 for what = 1:2 | |
224 | |
225 rule = rules {what} ; | |
226 kind = kinds {what} ; | |
227 | |
228 M = make (M, '%s -DCONJUGATE_SOLVE -c %sumf_%s.c', 'umf_%s.%s', ... | |
229 'umf_%s_%s.%s', rule, 'ltsolve', 'lhsolve', kind, obj, umfdir) ; | |
230 | |
231 M = make (M, '%s -DCONJUGATE_SOLVE -c %sumf_%s.c', 'umf_%s.%s', ... | |
232 'umf_%s_%s.%s', rule, 'utsolve', 'uhsolve', kind, obj, umfdir) ; | |
233 | |
234 M = make (M, '%s -DDO_MAP -c %sumf_%s.c', 'umf_%s.%s', ... | |
235 'umf_%s_%s_map_nox.%s', rule, 'triplet', 'triplet', kind, obj, umfdir) ; | |
236 | |
237 M = make (M, '%s -DDO_VALUES -c %sumf_%s.c', 'umf_%s.%s', ... | |
238 'umf_%s_%s_nomap_x.%s', rule, 'triplet', 'triplet', kind, obj, umfdir) ; | |
239 | |
240 M = make (M, '%s -c %sumf_%s.c', 'umf_%s.%s', ... | |
241 'umf_%s_%s_nomap_nox.%s', rule, 'triplet', 'triplet', kind, obj, ... | |
242 umfdir) ; | |
243 | |
244 M = make (M, '%s -DDO_MAP -DDO_VALUES -c %sumf_%s.c', 'umf_%s.%s', ... | |
245 'umf_%s_%s_map_x.%s', rule, 'triplet', 'triplet', kind, obj, umfdir) ; | |
246 | |
247 M = make (M, '%s -DFIXQ -c %sumf_%s.c', 'umf_%s.%s', ... | |
248 'umf_%s_%s_fixq.%s', rule, 'assemble', 'assemble', kind, obj, umfdir) ; | |
249 | |
250 M = make (M, '%s -DDROP -c %sumf_%s.c', 'umf_%s.%s', ... | |
251 'umf_%s_%s_drop.%s', rule, 'store_lu', 'store_lu', kind, obj, umfdir) ; | |
252 | |
253 for k = 1:length(umfch) | |
254 M = make (M, '%s -c %sumf_%s.c', 'umf_%s.%s', 'umf_%s_%s.%s', ... | |
255 rule, umfch {k}, umfch {k}, kind, obj, umfdir) ; | |
256 end | |
257 | |
258 M = make (M, '%s -DWSOLVE -c %sumfpack_%s.c', 'umfpack_%s.%s', ... | |
259 'umfpack_%s_w%s.%s', rule, 'solve', 'solve', kind, obj, umfdir) ; | |
260 | |
261 for k = 1:length(user) | |
262 M = make (M, '%s -c %sumfpack_%s.c', 'umfpack_%s.%s', ... | |
263 'umfpack_%s_%s.%s', rule, user {k}, user {k}, kind, obj, umfdir) ; | |
264 end | |
265 end | |
266 | |
267 for k = 1:length(generic) | |
268 M = make (M, '%s -c %sumfpack_%s.c', 'umfpack_%s.%s', ... | |
269 'umfpack_%s_%s.%s', mx, generic {k}, generic {k}, 'm', obj, umfdir) ; | |
270 end | |
271 | |
272 %---------------------------------------- | |
273 % AMD routines (int only) | |
274 %---------------------------------------- | |
275 | |
276 for k = 1:length(amd) | |
277 M = make (M, '%s -DDINT -c %samd_%s.c', 'amd_%s.%s', 'amd_%s_%s.%s', ... | |
278 mx, amd {k}, amd {k}, 'm', obj, amddir) ; | |
279 end | |
280 | |
281 %---------------------------------------- | |
282 % compile the umfpack mexFunction | |
283 %---------------------------------------- | |
284 | |
285 C = sprintf ('%s -output umfpack umfpackmex.c', mx) ; | |
286 for i = 1:length (M) | |
287 C = [C ' ' (M {i})] ; | |
288 end | |
289 C = [C ' ' blas_lib] ; | |
290 cmd (C) ; | |
291 | |
292 %---------------------------------------- | |
293 % delete the object files | |
294 %---------------------------------------- | |
295 | |
296 for i = 1:length (M) | |
297 rmfile (M {i}) ; | |
298 end | |
299 | |
300 %---------------------------------------- | |
301 % compile the luflop mexFunction | |
302 %---------------------------------------- | |
303 | |
304 cmd (sprintf ('%s -output luflop luflopmex.c', mx)) ; | |
305 | |
306 fprintf ('\n\nCompilation has completed. Now trying the umfpack_simple demo.\n'); | |
307 umfpack_simple | |
308 | |
309 %------------------------------------------------------------------------------- | |
310 % rmfile: delete a file, but only if it exists | |
311 %------------------------------------------------------------------------------- | |
312 | |
313 function rmfile (file) | |
314 if (length (dir (file)) > 0) | |
315 delete (file) ; | |
316 end | |
317 | |
318 %------------------------------------------------------------------------------- | |
319 % cpfile: copy the src file to the filename dst, overwriting dst if it exists | |
320 %------------------------------------------------------------------------------- | |
321 | |
322 function cpfile (src, dst) | |
323 rmfile (dst) | |
324 if (length (dir (src)) == 0) | |
325 help umfpack_make | |
326 error (sprintf ('File does not exist: %s\n', src)) ; | |
327 end | |
328 copyfile (src, dst) ; | |
329 | |
330 %------------------------------------------------------------------------------- | |
331 % mvfile: move the src file to the filename dst, overwriting dst if it exists | |
332 %------------------------------------------------------------------------------- | |
333 | |
334 function mvfile (src, dst) | |
335 cpfile (src, dst) ; | |
336 rmfile (src) ; | |
337 | |
338 %------------------------------------------------------------------------------- | |
339 % cmd: display and execute a command | |
340 %------------------------------------------------------------------------------- | |
341 | |
342 function cmd (s) | |
343 fprintf ('.') ; | |
344 eval (s) ; | |
345 | |
346 %------------------------------------------------------------------------------- | |
347 % make: execute a "make" command for a source file | |
348 %------------------------------------------------------------------------------- | |
349 | |
350 function M = make (M, s, src, dst, rule, file1, file2, kind, obj, srcdir) | |
351 cmd (sprintf (s, rule, srcdir, file1)) ; | |
352 src = sprintf (src, file1, obj) ; | |
353 dst = sprintf (dst, kind, file2, obj) ; | |
354 mvfile (src, dst) ; | |
355 M {end + 1} = dst ; | |
356 |