MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
colamd.h File Reference
#include <stdlib.h>
Include dependency graph for colamd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mbdyn_Colamd_Col
 
struct  mbdyn_Colamd_Row
 

Macros

#define COLAMD_KNOBS   20
 
#define COLAMD_STATS   20
 
#define COLAMD_DENSE_ROW   0
 
#define COLAMD_DENSE_COL   1
 
#define COLAMD_DEFRAG_COUNT   2
 
#define COLAMD_STATUS   3
 
#define COLAMD_INFO1   4
 
#define COLAMD_INFO2   5
 
#define COLAMD_INFO3   6
 
#define COLAMD_OK   (0)
 
#define COLAMD_OK_BUT_JUMBLED   (1)
 
#define COLAMD_ERROR_A_not_present   (-1)
 
#define COLAMD_ERROR_p_not_present   (-2)
 
#define COLAMD_ERROR_nrow_negative   (-3)
 
#define COLAMD_ERROR_ncol_negative   (-4)
 
#define COLAMD_ERROR_nnz_negative   (-5)
 
#define COLAMD_ERROR_p0_nonzero   (-6)
 
#define COLAMD_ERROR_A_too_small   (-7)
 
#define COLAMD_ERROR_col_length_negative   (-8)
 
#define COLAMD_ERROR_row_index_out_of_bounds   (-9)
 
#define COLAMD_ERROR_out_of_memory   (-10)
 
#define COLAMD_ERROR_internal_error   (-999)
 
#define COLAMD_C(n_col)   (((n_col) + 1) * sizeof (mbdyn_Colamd_Col) / sizeof (int))
 
#define COLAMD_R(n_row)   (((n_row) + 1) * sizeof (mbdyn_Colamd_Row) / sizeof (int))
 
#define COLAMD_RECOMMENDED(nnz, n_row, n_col)
 

Typedefs

typedef struct mbdyn_Colamd_Col mbdyn_Colamd_Col
 
typedef struct mbdyn_Colamd_Row mbdyn_Colamd_Row
 

Functions

integer mbdyn_colamd_recommended (integer nnz, integer n_row, integer n_col)
 
void mbdyn_colamd_set_defaults (double knobs[20])
 
integer mbdyn_colamd (integer n_row, integer n_col, integer Alen, integer A[], integer p[], double knobs[20], integer stats[20])
 
integer mbdyn_symamd (integer n, integer A[], integer p[], integer perm[], double knobs[20], integer stats[20], void *(*allocate)(size_t, size_t), void(*release)(void *))
 
void mbdyn_colamd_report (integer stats[20])
 
void mbdyn_symamd_report (integer stats[20])
 

Macro Definition Documentation

#define COLAMD_C (   n_col)    (((n_col) + 1) * sizeof (mbdyn_Colamd_Col) / sizeof (int))

Definition at line 225 of file colamd.h.

Referenced by mbdyn_colamd().

#define COLAMD_DEFRAG_COUNT   2

Definition at line 126 of file colamd.h.

Referenced by mbdyn_colamd(), mbdyn_symamd(), and print_report().

#define COLAMD_DENSE_COL   1
#define COLAMD_DENSE_ROW   0
#define COLAMD_ERROR_A_not_present   (-1)

Definition at line 139 of file colamd.h.

Referenced by mbdyn_colamd(), mbdyn_symamd(), and print_report().

#define COLAMD_ERROR_A_too_small   (-7)

Definition at line 145 of file colamd.h.

Referenced by mbdyn_colamd(), and print_report().

#define COLAMD_ERROR_col_length_negative   (-8)

Definition at line 146 of file colamd.h.

Referenced by init_rows_cols(), mbdyn_symamd(), and print_report().

#define COLAMD_ERROR_internal_error   (-999)

Definition at line 149 of file colamd.h.

Referenced by mbdyn_symamd(), and print_report().

#define COLAMD_ERROR_ncol_negative   (-4)

Definition at line 142 of file colamd.h.

Referenced by mbdyn_colamd(), mbdyn_symamd(), and print_report().

#define COLAMD_ERROR_nnz_negative   (-5)

Definition at line 143 of file colamd.h.

Referenced by mbdyn_colamd(), mbdyn_symamd(), and print_report().

