PaStiX Handbook  6.3.1
order_scotch_common.c
Go to the documentation of this file.
1 /**
2  *
3  * @file order_scotch_common.c
4  *
5  * PaStiX order common routine between order_compute_scotch.c and order_compute_ptscotch.c.
6  *
7  * @copyright 2004-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.3.1
11  * @author Xavier Lacoste
12  * @author Pierre Ramet
13  * @author Mathieu Faverge
14  * @author Tony Delarue
15  * @author Vincent Bridonneau
16  * @date 2023-07-21
17  *
18  **/
19 #include "common.h"
20 #include "graph/graph.h"
21 #include "order/order_internal.h"
22 #include "order_scotch_strats.h"
23 
24 #ifndef DOXYGEN_SHOULD_SKIP_THIS
25 #define STRAT_STR_MAX 1024
26 
27 #define STRAT_DIRECT(_isPTScotch_) ( (_isPTScotch_) ? PTSCOTCH_STRAT_DIRECT : SCOTCH_STRAT_DIRECT )
28 #define STRAT_INCOMP(_isPTScotch_) ( (_isPTScotch_) ? PTSCOTCH_STRAT_INCOMP : SCOTCH_STRAT_INCOMP )
29 #define STRAT_PERSON(_isPTScotch_) ( (_isPTScotch_) ? PTSCOTCH_STRAT_PERSO : SCOTCH_STRAT_PERSO )
30 
31 #define OUTPUT_DIRECT(_isPTScotch_) ( (_isPTScotch_) ? " PT-Scotch direct strategy\n" : " Scotch direct strategy\n" )
32 #define OUTPUT_INCOMP(_isPTScotch_) ( (_isPTScotch_) ? " PT-Scotch incomplete strategy\n" : " Scotch incomplete strategy\n" )
33 #define OUTPUT_PERSON(_isPTScotch_) ( (_isPTScotch_) ? " PT-Scotch personal strategy |%s|\n": " Scotch personal strategy |%s|\n" )
34 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
35 
36 /**
37  *******************************************************************************
38  *
39  * @ingroup pastix_order
40  *
41  * @brief Generate the ordering strategy string based on the input parameters.
42  *
43  *******************************************************************************
44  *
45  * @param[in] iparm
46  * Pointer to the iparm array.
47  *
48  * @param[in] procnum
49  * Procnum of the process. Output purpose.
50  *
51  * @param[in] isPTscotch
52  * Boolean that indicates if we use Scotch or PT-Scotch for the order
53  * step.
54  *
55  ********************************************************************************
56  *
57  * @retval The strategy string of the order step.
58  *
59  *******************************************************************************/
60 char *
62  pastix_int_t procnum,
63  int isPTscotch )
64 {
65  char *strat;
66  MALLOC_INTERN( strat, STRAT_STR_MAX, char );
67 
68  /* Default ordering */
69  if ( iparm[IPARM_ORDERING_DEFAULT] == 1 ) {
70  if ( iparm[IPARM_INCOMPLETE] == 0 ) {
71  if ( iparm[IPARM_VERBOSE] > PastixVerboseNo ) {
72  pastix_print( procnum, 0, OUTPUT_DIRECT(isPTscotch) );
73  }
74  snprintf( strat, STRAT_STR_MAX, STRAT_DIRECT(isPTscotch) );
75  }
76  else {
77  if ( iparm[IPARM_VERBOSE] > PastixVerboseNo ) {
78  pastix_print( procnum, 0, OUTPUT_INCOMP(isPTscotch) );
79  }
80  snprintf( strat, STRAT_STR_MAX, STRAT_INCOMP(isPTscotch) );
81  }
82  }
83  /* Personal ordering */
84  else {
85  int rc;
86  rc = snprintf( strat, STRAT_STR_MAX, STRAT_PERSON(isPTscotch),
87  (long) iparm[IPARM_SCOTCH_SWITCH_LEVEL],
88  (long) iparm[IPARM_SCOTCH_CMIN],
89  (long) iparm[IPARM_SCOTCH_CMAX],
90  ((float)iparm[IPARM_SCOTCH_FRAT])/100.,
91  (long) iparm[IPARM_SCOTCH_SWITCH_LEVEL],
92  (long) iparm[IPARM_SCOTCH_CMIN],
93  (long) iparm[IPARM_SCOTCH_CMAX],
94  ((float)iparm[IPARM_SCOTCH_FRAT])/100. );
95  if ( rc > STRAT_STR_MAX ) {
96  pastix_print_error( "Order_scotch_build_strategy: Strategy string too long\n" );
97  exit(-1);
98  }
99 
100  if ( iparm[IPARM_VERBOSE] > PastixVerboseNo ) {
101  pastix_print( procnum, 0, OUTPUT_PERSON(isPTscotch), strat );
102  }
103  }
104 
105  return strat;
106 }
107 
108 /**
109  *******************************************************************************
110  *
111  * @ingroup pastix_order
112  *
113  * @brief Reallocate the ordering structure.
114  *
115  * If we decide to drop the Scotch partition to recompute it later, then
116  * partition information is freed, otherwise its memory space is compressed.
117  *
118  *******************************************************************************
119  *
120  * @param[inout] ordemesh
121  * Pointer to the ordemesh structure to reallocate.
122  *
123  *******************************************************************************/
124 void
126 {
127 #if defined(FORGET_PARTITION)
128  ordemesh->cblknbr = 0;
129  if ( ordemesh->rangtab != NULL ) {
130  memFree_null( ordemesh->rangtab );
131  }
132  if ( ordemesh->treetab != NULL ) {
133  memFree_null( ordemesh->treetab );
134  }
135 #else
136  /**
137  * Adapt size of rangtab and treetab to the new cblknbr
138  * WARNING: If no nodes in the graph, nothing has been initialized.
139  */
140  ordemesh->rangtab =
141  (pastix_int_t *) memRealloc( ordemesh->rangtab,
142  (ordemesh->cblknbr + 1)*sizeof(pastix_int_t) );
143  ordemesh->treetab =
144  (pastix_int_t *) memRealloc( ordemesh->treetab,
145  (ordemesh->cblknbr)*sizeof(pastix_int_t) );
146  if ( ordemesh->cblknbr == 0 ) {
147  ordemesh->rangtab[0] = ordemesh->baseval;
148  }
149 #endif
150 }
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
@ IPARM_SCOTCH_FRAT
Definition: api.h:58
@ IPARM_SCOTCH_CMAX
Definition: api.h:57
@ IPARM_ORDERING_DEFAULT
Definition: api.h:51
@ IPARM_SCOTCH_SWITCH_LEVEL
Definition: api.h:55
@ IPARM_VERBOSE
Definition: api.h:36
@ IPARM_SCOTCH_CMIN
Definition: api.h:56
@ IPARM_INCOMPLETE
Definition: api.h:95
@ PastixVerboseNo
Definition: api.h:221
pastix_int_t baseval
Definition: order.h:48
pastix_int_t * treetab
Definition: order.h:54
pastix_int_t cblknbr
Definition: order.h:50
pastix_int_t * rangtab
Definition: order.h:53
void order_scotch_reallocate_ordemesh(pastix_order_t *ordemesh)
Reallocate the ordering structure.
char * order_scotch_build_strategy(const pastix_int_t *iparm, pastix_int_t procnum, int isPTscotch)
Generate the ordering strategy string based on the input parameters.
Order structure.
Definition: order.h:47