PaStiX Handbook  6.3.2
order_add_isolate.c
Go to the documentation of this file.
1 /**
2  *
3  * @file order_add_isolate.c
4  *
5  * PaStiX order routines to add subset of isolated vertices.
6  *
7  * @copyright 2004-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.3.2
11  * @author Xavier Lacoste
12  * @author Mathieu Faverge
13  * @author Pierre Ramet
14  * @date 2023-07-21
15  *
16  **/
17 #include "common.h"
18 #include "order/order_internal.h"
19 
20 /**
21  *******************************************************************************
22  *
23  * @ingroup pastix_order
24  *
25  * @brief This routine combines two permutation arrays when a subset
26  * of vertices has been isolated from the original graph through graphIsolate()
27  * function.
28  *
29  *******************************************************************************
30  *
31  * @param[inout] ordemesh
32  * The ordering generated by the ordering tool.
33  *
34  * @param[in] new_n
35  * The total number of vertices in the combined graph
36  *
37  * @param[in] perm
38  * Array of size new_n that must be 0-based.
39  * The permutation array that isolated the extra vertices at the end of
40  * the graph. This permutation will be combined with the one stored in
41  * ordemesh to generate a permutation array for the full graph.
42  * This permutation must be 0-based.
43  *
44  *******************************************************************************
45  *
46  * @retval PASTIX_SUCCESS on successful exit,
47  * @retval PASTIX_ERR_BADPARAMETER if one parameter is incorrect,
48  * @retval PASTIX_ERR_OUTOFMEMORY if one allocation failed.
49  *
50  *******************************************************************************
51  *
52  * @sa graphIsolate
53  *
54  *******************************************************************************/
55 int
57  pastix_int_t new_n,
58  const pastix_int_t *perm )
59 {
60  pastix_order_t ordesave;
61  pastix_int_t i, ip;
62  pastix_int_t n;
63  pastix_int_t cblknbr;
64  int baseval, rc;
65 
66  /* Parameter checks */
67  if ( ordemesh == NULL ) {
69  }
70  if ( new_n < ordemesh->vertnbr ) {
72  }
73  if ( perm == NULL ) {
75  }
76 
77  n = ordemesh->vertnbr;
78  cblknbr = ordemesh->cblknbr;
79  baseval = ordemesh->baseval;
80 
81  /* Quick return */
82  if ( n == new_n )
83  return PASTIX_SUCCESS;
84 
85  assert( n <= new_n );
86 
87  memcpy( &ordesave, ordemesh, sizeof(pastix_order_t) );
88  rc = pastixOrderAlloc( ordemesh, new_n, cblknbr + 1 );
89  if (rc != PASTIX_SUCCESS) {
90  return rc;
91  }
92 
93  ordemesh->baseval = baseval;
94  for(i=0; i< new_n; i++) {
95  ip = perm[i];
96  assert(ip < new_n);
97  if (ip < n) {
98  ordemesh->permtab[i] = ordesave.permtab[ ip ];
99  }
100  else {
101  ordemesh->permtab[i] = ip+baseval;
102  }
103  }
104  for(i=0; i<new_n; i++) {
105  ip = ordemesh->permtab[i] - baseval;
106  assert( (ip > -1) && (ip < new_n) );
107  ordemesh->peritab[ip] = i + baseval;
108  }
109 
110  /* Copy the cblknbr+1 first element of old rangtab and add last element */
111  assert( ordesave.rangtab != NULL );
112  memcpy( ordemesh->rangtab, ordesave.rangtab, (ordesave.cblknbr+1) * sizeof(pastix_int_t) );
113  ordemesh->rangtab[ ordemesh->cblknbr ] = new_n + baseval;
114 
115  /* We connect each roots of the elimination forest to the new cblk (shur or isolated terms) */
116  assert( ordesave.treetab != NULL );
117  memcpy( ordemesh->treetab, ordesave.treetab, ordesave.cblknbr * sizeof(pastix_int_t) );
118  for(i=0; i < ordesave.cblknbr; i++) {
119  assert( ordemesh->treetab[i] != i );
120  /* This was a root, we connect it to the last one */
121  if ( ordemesh->treetab[i] == -1 ) {
122  ordemesh->treetab[ i ] = ordesave.cblknbr + baseval;
123  }
124  }
125  ordemesh->treetab[ ordesave.cblknbr ] = -1;
126 
127  pastixOrderExit( &ordesave );
128  return PASTIX_SUCCESS;
129 }
130 
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
@ PASTIX_SUCCESS
Definition: api.h:367
@ PASTIX_ERR_BADPARAMETER
Definition: api.h:374
pastix_int_t baseval
Definition: order.h:48
pastix_int_t * treetab
Definition: order.h:54
pastix_int_t * permtab
Definition: order.h:51
pastix_int_t * peritab
Definition: order.h:52
pastix_int_t cblknbr
Definition: order.h:50
pastix_int_t * rangtab
Definition: order.h:53
pastix_int_t vertnbr
Definition: order.h:49
int pastixOrderAlloc(pastix_order_t *ordeptr, pastix_int_t vertnbr, pastix_int_t cblknbr)
Allocate the order structure.
Definition: order.c:55
int orderAddIsolate(pastix_order_t *ordemesh, pastix_int_t new_n, const pastix_int_t *perm)
This routine combines two permutation arrays when a subset of vertices has been isolated from the ori...
void pastixOrderExit(pastix_order_t *ordeptr)
Free the arrays initialized in the order structure.
Definition: order.c:273
Order structure.
Definition: order.h:47