#define COLAMD_ERROR_nrow_negative   (-3)

Definition at line 141 of file colamd.h.

Referenced by mbdyn_colamd(), and print_report().

#define COLAMD_ERROR_out_of_memory   (-10)

Definition at line 148 of file colamd.h.

Referenced by mbdyn_symamd(), and print_report().

#define COLAMD_ERROR_p0_nonzero   (-6)

Definition at line 144 of file colamd.h.

Referenced by mbdyn_colamd(), mbdyn_symamd(), and print_report().

#define COLAMD_ERROR_p_not_present   (-2)

Definition at line 140 of file colamd.h.

Referenced by mbdyn_colamd(), mbdyn_symamd(), and print_report().

#define COLAMD_ERROR_row_index_out_of_bounds   (-9)

Definition at line 147 of file colamd.h.

Referenced by init_rows_cols(), mbdyn_symamd(), and print_report().

#define COLAMD_INFO1   4

Definition at line 132 of file colamd.h.

Referenced by init_rows_cols(), mbdyn_colamd(), mbdyn_symamd(), and print_report().

#define COLAMD_INFO2   5

Definition at line 133 of file colamd.h.

Referenced by init_rows_cols(), mbdyn_colamd(), mbdyn_symamd(), and print_report().

#define COLAMD_INFO3   6

Definition at line 134 of file colamd.h.

Referenced by init_rows_cols(), mbdyn_symamd(), and print_report().

#define COLAMD_KNOBS   20
#define COLAMD_OK   (0)

Definition at line 137 of file colamd.h.

Referenced by mbdyn_colamd(), mbdyn_symamd(), and print_report().

#define COLAMD_OK_BUT_JUMBLED   (1)

Definition at line 138 of file colamd.h.

Referenced by init_rows_cols(), mbdyn_symamd(), and print_report().

#define COLAMD_R (   n_row)    (((n_row) + 1) * sizeof (mbdyn_Colamd_Row) / sizeof (int))

Definition at line 226 of file colamd.h.

Referenced by mbdyn_colamd().

#define COLAMD_RECOMMENDED (   nnz,
  n_row,
  n_col 
)
Value:
( \
((nnz) < 0 || (n_row) < 0 || (n_col) < 0) \
? \
(-1) \
: \
(2 * (nnz) + COLAMD_C (n_col) + COLAMD_R (n_row) + (n_col) + ((nnz) / 5)) \
)
#define COLAMD_R(n_row)
Definition: colamd.h:226
#define COLAMD_C(n_col)
Definition: colamd.h:225

Definition at line 228 of file colamd.h.

Referenced by mbdyn_colamd_recommended().

#define COLAMD_STATS   20
#define COLAMD_STATUS   3

Definition at line 129 of file colamd.h.

Referenced by init_rows_cols(), mbdyn_colamd(), mbdyn_symamd(), and print_report().

Typedef Documentation

Function Documentation

integer mbdyn_colamd ( integer  n_row,
integer  n_col,
integer  Alen,
integer  A[],
integer  p[],
double  knobs[20],
integer  stats[20] 
)

Definition at line 1411 of file colamd.c.

References COLAMD_C, COLAMD_DEFRAG_COUNT, COLAMD_DENSE_COL, COLAMD_DENSE_ROW, COLAMD_ERROR_A_not_present, COLAMD_ERROR_A_too_small, COLAMD_ERROR_ncol_negative, COLAMD_ERROR_nnz_negative, COLAMD_ERROR_nrow_negative, COLAMD_ERROR_p0_nonzero, COLAMD_ERROR_p_not_present, COLAMD_INFO1, COLAMD_INFO2, COLAMD_KNOBS, COLAMD_OK, COLAMD_R, COLAMD_STATS, COLAMD_STATUS, DEBUG0, FALSE, find_ordering(), init_rows_cols(), init_scoring(), mbdyn_colamd_set_defaults(), order_children(), and TRUE.

Referenced by NaiveSparsePermSolutionManager< T >::ComputePermutation(), and mbdyn_symamd().

