Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/umfpack/demo/umf4_f77wrapper.c
3196 views
1
/* ========================================================================== */
2
/* === umf4_f77wrapper ====================================================== */
3
/* ========================================================================== */
4
5
/* -------------------------------------------------------------------------- */
6
/* UMFPACK Version 4.4, Copyright (c) 2005 by Timothy A. Davis. CISE Dept, */
7
/* Univ. of Florida. All Rights Reserved. See ../Doc/License for License. */
8
/* web: http://www.cise.ufl.edu/research/sparse/umfpack */
9
/* -------------------------------------------------------------------------- */
10
11
/* FORTRAN interface for the C-callable UMFPACK library (double / int version
12
* only and double / long versions only). This is HIGHLY non-portable. You
13
* will need to modify this depending on how your FORTRAN and C compilers
14
* behave. This has been tested in Linux, Sun Solaris, SGI IRIX, and IBM AIX,
15
* with various compilers. It has not been exhaustively tested on all possible
16
* combinations of C and FORTRAN compilers. The long version works on
17
* Solaris, SGI IRIX, and IBM AIX when the UMFPACK library is compiled in
18
* 64-bit mode.
19
*
20
* Only a subset of UMFPACK's capabilities are provided. Refer to the UMFPACK
21
* User Guide for details.
22
*
23
* For some C and FORTRAN compilers, the FORTRAN compiler appends a single
24
* underscore ("_") after each routine name. C doesn't do this, so the
25
* translation is made here. Other FORTRAN compilers treat underscores
26
* differently. For example, a FORTRAN call to a_b gets translated to a call
27
* to a_b__ by g77, and to a_b_ by most other FORTRAN compilers. Thus, the
28
* FORTRAN names here do not use underscores. The xlf compiler in IBM AIX
29
* doesn't add an underscore.
30
*
31
* The matrix A is passed to UMFPACK in compressed column form, with 0-based
32
* indices. In FORTRAN, for an m-by-n matrix A with nz entries, the row
33
* indices of the first column (column 1) are in Ai (Ap (1) + 1 ... Ap (2)),
34
* with values in Ax (Ap (1) + 1 ... Ap (2)). The last column (column n) is
35
* in Ai (Ap (n) + 1 ... Ap (n+1)) and Ax (Ap (n) + 1 ... Ap (n+1)). The row
36
* indices in Ai are in the range 0 to m-1. They must be sorted, with no
37
* duplicate entries allowed. Refer to umfpack_di_triplet_to_col for a more
38
* flexible format for the input matrix. The following defintions apply
39
* for each of the routines in this file:
40
*
41
* integer m, n, Ap (n+1), Ai (nz), symbolic, numeric, filenum, status
42
* double precision Ax (nz), control (20), info (90), x (n), b (n)
43
*
44
* UMFPACK's status is returned in either a status argument, or in info (1).
45
* It is zero if everything is OK, 1 if the matrix is singular (this is a
46
* warning, not an error), and negative if an error occurred. See umfpack.h
47
* for more details on the contents of the control and info arrays, and the
48
* value of the sys argument.
49
*
50
* For the Numeric and Symbolic handles, it's probably safe to assume that a
51
* FORTRAN integer is sufficient to store a C pointer. If that doesn't work,
52
* try defining numeric and symbolic as integer arrays of size 2, or as
53
* integer*8, in the FORTRAN routine that calls these wrapper routines.
54
* The latter is required on Solaris, SGI IRIX, and IBM AIX when UMFPACK is
55
* compiled in 64-bit mode.
56
*
57
* If you want to use 64-bit integers, try compiling this file with the -DDLONG
58
* compiler option (via "make fortran64"). First modify your Make/Make.include
59
* and Make/Make.<arch> files to compile UMFPACK in LP64 mode (see the User
60
* Guide for details). Your FORTRAN code should use integer*8. See umf4hb64.f
61
* for an example.
62
*
63
* Tested with the following compilers:
64
* * Solaris with cc and f77 from Sun WorkShop 6 update 1
65
* (32-bit and 64-bit modes)
66
* * SGI Irix with MIPSpro cc and f77 compilers version 7.4
67
* (32-bit and 64-bit modes)
68
* * Linux with GNU gcc and Intel's icc, and GNU g77 and Intel's
69
* ifc FORTRAN compiler. See the comments above about g77 and
70
* underscores. Only supports 32-bit mode.
71
* * IBM AIX xlc and xlf compilers.
72
* (32-bit and 64-bit modes)
73
*/
74
75
#include "umfpack.h"
76
#include <ctype.h>
77
#include <stdio.h>
78
#ifdef NULL
79
#undef NULL
80
#endif
81
#define NULL 0
82
#define LEN 200
83
84
/* -------------------------------------------------------------------------- */
85
/* integer type: int or long */
86
/* -------------------------------------------------------------------------- */
87
88
#if defined (DLONG)
89
90
#define Int long
91
#define UMFPACK_defaults umfpack_dl_defaults
92
#define UMFPACK_free_numeric umfpack_dl_free_numeric
93
#define UMFPACK_free_symbolic umfpack_dl_free_symbolic
94
#define UMFPACK_numeric umfpack_dl_numeric
95
#define UMFPACK_report_control umfpack_dl_report_control
96
#define UMFPACK_report_info umfpack_dl_report_info
97
#define UMFPACK_save_numeric umfpack_dl_save_numeric
98
#define UMFPACK_save_symbolic umfpack_dl_save_symbolic
99
#define UMFPACK_load_numeric umfpack_dl_load_numeric
100
#define UMFPACK_load_symbolic umfpack_dl_load_symbolic
101
#define UMFPACK_scale umfpack_dl_scale
102
#define UMFPACK_solve umfpack_dl_solve
103
#define UMFPACK_symbolic umfpack_dl_symbolic
104
105
#else
106
107
#define Int int
108
#define UMFPACK_defaults umfpack_di_defaults
109
#define UMFPACK_free_numeric umfpack_di_free_numeric
110
#define UMFPACK_free_symbolic umfpack_di_free_symbolic
111
#define UMFPACK_numeric umfpack_di_numeric
112
#define UMFPACK_report_control umfpack_di_report_control
113
#define UMFPACK_report_info umfpack_di_report_info
114
#define UMFPACK_save_numeric umfpack_di_save_numeric
115
#define UMFPACK_save_symbolic umfpack_di_save_symbolic
116
#define UMFPACK_load_numeric umfpack_di_load_numeric
117
#define UMFPACK_load_symbolic umfpack_di_load_symbolic
118
#define UMFPACK_scale umfpack_di_scale
119
#define UMFPACK_solve umfpack_di_solve
120
#define UMFPACK_symbolic umfpack_di_symbolic
121
122
#endif
123
124
/* -------------------------------------------------------------------------- */
125
/* construct a file name from a file number (not user-callable) */
126
/* -------------------------------------------------------------------------- */
127
128
static void make_filename (Int filenum, char *prefix, char *filename)
129
{
130
char *psrc, *pdst ;
131
#ifdef DLONG
132
sprintf (filename, "%s%ld.umf", prefix, filenum) ;
133
#else
134
sprintf (filename, "%s%d.umf", prefix, filenum) ;
135
#endif
136
/* remove any spaces in the filename */
137
pdst = filename ;
138
for (psrc = filename ; *psrc ; psrc++)
139
{
140
if (!isspace (*psrc)) *pdst++ = *psrc ;
141
}
142
*pdst = '\0' ;
143
}
144
145
/* ========================================================================== */
146
/* === with underscore ====================================================== */
147
/* ========================================================================== */
148
149
/* Solaris, Linux, and SGI IRIX. Probably Compaq Alpha as well. */
150
151
/* -------------------------------------------------------------------------- */
152
/* umf4def: set default control parameters */
153
/* -------------------------------------------------------------------------- */
154
155
/* call umf4def (control) */
156
157
void umf4def_ (double Control [UMFPACK_CONTROL])
158
{
159
UMFPACK_defaults (Control) ;
160
}
161
162
/* -------------------------------------------------------------------------- */
163
/* umf4pcon: print control parameters */
164
/* -------------------------------------------------------------------------- */
165
166
/* call umf4pcon (control) */
167
168
void umf4pcon_ (double Control [UMFPACK_CONTROL])
169
{
170
fflush (stdout) ;
171
UMFPACK_report_control (Control) ;
172
fflush (stdout) ;
173
}
174
175
/* -------------------------------------------------------------------------- */
176
/* umf4sym: pre-ordering and symbolic factorization */
177
/* -------------------------------------------------------------------------- */
178
179
/* call umf4sym (m, n, Ap, Ai, Ax, symbolic, control, info) */
180
181
void umf4sym_ (Int *m, Int *n, Int Ap [ ], Int Ai [ ],
182
double Ax [ ], void **Symbolic,
183
double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO])
184
{
185
(void) UMFPACK_symbolic (*m, *n, Ap, Ai, Ax, Symbolic, Control, Info) ;
186
}
187
188
/* -------------------------------------------------------------------------- */
189
/* umf4num: numeric factorization */
190
/* -------------------------------------------------------------------------- */
191
192
/* call umf4num (Ap, Ai, Ax, symbolic, numeric, control, info) */
193
194
void umf4num_ (Int Ap [ ], Int Ai [ ], double Ax [ ],
195
void **Symbolic, void **Numeric,
196
double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO])
197
{
198
(void) UMFPACK_numeric (Ap, Ai, Ax, *Symbolic, Numeric, Control, Info);
199
}
200
201
/* -------------------------------------------------------------------------- */
202
/* umf4solr: solve a linear system with iterative refinement */
203
/* -------------------------------------------------------------------------- */
204
205
/* call umf4solr (sys, Ap, Ai, Ax, x, b, numeric, control, info) */
206
207
void umf4solr_ (Int *sys, Int Ap [ ], Int Ai [ ], double Ax [ ],
208
double x [ ], double b [ ], void **Numeric,
209
double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO])
210
{
211
(void) UMFPACK_solve (*sys, Ap, Ai, Ax, x, b, *Numeric, Control, Info) ;
212
}
213
214
/* -------------------------------------------------------------------------- */
215
/* umf4sol: solve a linear system without iterative refinement */
216
/* -------------------------------------------------------------------------- */
217
218
/* call umf4sol (sys, x, b, numeric, control, info) */
219
220
void umf4sol_ (Int *sys, double x [ ], double b [ ], void **Numeric,
221
double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO])
222
{
223
Control [UMFPACK_IRSTEP] = 0 ;
224
(void) UMFPACK_solve (*sys, (Int *) NULL, (Int *) NULL, (double *) NULL,
225
x, b, *Numeric, Control, Info) ;
226
}
227
228
/* -------------------------------------------------------------------------- */
229
/* umf4scal: scale a vector using UMFPACK's scale factors */
230
/* -------------------------------------------------------------------------- */
231
232
/* call umf4scal (x, b, numeric, status) */
233
234
void umf4scal_ (double x [ ], double b [ ], void **Numeric, Int *status)
235
{
236
*status = UMFPACK_scale (x, b, *Numeric) ;
237
}
238
239
/* -------------------------------------------------------------------------- */
240
/* umf4pinf: print info */
241
/* -------------------------------------------------------------------------- */
242
243
/* call umf4pinf (control) */
244
245
void umf4pinf_ (double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO])
246
{
247
fflush (stdout) ;
248
UMFPACK_report_info (Control, Info) ;
249
fflush (stdout) ;
250
}
251
252
/* -------------------------------------------------------------------------- */
253
/* umf4fnum: free the Numeric object */
254
/* -------------------------------------------------------------------------- */
255
256
/* call umf4fnum (numeric) */
257
258
void umf4fnum_ (void **Numeric)
259
{
260
UMFPACK_free_numeric (Numeric) ;
261
}
262
263
/* -------------------------------------------------------------------------- */
264
/* umf4fsym: free the Symbolic object */
265
/* -------------------------------------------------------------------------- */
266
267
/* call umf4fsym (symbolic) */
268
269
void umf4fsym_ (void **Symbolic)
270
{
271
UMFPACK_free_symbolic (Symbolic) ;
272
}
273
274
/* -------------------------------------------------------------------------- */
275
/* umf4snum: save the Numeric object to a file */
276
/* -------------------------------------------------------------------------- */
277
278
/* call umf4snum (numeric, filenum, status) */
279
280
void umf4snum_ (void **Numeric, Int *filenum, Int *status)
281
{
282
char filename [LEN] ;
283
make_filename (*filenum, "n", filename) ;
284
*status = UMFPACK_save_numeric (*Numeric, filename) ;
285
}
286
287
/* -------------------------------------------------------------------------- */
288
/* umf4ssym: save the Symbolic object to a file */
289
/* -------------------------------------------------------------------------- */
290
291
/* call umf4ssym (symbolic, filenum, status) */
292
293
void umf4ssym_ (void **Symbolic, Int *filenum, Int *status)
294
{
295
char filename [LEN] ;
296
make_filename (*filenum, "s", filename) ;
297
*status = UMFPACK_save_symbolic (*Symbolic, filename) ;
298
}
299
300
/* -------------------------------------------------------------------------- */
301
/* umf4lnum: load the Numeric object from a file */
302
/* -------------------------------------------------------------------------- */
303
304
/* call umf4lnum (numeric, filenum, status) */
305
306
void umf4lnum_ (void **Numeric, Int *filenum, Int *status)
307
{
308
char filename [LEN] ;
309
make_filename (*filenum, "n", filename) ;
310
*status = UMFPACK_load_numeric (Numeric, filename) ;
311
}
312
313
/* -------------------------------------------------------------------------- */
314
/* umf4lsym: load the Symbolic object from a file */
315
/* -------------------------------------------------------------------------- */
316
317
/* call umf4lsym (symbolic, filenum, status) */
318
319
void umf4lsym_ (void **Symbolic, Int *filenum, Int *status)
320
{
321
char filename [LEN] ;
322
make_filename (*filenum, "s", filename) ;
323
*status = UMFPACK_load_symbolic (Symbolic, filename) ;
324
}
325
326
/* ========================================================================== */
327
/* === with no underscore =================================================== */
328
/* ========================================================================== */
329
330
/* IBM AIX. Probably Microsoft Windows and HP Unix as well. */
331
332
/* -------------------------------------------------------------------------- */
333
/* umf4def: set default control parameters */
334
/* -------------------------------------------------------------------------- */
335
336
/* call umf4def (control) */
337
338
void umf4def (double Control [UMFPACK_CONTROL])
339
{
340
UMFPACK_defaults (Control) ;
341
}
342
343
/* -------------------------------------------------------------------------- */
344
/* umf4pcon: print control parameters */
345
/* -------------------------------------------------------------------------- */
346
347
/* call umf4pcon (control) */
348
349
void umf4pcon (double Control [UMFPACK_CONTROL])
350
{
351
fflush (stdout) ;
352
UMFPACK_report_control (Control) ;
353
fflush (stdout) ;
354
}
355
356
/* -------------------------------------------------------------------------- */
357
/* umf4sym: pre-ordering and symbolic factorization */
358
/* -------------------------------------------------------------------------- */
359
360
/* call umf4sym (m, n, Ap, Ai, Ax, symbolic, control, info) */
361
362
void umf4sym (Int *m, Int *n, Int Ap [ ], Int Ai [ ],
363
double Ax [ ], void **Symbolic,
364
double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO])
365
{
366
(void) UMFPACK_symbolic (*m, *n, Ap, Ai, Ax, Symbolic, Control, Info) ;
367
}
368
369
/* -------------------------------------------------------------------------- */
370
/* umf4num: numeric factorization */
371
/* -------------------------------------------------------------------------- */
372
373
/* call umf4num (Ap, Ai, Ax, symbolic, numeric, control, info) */
374
375
void umf4num (Int Ap [ ], Int Ai [ ], double Ax [ ],
376
void **Symbolic, void **Numeric,
377
double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO])
378
{
379
(void) UMFPACK_numeric (Ap, Ai, Ax, *Symbolic, Numeric, Control, Info);
380
}
381
382
/* -------------------------------------------------------------------------- */
383
/* umf4solr: solve a linear system with iterative refinement */
384
/* -------------------------------------------------------------------------- */
385
386
/* call umf4solr (sys, Ap, Ai, Ax, x, b, numeric, control, info) */
387
388
void umf4solr (Int *sys, Int Ap [ ], Int Ai [ ], double Ax [ ],
389
double x [ ], double b [ ], void **Numeric,
390
double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO])
391
{
392
(void) UMFPACK_solve (*sys, Ap, Ai, Ax, x, b, *Numeric, Control, Info) ;
393
}
394
395
/* -------------------------------------------------------------------------- */
396
/* umf4sol: solve a linear system without iterative refinement */
397
/* -------------------------------------------------------------------------- */
398
399
/* call umf4sol (sys, x, b, numeric, control, info) */
400
401
void umf4sol (Int *sys, double x [ ], double b [ ], void **Numeric,
402
double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO])
403
{
404
Control [UMFPACK_IRSTEP] = 0 ;
405
(void) UMFPACK_solve (*sys, (Int *) NULL, (Int *) NULL, (double *) NULL,
406
x, b, *Numeric, Control, Info) ;
407
}
408
409
/* -------------------------------------------------------------------------- */
410
/* umf4scal: scale a vector using UMFPACK's scale factors */
411
/* -------------------------------------------------------------------------- */
412
413
/* call umf4scal (x, b, numeric, status) */
414
415
void umf4scal (double x [ ], double b [ ], void **Numeric, Int *status)
416
{
417
*status = UMFPACK_scale (x, b, *Numeric) ;
418
}
419
420
/* -------------------------------------------------------------------------- */
421
/* umf4pinf: print info */
422
/* -------------------------------------------------------------------------- */
423
424
/* call umf4pinf (control) */
425
426
void umf4pinf (double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO])
427
{
428
fflush (stdout) ;
429
UMFPACK_report_info (Control, Info) ;
430
fflush (stdout) ;
431
}
432
433
/* -------------------------------------------------------------------------- */
434
/* umf4fnum: free the Numeric object */
435
/* -------------------------------------------------------------------------- */
436
437
/* call umf4fnum (numeric) */
438
439
void umf4fnum (void **Numeric)
440
{
441
UMFPACK_free_numeric (Numeric) ;
442
}
443
444
/* -------------------------------------------------------------------------- */
445
/* umf4fsym: free the Symbolic object */
446
/* -------------------------------------------------------------------------- */
447
448
/* call umf4fsym (symbolic) */
449
450
void umf4fsym (void **Symbolic)
451
{
452
UMFPACK_free_symbolic (Symbolic) ;
453
}
454
455
/* -------------------------------------------------------------------------- */
456
/* umf4snum: save the Numeric object to a file */
457
/* -------------------------------------------------------------------------- */
458
459
/* call umf4snum (numeric, filenum, status) */
460
461
void umf4snum (void **Numeric, Int *filenum, Int *status)
462
{
463
char filename [LEN] ;
464
make_filename (*filenum, "n", filename) ;
465
*status = UMFPACK_save_numeric (*Numeric, filename) ;
466
}
467
468
/* -------------------------------------------------------------------------- */
469
/* umf4ssym: save the Symbolic object to a file */
470
/* -------------------------------------------------------------------------- */
471
472
/* call umf4ssym (symbolic, filenum, status) */
473
474
void umf4ssym (void **Symbolic, Int *filenum, Int *status)
475
{
476
char filename [LEN] ;
477
make_filename (*filenum, "s", filename) ;
478
*status = UMFPACK_save_symbolic (*Symbolic, filename) ;
479
}
480
481
/* -------------------------------------------------------------------------- */
482
/* umf4lnum: load the Numeric object from a file */
483
/* -------------------------------------------------------------------------- */
484
485
/* call umf4lnum (numeric, filenum, status) */
486
487
void umf4lnum (void **Numeric, Int *filenum, Int *status)
488
{
489
char filename [LEN] ;
490
make_filename (*filenum, "n", filename) ;
491
*status = UMFPACK_load_numeric (Numeric, filename) ;
492
}
493
494
/* -------------------------------------------------------------------------- */
495
/* umf4lsym: load the Symbolic object from a file */
496
/* -------------------------------------------------------------------------- */
497
498
/* call umf4lsym (symbolic, filenum, status) */
499
500
void umf4lsym (void **Symbolic, Int *filenum, Int *status)
501
{
502
char filename [LEN] ;
503
make_filename (*filenum, "s", filename) ;
504
*status = UMFPACK_load_symbolic (Symbolic, filename) ;
505
}
506
507