Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
amesos_amd_l_preprocess.c
Go to the documentation of this file.
1 /* ========================================================================= */
2 /* === AMD_preprocess ====================================================== */
3 /* ========================================================================= */
4 
5 /* ------------------------------------------------------------------------- */
6 /* AMD, Copyright (c) Timothy A. Davis, */
7 /* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
8 /* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
9 /* web: http://www.cise.ufl.edu/research/sparse/amd */
10 /* ------------------------------------------------------------------------- */
11 
12 /* Sorts, removes duplicate entries, and transposes from the nonzero pattern of
13  * a column-form matrix A, to obtain the matrix R. The input matrix can have
14  * duplicate entries and/or unsorted columns (AMD_valid (n,Ap,Ai) must not be
15  * AMD_INVALID).
16  *
17  * This input condition is NOT checked. This routine is not user-callable.
18  */
19 
20 /* This file should make the long int version of AMD */
21 #define DLONG 1
22 
23 #include "amesos_amd_internal.h"
24 
25 /* ========================================================================= */
26 /* === AMD_preprocess ====================================================== */
27 /* ========================================================================= */
28 
29 /* AMD_preprocess does not check its input for errors or allocate workspace.
30  * On input, the condition (AMD_valid (n,n,Ap,Ai) != AMD_INVALID) must hold.
31  */
32 
34 (
35  Int n, /* input matrix: A is n-by-n */
36  const Int Ap [ ], /* size n+1 */
37  const Int Ai [ ], /* size nz = Ap [n] */
38 
39  /* output matrix R: */
40  Int Rp [ ], /* size n+1 */
41  Int Ri [ ], /* size nz (or less, if duplicates present) */
42 
43  Int W [ ], /* workspace of size n */
44  Int Flag [ ] /* workspace of size n */
45 )
46 {
47 
48  /* --------------------------------------------------------------------- */
49  /* local variables */
50  /* --------------------------------------------------------------------- */
51 
52  Int i, j, p, p2 ;
53 
54  ASSERT (AMD_valid (n, n, Ap, Ai) != AMD_INVALID) ;
55 
56  /* --------------------------------------------------------------------- */
57  /* count the entries in each row of A (excluding duplicates) */
58  /* --------------------------------------------------------------------- */
59 
60  for (i = 0 ; i < n ; i++)
61  {
62  W [i] = 0 ; /* # of nonzeros in row i (excl duplicates) */
63  Flag [i] = EMPTY ; /* Flag [i] = j if i appears in column j */
64  }
65  for (j = 0 ; j < n ; j++)
66  {
67  p2 = Ap [j+1] ;
68  for (p = Ap [j] ; p < p2 ; p++)
69  {
70  i = Ai [p] ;
71  if (Flag [i] != j)
72  {
73  /* row index i has not yet appeared in column j */
74  W [i]++ ; /* one more entry in row i */
75  Flag [i] = j ; /* flag row index i as appearing in col j*/
76  }
77  }
78  }
79 
80  /* --------------------------------------------------------------------- */
81  /* compute the row pointers for R */
82  /* --------------------------------------------------------------------- */
83 
84  Rp [0] = 0 ;
85  for (i = 0 ; i < n ; i++)
86  {
87  Rp [i+1] = Rp [i] + W [i] ;
88  }
89  for (i = 0 ; i < n ; i++)
90  {
91  W [i] = Rp [i] ;
92  Flag [i] = EMPTY ;
93  }
94 
95  /* --------------------------------------------------------------------- */
96  /* construct the row form matrix R */
97  /* --------------------------------------------------------------------- */
98 
99  /* R = row form of pattern of A */
100  for (j = 0 ; j < n ; j++)
101  {
102  p2 = Ap [j+1] ;
103  for (p = Ap [j] ; p < p2 ; p++)
104  {
105  i = Ai [p] ;
106  if (Flag [i] != j)
107  {
108  /* row index i has not yet appeared in column j */
109  Ri [W [i]++] = j ; /* put col j in row i */
110  Flag [i] = j ; /* flag row index i as appearing in col j*/
111  }
112  }
113  }
114 
115 #ifndef NDEBUG
116  ASSERT (AMD_valid (n, n, Rp, Ri) == AMD_OK) ;
117  for (j = 0 ; j < n ; j++)
118  {
119  ASSERT (W [j] == Rp [j+1]) ;
120  }
121 #endif
122 }
#define EMPTY
#define GLOBAL
#define Int
#define ASSERT(expression)
#define AMD_INVALID
Definition: amesos_amd.h:373
GLOBAL void AMD_preprocess(Int n, const Int Ap[], const Int Ai[], Int Rp[], Int Ri[], Int W[], Int Flag[])
#define AMD_OK
Definition: amesos_amd.h:371
#define AMD_valid