1422 {
1423  /* === Local variables ================================================== */
1424 
1425  integer i ; /* loop index */
1426  integer nnz ; /* nonzeros in A */
1427  integer Row_size ; /* size of Row [], in integers */
1428  integer Col_size ; /* size of Col [], in integers */
1429  integer need ; /* minimum required length of A */
1430  mbdyn_Colamd_Row *Row ; /* pointer into A of Row [0..n_row] array */
1431  mbdyn_Colamd_Col *Col ; /* pointer into A of Col [0..n_col] array */
1432  integer n_col2 ; /* number of non-dense, non-empty columns */
1433  integer n_row2 ; /* number of non-dense, non-empty rows */
1434  integer ngarbage ; /* number of garbage collections performed */
1435  integer max_deg ; /* maximum row degree */
1436  double default_knobs [COLAMD_KNOBS] ; /* default knobs array */
1437 
1438 #ifndef NDEBUG
1439  colamd_get_debug ("colamd") ;
1440 #endif /* NDEBUG */
1441 
1442  /* === Check the input arguments ======================================== */
1443 
1444  if (!stats)
1445  {
1446  DEBUG0 (("colamd: stats not present\n")) ;
1447  return (FALSE) ;
1448  }
1449  for (i = 0 ; i < COLAMD_STATS ; i++)
1450  {
1451  stats [i] = 0 ;
1452  }
1453  stats [COLAMD_STATUS] = COLAMD_OK ;
1454  stats [COLAMD_INFO1] = -1 ;
1455  stats [COLAMD_INFO2] = -1 ;
1456 
1457  if (!A) /* A is not present */
1458  {
1460  DEBUG0 (("colamd: A not present\n")) ;
1461  return (FALSE) ;
1462  }
1463 
1464  if (!p) /* p is not present */
1465  {
1467  DEBUG0 (("colamd: p not present\n")) ;
1468  return (FALSE) ;
1469  }
1470 
1471  if (n_row < 0) /* n_row must be >= 0 */
1472  {
1474  stats [COLAMD_INFO1] = n_row ;
1475  DEBUG0 (("colamd: nrow negative %d\n", n_row)) ;
1476  return (FALSE) ;
1477  }
1478 
1479  if (n_col < 0) /* n_col must be >= 0 */
1480  {
1482  stats [COLAMD_INFO1] = n_col ;
1483  DEBUG0 (("colamd: ncol negative %d\n", n_col)) ;
1484  return (FALSE) ;
1485  }
1486 
1487  nnz = p [n_col] ;
1488  if (nnz < 0) /* nnz must be >= 0 */
1489  {
1491  stats [COLAMD_INFO1] = nnz ;
1492  DEBUG0 (("colamd: number of entries negative %d\n", nnz)) ;
1493  return (FALSE) ;
1494  }
1495 
1496  if (p [0] != 0)
1497  {
1499  stats [COLAMD_INFO1] = p [0] ;
1500  DEBUG0 (("colamd: p[0] not zero %d\n", p [0])) ;
1501  return (FALSE) ;
1502  }
1503 
1504  /* === If no knobs, set default knobs =================================== */
1505 
1506  if (!knobs)
1507  {
1508  mbdyn_colamd_set_defaults (default_knobs) ;
1509  knobs = default_knobs ;
1510  }
1511 
1512  /* === Allocate the Row and Col arrays from array A ===================== */
1513 
1514  Col_size = COLAMD_C (n_col) ;
1515  Row_size = COLAMD_R (n_row) ;
1516  need = 2*nnz + n_col + Col_size + Row_size ;
1517 
1518  if (need > Alen)
1519  {
1520  /* not enough space in array A to perform the ordering */
1522  stats [COLAMD_INFO1] = need ;
1523  stats [COLAMD_INFO2] = Alen ;
1524  DEBUG0 (("colamd: Need Alen >= %d, given only Alen = %d\n", need,Alen));
1525  return (FALSE) ;
1526  }
1527 
1528  Alen -= Col_size + Row_size ;
1529  Col = (mbdyn_Colamd_Col *) &A [Alen] ;
1530  Row = (mbdyn_Colamd_Row *) &A [Alen + Col_size] ;
1531 
1532  /* === Construct the row and column data structures ===================== */
1533 
1534  if (!init_rows_cols (n_row, n_col, Row, Col, A, p, stats))
1535  {
1536  /* input matrix is invalid */
1537  DEBUG0 (("colamd: Matrix invalid\n")) ;
1538  return (FALSE) ;
1539  }
1540 
1541  /* === Initialize scores, kill dense rows/columns ======================= */
1542 
1543  init_scoring (n_row, n_col, Row, Col, A, p, knobs,
1544  &n_row2, &n_col2, &max_deg) ;
1545 
1546  /* === Order the supercolumns =========================================== */
1547 
1548  ngarbage = find_ordering (n_row, n_col, Alen, Row, Col, A, p,
1549  n_col2, max_deg, 2*nnz) ;
1550 
1551  /* === Order the non-principal columns ================================== */
1552 
1553  order_children (n_col, Col, p) ;
1554 
1555  /* === Return statistics in stats ======================================= */
1556 
1557  stats [COLAMD_DENSE_ROW] = n_row - n_row2 ;
1558  stats [COLAMD_DENSE_COL] = n_col - n_col2 ;
1559  stats [COLAMD_DEFRAG_COUNT] = ngarbage ;
1560  DEBUG0 (("colamd: done.\n")) ;
1561  return (TRUE) ;
1562 }
#define COLAMD_DEFRAG_COUNT
Definition: colamd.h:126
#define COLAMD_R(n_row)
Definition: colamd.h:226
static void order_children(integer n_col, mbdyn_Colamd_Col Col[], integer p[])
Definition: colamd.c:2670
static integer init_rows_cols(integer n_row, integer n_col, mbdyn_Colamd_Row Row[], mbdyn_Colamd_Col Col[], integer A[], integer p[], integer stats[20])
Definition: colamd.c:1613
static void init_scoring(integer n_row, integer n_col, mbdyn_Colamd_Row Row[], mbdyn_Colamd_Col Col[], integer A[], integer head[], double knobs[20], integer *p_n_row2, integer *p_n_col2, integer *p_max_deg)
Definition: colamd.c:1850
#define COLAMD_INFO2
Definition: colamd.h:133
void mbdyn_colamd_set_defaults(double knobs[20])
Definition: colamd.c:1038
#define COLAMD_STATS
Definition: colamd.h:117
#define COLAMD_DENSE_COL
Definition: colamd.h:123
static integer find_ordering(integer n_row, integer n_col, integer Alen, mbdyn_Colamd_Row Row[], mbdyn_Colamd_Col Col[], integer A[], integer head[], integer n_col2, integer max_deg, integer pfree)
Definition: colamd.c:2106
#define COLAMD_ERROR_p_not_present
Definition: colamd.h:140
#define COLAMD_ERROR_A_too_small
Definition: colamd.h:145
#define COLAMD_ERROR_A_not_present
Definition: colamd.h:139
#define TRUE
Definition: colamd.c:759
#define COLAMD_KNOBS
Definition: colamd.h:114
#define COLAMD_OK
Definition: colamd.h:137
#define COLAMD_DENSE_ROW
Definition: colamd.h:120
#define COLAMD_INFO1
Definition: colamd.h:132
#define COLAMD_C(n_col)
Definition: colamd.h:225
#define COLAMD_ERROR_ncol_negative
Definition: colamd.h:142
#define COLAMD_ERROR_nrow_negative
Definition: colamd.h:141
#define FALSE
Definition: colamd.c:763
#define DEBUG0(params)
Definition: colamd.c:971
long int integer
Definition: colamd.c:51
#define COLAMD_STATUS
Definition: colamd.h:129
#define COLAMD_ERROR_nnz_negative
Definition: colamd.h:143
#define COLAMD_ERROR_p0_nonzero
Definition: colamd.h:144

