PaStiX Handbook  6.3.2
order_compute_personal.c
Go to the documentation of this file.
1 /**
2  *
3  * @file order_compute_personal.c
4  *
5  * PaStiX order driver to perform ordering with personal algorithm.
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 Pierre Ramet
13  * @author Mathieu Faverge
14  * @author Tony Delarue
15  * @date 2023-07-21
16  *
17  **/
18 #include "common.h"
19 #include "graph/graph.h"
20 #include "order/order_internal.h"
21 
22 /**
23  *******************************************************************************
24  *
25  * @ingroup pastix_order
26  *
27  * @brief Computes the personal ordering of the PaStiX instance.
28  *
29  *******************************************************************************
30  *
31  * @param[inout] pastix_data
32  * The pastix_data structure that describes the solver instance.
33  * On exit, the field ordemesh is initialized with the identity
34  * ordering if myorder is NULL, or with the provided ordering
35  * otherwise.
36  *
37  * @param[inout] graph
38  * The graph prepared by graphPrepare function on which we want to
39  * perform the ordering. On exit, the graph might be rebased.
40  *
41  * @param[inout] myorder
42  * On entry, the permutation provided by the user or NULL to get
43  * the identity ordering.
44  * On exit, if the permutation is not NULL, it contains the generated
45  * ordering permutation.
46  * Otherwise, it is not referenced.
47  *
48  *******************************************************************************
49  *
50  * @retval PASTIX_SUCCESS on successful exit,
51  * @retval PASTIX_ERR_BADPARAMETER if one parameter is incorrect,
52  * @retval PASTIX_ERR_FILE if a problem occurs during the read in pastixOrderLoad
53  *
54  *******************************************************************************/
55 int
57  pastix_graph_t *graph,
58  pastix_order_t *myorder )
59 {
60  pastix_order_t *ordemesh;
61  pastix_int_t *iparm;
62  pastix_int_t i, n;
63  int procnum;
64  int retval = PASTIX_SUCCESS;
65 
66  ordemesh = pastix_data->ordemesh;
67  iparm = pastix_data->iparm;
68  procnum = pastix_data->procnum;
69  n = graph->gN;
70 
71  /* Load ordering from file */
72  if ( iparm[IPARM_IO_STRATEGY] & PastixIOLoad ) {
73  if ( iparm[IPARM_VERBOSE] > PastixVerboseNot ) {
74  pastix_print( procnum, 0, OUT_ORDER_METHOD, "Load" );
75  }
76  retval = pastixOrderLoad( pastix_data, ordemesh );
77  return retval;
78  }
79  pastixOrderAlloc( ordemesh, n, 0 );
80 
81  /* Rebase the Personal ordering to 0 */
82  if ( myorder != NULL ) {
83  assert( myorder != NULL );
84  assert( myorder->vertnbr == n );
85  pastixOrderBase( myorder, 0 );
86  }
87 
88  if ( (myorder == NULL) || (myorder->permtab == NULL) ) {
89  if ( (myorder == NULL) || (myorder->peritab == NULL) ) {
90  if ( iparm[IPARM_VERBOSE] > PastixVerboseNot ) {
91  pastix_print( procnum, 0, OUT_ORDER_METHOD, "Personal (identity)" );
92  }
93  for( i=0; i<n; i++ ) {
94  ordemesh->permtab[i] = i;
95  ordemesh->peritab[i] = i;
96  }
97  }
98  else {
99  if ( iparm[IPARM_VERBOSE] > PastixVerboseNot ) {
100  pastix_print( procnum, 0, OUT_ORDER_METHOD, "Personal (from myorder->peritab)" );
101  }
102  /* generate permtab from myorder->peritab */
103  for( i=0; i<n; i++ ) {
104  ordemesh->permtab[myorder->peritab[i]] = i;
105  }
106  memcpy( ordemesh->peritab, myorder->peritab, n*sizeof(pastix_int_t) );
107  }
108  }
109  else {
110  if ( myorder->peritab == NULL ) {
111  if ( iparm[IPARM_VERBOSE] > PastixVerboseNot ) {
112  pastix_print( procnum, 0, OUT_ORDER_METHOD, "Personal (from myorder->permtab)" );
113  }
114  /* generate peritab from myorder->permtab */
115  for( i=0; i<n; i++) {
116  ordemesh->peritab[myorder->permtab[i]] = i;
117  }
118  memcpy( ordemesh->permtab, myorder->permtab, n*sizeof(pastix_int_t) );
119  }
120  else {
121  if ( iparm[IPARM_VERBOSE] > PastixVerboseNot ) {
122  pastix_print( procnum, 0, OUT_ORDER_METHOD, "Personal (myorder->permtab/peritab)" );
123  }
124  memcpy( ordemesh->permtab, myorder->permtab, n*sizeof(pastix_int_t) );
125  memcpy( ordemesh->peritab, myorder->peritab, n*sizeof(pastix_int_t) );
126  }
127  }
128 
129  /* Destroy the rangtab */
130  ordemesh->cblknbr = 0;
131  memFree_null( ordemesh->rangtab );
132  /* Destroy the treetab */
133  memFree_null( ordemesh->treetab );
134 
135  /* If treetab is provided, user must also provide rangtab */
136  if ( myorder != NULL ) {
137  assert( !( (myorder->rangtab == NULL) && (myorder->treetab != NULL) ) );
138  if ( myorder->rangtab != NULL )
139  {
140  ordemesh->cblknbr = myorder->cblknbr;
141  MALLOC_INTERN( ordemesh->rangtab, myorder->cblknbr+1, pastix_int_t );
142  memcpy( ordemesh->rangtab, myorder->rangtab, (myorder->cblknbr+1)*sizeof(pastix_int_t) );
143  }
144  if ( myorder->treetab != NULL )
145  {
146  MALLOC_INTERN( ordemesh->treetab, myorder->cblknbr, pastix_int_t );
147  memcpy( ordemesh->treetab, myorder->treetab, myorder->cblknbr*sizeof(pastix_int_t) );
148  }
149  }
150 
151  return retval;
152 }
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
@ PastixIOLoad
Definition: api.h:230
@ IPARM_VERBOSE
Definition: api.h:36
@ IPARM_IO_STRATEGY
Definition: api.h:37
@ PastixVerboseNot
Definition: api.h:220
@ PASTIX_SUCCESS
Definition: api.h:367
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
void pastixOrderBase(pastix_order_t *ordeptr, pastix_int_t baseval)
This routine sets the base of the given ordering structure to the given base value.
Definition: order.c:322
int orderComputePersonal(pastix_data_t *pastix_data, pastix_graph_t *graph, pastix_order_t *myorder)
Computes the personal ordering of the PaStiX instance.
int pastixOrderLoad(const pastix_data_t *pastix_data, pastix_order_t *ordeptr)
Load an ordering from a file.
Definition: order_io.c:132
Order structure.
Definition: order.h:47
pastix_order_t * ordemesh
Definition: pastixdata.h:97
pastix_int_t * iparm
Definition: pastixdata.h:69
Main PaStiX data structure.
Definition: pastixdata.h:67