Here is the call graph for this function:

integer mbdyn_colamd_recommended ( integer  nnz,
integer  n_row,
integer  n_col 
)

Definition at line 1004 of file colamd.c.

References COLAMD_RECOMMENDED.

Referenced by NaiveSparsePermSolutionManager< T >::ComputePermutation(), and mbdyn_symamd().

1011 {
1012  return (COLAMD_RECOMMENDED (nnz, n_row, n_col)) ;
1013 }
#define COLAMD_RECOMMENDED(nnz, n_row, n_col)
Definition: colamd.h:228
void mbdyn_colamd_report ( integer  stats[20])

Definition at line 1570 of file colamd.c.

References print_report().

1573 {
1574  print_report ("colamd", stats) ;
1575 }
static void print_report(char *method, integer stats[20])
Definition: colamd.c:3091

Here is the call graph for this function:

void mbdyn_colamd_set_defaults ( double  knobs[20])

Definition at line 1038 of file colamd.c.

References COLAMD_DENSE_COL, COLAMD_DENSE_ROW, and COLAMD_KNOBS.

Referenced by NaiveSparsePermSolutionManager< T >::ComputePermutation(), mbdyn_colamd(), and mbdyn_symamd().

1043 {
1044  /* === Local variables ================================================== */
1045 
1046  integer i ;
1047 
1048  if (!knobs)
1049  {
1050  return ; /* no knobs to initialize */
1051  }
1052  for (i = 0 ; i < COLAMD_KNOBS ; i++)
1053  {
1054  knobs [i] = 0 ;
1055  }
1056  knobs [COLAMD_DENSE_ROW] = 0.5 ; /* ignore rows over 50% dense */
1057  knobs [COLAMD_DENSE_COL] = 0.5 ; /* ignore columns over 50% dense */
1058 }
#define COLAMD_DENSE_COL
Definition: colamd.h:123
#define COLAMD_KNOBS
Definition: colamd.h:114
#define COLAMD_DENSE_ROW
Definition: colamd.h:120
long int integer
Definition: colamd.c:51
integer mbdyn_symamd ( integer  n,
integer  A[],
integer  p[],
integer  perm[],
double  knobs[20],
integer  stats[20],
void *(*)(size_t, size_t)  allocate,
void(*)(void *)  release 
)

Definition at line 1066 of file colamd.c.

References ASSERT, COLAMD_DEFRAG_COUNT, COLAMD_DENSE_COL, COLAMD_DENSE_ROW, COLAMD_ERROR_A_not_present, COLAMD_ERROR_col_length_negative, COLAMD_ERROR_internal_error, COLAMD_ERROR_ncol_negative, COLAMD_ERROR_nnz_negative, COLAMD_ERROR_out_of_memory, COLAMD_ERROR_p0_nonzero, COLAMD_ERROR_p_not_present, COLAMD_ERROR_row_index_out_of_bounds, COLAMD_INFO1, COLAMD_INFO2, COLAMD_INFO3, COLAMD_KNOBS, COLAMD_OK, COLAMD_OK_BUT_JUMBLED, COLAMD_STATS, COLAMD_STATUS, count, DEBUG0, DEBUG1, FALSE, mbdyn_colamd(), mbdyn_colamd_recommended(), mbdyn_colamd_set_defaults(), and TRUE.

1082 {
1083  /* === Local variables ================================================== */
1084 
1085  integer *count ; /* length of each column of M, and col pointer*/
1086  integer *mark ; /* mark array for finding duplicate entries */
1087  integer *M ; /* row indices of matrix M */
1088  integer Mlen ; /* length of M */
1089  integer n_row ; /* number of rows in M */
1090  integer nnz ; /* number of entries in A */
1091  integer i ; /* row index of A */
1092  integer j ; /* column index of A */
1093  integer k ; /* row index of M */
1094  integer mnz ; /* number of nonzeros in M */
1095  integer pp ; /* index into a column of A */
1096  integer last_row ; /* last row seen in the current column */
1097  integer length ; /* number of nonzeros in a column */
1098 
1099  double cknobs [COLAMD_KNOBS] ; /* knobs for colamd */
1100  double default_knobs [COLAMD_KNOBS] ; /* default knobs for colamd */
1101  integer cstats [COLAMD_STATS] ; /* colamd stats */
1102 
1103 #ifndef NDEBUG
1104  colamd_get_debug ("symamd") ;
1105 #endif /* NDEBUG */
1106 
1107  /* === Check the input arguments ======================================== */
1108 
1109  if (!stats)
1110  {
1111  DEBUG0 (("symamd: stats not present\n")) ;
1112  return (FALSE) ;
1113  }
1114  for (i = 0 ; i < COLAMD_STATS ; i++)
1115  {
1116  stats [i] = 0 ;
1117  }
1118  stats [COLAMD_STATUS] = COLAMD_OK ;
1119  stats [COLAMD_INFO1] = -1 ;
1120  stats [COLAMD_INFO2] = -1 ;
1121 
1122  if (!A)
1123  {
1125  DEBUG0 (("symamd: A not present\n")) ;
1126  return (FALSE) ;
1127  }
1128 
1129  if (!p) /* p is not present */
1130  {
1132  DEBUG0 (("symamd: p not present\n")) ;
1133  return (FALSE) ;
1134  }
1135 
1136  if (n < 0) /* n must be >= 0 */
1137  {
1139  stats [COLAMD_INFO1] = n ;
1140  DEBUG0 (("symamd: n negative %d\n", n)) ;
1141  return (FALSE) ;
1142  }
1143 
1144  nnz = p [n] ;
1145  if (nnz < 0) /* nnz must be >= 0 */
1146  {
1148  stats [COLAMD_INFO1] = nnz ;
1149  DEBUG0 (("symamd: number of entries negative %d\n", nnz)) ;
1150  return (FALSE) ;
1151  }
1152 
1153  if (p [0] != 0)
1154  {
1156  stats [COLAMD_INFO1] = p [0] ;
1157  DEBUG0 (("symamd: p[0] not zero %d\n", p [0])) ;
1158  return (FALSE) ;
1159  }
1160 
1161  /* === If no knobs, set default knobs =================================== */
1162 
1163  if (!knobs)
1164  {
1165  mbdyn_colamd_set_defaults (default_knobs) ;
1166  knobs = default_knobs ;
1167  }
1168 
1169  /* === Allocate count and mark ========================================== */
1170 
1171  count = (integer *) ((*allocate) (n+1, sizeof (int))) ;
1172  if (!count)
1173  {
1175  DEBUG0 (("symamd: allocate count (size %d) failed\n", n+1)) ;
1176  return (FALSE) ;
1177  }
1178 
1179  mark = (integer *) ((*allocate) (n+1, sizeof (int))) ;
1180  if (!mark)
1181  {
1183  (*release) ((void *) count) ;
1184  DEBUG0 (("symamd: allocate mark (size %d) failed\n", n+1)) ;
1185  return (FALSE) ;
1186  }
1187 
1188  /* === Compute column counts of M, check if A is valid ================== */
1189 
1190  stats [COLAMD_INFO3] = 0 ; /* number of duplicate or unsorted row indices*/
1191 
1192  for (i = 0 ; i < n ; i++)
1193  {
1194  mark [i] = -1 ;
1195  }
1196 
1197  for (j = 0 ; j < n ; j++)
1198  {
1199  last_row = -1 ;
1200 
1201  length = p [j+1] - p [j] ;
1202  if (length < 0)
1203  {
1204  /* column pointers must be non-decreasing */
1206  stats [COLAMD_INFO1] = j ;
1207  stats [COLAMD_INFO2] = length ;
1208  (*release) ((void *) count) ;
1209  (*release) ((void *) mark) ;
1210  DEBUG0 (("symamd: col %d negative length %d\n", j, length)) ;
1211  return (FALSE) ;
1212  }
1213 
1214  for (pp = p [j] ; pp < p [j+1] ; pp++)
1215  {
1216  i = A [pp] ;
1217  if (i < 0 || i >= n)
1218  {
1219  /* row index i, in column j, is out of bounds */
1221  stats [COLAMD_INFO1] = j ;
1222  stats [COLAMD_INFO2] = i ;
1223  stats [COLAMD_INFO3] = n ;
1224  (*release) ((void *) count) ;
1225  (*release) ((void *) mark) ;
1226  DEBUG0 (("symamd: row %d col %d out of bounds\n", i, j)) ;
1227  return (FALSE) ;
1228  }
1229 
1230  if (i <= last_row || mark [i] == j)
1231  {
1232  /* row index is unsorted or repeated (or both), thus col */
1233  /* is jumbled. This is a notice, not an error condition. */
1235  stats [COLAMD_INFO1] = j ;
1236  stats [COLAMD_INFO2] = i ;
1237  (stats [COLAMD_INFO3]) ++ ;
1238  DEBUG1 (("symamd: row %d col %d unsorted/duplicate\n", i, j)) ;
1239  }
1240 
1241  if (i > j && mark [i] != j)
1242  {
1243  /* row k of M will contain column indices i and j */
1244  count [i]++ ;
1245  count [j]++ ;
1246  }
1247 
1248  /* mark the row as having been seen in this column */
1249  mark [i] = j ;
1250 
1251  last_row = i ;
1252  }
1253  }
1254 
1255  if (stats [COLAMD_STATUS] == COLAMD_OK)
1256  {
1257  /* if there are no duplicate entries, then mark is no longer needed */
1258  (*release) ((void *) mark) ;
1259  }
1260 
1261  /* === Compute column pointers of M ===================================== */
1262 
1263  /* use output permutation, perm, for column pointers of M */
1264  perm [0] = 0 ;
1265  for (j = 1 ; j <= n ; j++)
1266  {
1267  perm [j] = perm [j-1] + count [j-1] ;
1268  }
1269  for (j = 0 ; j < n ; j++)
1270  {
1271  count [j] = perm [j] ;
1272  }
1273 
1274  /* === Construct M ====================================================== */
1275 
1276  mnz = perm [n] ;
1277  n_row = mnz / 2 ;
1278  Mlen = mbdyn_colamd_recommended (mnz, n_row, n) ;
1279  M = (integer *) ((*allocate) (Mlen, sizeof (int))) ;
1280  DEBUG0 (("symamd: M is %d-by-%d with %d entries, Mlen = %d\n",
1281  n_row, n, mnz, Mlen)) ;
1282 
1283  if (!M)
1284  {
1286  (*release) ((void *) count) ;
1287  (*release) ((void *) mark) ;
1288  DEBUG0 (("symamd: allocate M (size %d) failed\n", Mlen)) ;
1289  return (FALSE) ;
1290  }
1291 
1292  k = 0 ;
1293 
1294  if (stats [COLAMD_STATUS] == COLAMD_OK)
1295  {
1296  /* Matrix is OK */
1297  for (j = 0 ; j < n ; j++)
1298  {
1299  ASSERT (p [j+1] - p [j] >= 0) ;
1300  for (pp = p [j] ; pp < p [j+1] ; pp++)
1301  {
1302  i = A [pp] ;
1303  ASSERT (i >= 0 && i < n) ;
1304  if (i > j)
1305  {
1306  /* row k of M contains column indices i and j */
1307  M [count [i]++] = k ;
1308  M [count [j]++] = k ;
1309  k++ ;
1310  }
1311  }
1312  }
1313  }
1314  else
1315  {
1316  /* Matrix is jumbled. Do not add duplicates to M. Unsorted cols OK. */
1317  DEBUG0 (("symamd: Duplicates in A.\n")) ;
1318  for (i = 0 ; i < n ; i++)
1319  {
1320  mark [i] = -1 ;
1321  }
1322  for (j = 0 ; j < n ; j++)
1323  {
1324  ASSERT (p [j+1] - p [j] >= 0) ;
1325  for (pp = p [j] ; pp < p [j+1] ; pp++)
1326  {
1327  i = A [pp] ;
1328  ASSERT (i >= 0 && i < n) ;
1329  if (i > j && mark [i] != j)
1330  {
1331  /* row k of M contains column indices i and j */
1332  M [count [i]++] = k ;
1333  M [count [j]++] = k ;
1334  k++ ;
1335  mark [i] = j ;
1336  }
1337  }
1338  }
1339  (*release) ((void *) mark) ;
1340  }
1341 
1342  /* count and mark no longer needed */
1343  (*release) ((void *) count) ;
1344  ASSERT (k == n_row) ;
1345 
1346  /* === Adjust the knobs for M =========================================== */
1347 
1348  for (i = 0 ; i < COLAMD_KNOBS ; i++)
1349  {
1350  cknobs [i] = knobs [i] ;
1351  }
1352 
1353  /* there are no dense rows in M */
1354  cknobs [COLAMD_DENSE_ROW] = 1.0 ;
1355 
1356  if (n_row != 0 && n < n_row)
1357  {
1358  /* On input, the knob is a fraction of 1..n, the number of rows of A. */
1359  /* Convert it to a fraction of 1..n_row, of the number of rows of M. */
1360  cknobs [COLAMD_DENSE_COL] = (knobs [COLAMD_DENSE_ROW] * n) / n_row ;
1361  }
1362  else
1363  {
1364  /* no dense columns in M */
1365  cknobs [COLAMD_DENSE_COL] = 1.0 ;
1366  }
1367 
1368  DEBUG0 (("symamd: dense col knob for M: %g\n", cknobs [COLAMD_DENSE_COL])) ;
1369 
1370  /* === Order the columns of M =========================================== */
1371 
1372  if (!mbdyn_colamd (n_row, n, Mlen, M, perm, cknobs, cstats))
1373  {
1374  /* This "cannot" happen, unless there is a bug in the code. */
1376  (*release) ((void *) M) ;
1377  DEBUG0 (("symamd: internal error!\n")) ;
1378  return (FALSE) ;
1379  }
1380 
1381  /* Note that the output permutation is now in perm */
1382 
1383  /* === get the statistics for symamd from colamd ======================== */
1384 
1385  /* note that a dense column in colamd means a dense row and col in symamd */
1386  stats [COLAMD_DENSE_ROW] = cstats [COLAMD_DENSE_COL] ;
1387  stats [COLAMD_DENSE_COL] = cstats [COLAMD_DENSE_COL] ;
1388  stats [COLAMD_DEFRAG_COUNT] = cstats [COLAMD_DEFRAG_COUNT] ;
1389 
1390  /* === Free M =========================================================== */
1391 
1392  (*release) ((void *) M) ;
1393  DEBUG0 (("symamd: done.\n")) ;
1394  return (TRUE) ;
1395 
1396 }
#define COLAMD_DEFRAG_COUNT
Definition: colamd.h:126
#define COLAMD_INFO2
Definition: colamd.h:133
#define COLAMD_ERROR_col_length_negative
Definition: colamd.h:146
#define COLAMD_INFO3
Definition: colamd.h:134
void mbdyn_colamd_set_defaults(double knobs[20])
Definition: colamd.c:1038
#define COLAMD_STATS
Definition: colamd.h:117
#define COLAMD_DENSE_COL
Definition: colamd.h:123
#define COLAMD_ERROR_p_not_present
Definition: colamd.h:140
#define COLAMD_ERROR_A_not_present
Definition: colamd.h:139
#define TRUE
Definition: colamd.c:759
#define COLAMD_KNOBS
Definition: colamd.h:114
#define COLAMD_ERROR_internal_error
Definition: colamd.h:149
integer mbdyn_colamd_recommended(integer nnz, integer n_row, integer n_col)
Definition: colamd.c:1004
integer mbdyn_colamd(integer n_row, integer n_col, integer Alen, integer A[], integer p[], double knobs[20], integer stats[20])
Definition: colamd.c:1411
#define COLAMD_OK
Definition: colamd.h:137
static int count
Definition: modules.cc:41
#define COLAMD_OK_BUT_JUMBLED
Definition: colamd.h:138
#define ASSERT(expression)
Definition: colamd.c:977
#define COLAMD_DENSE_ROW
Definition: colamd.h:120
#define COLAMD_INFO1
Definition: colamd.h:132
#define COLAMD_ERROR_ncol_negative
Definition: colamd.h:142
#define COLAMD_ERROR_row_index_out_of_bounds
Definition: colamd.h:147
#define FALSE
Definition: colamd.c:763
#define COLAMD_ERROR_out_of_memory
Definition: colamd.h:148
#define DEBUG0(params)
Definition: colamd.c:971
long int integer
Definition: colamd.c:51
#define COLAMD_STATUS
Definition: colamd.h:129
#define COLAMD_ERROR_nnz_negative
Definition: colamd.h:143
#define DEBUG1(params)
Definition: colamd.c:972
#define COLAMD_ERROR_p0_nonzero
Definition: colamd.h:144

Here is the call graph for this function:

void mbdyn_symamd_report ( integer  stats[20])

Definition at line 1583 of file colamd.c.

References print_report().

1586 {
1587  print_report ("symamd", stats) ;
1588 }
static void print_report(char *method, integer stats[20])
Definition: colamd.c:3091

Here is the call graph for this function: