PaStiX Handbook 6.4.0
Loading...
Searching...
No Matches
blendctrl.c
Go to the documentation of this file.
1/**
2 *
3 * @file blendctrl.c
4 *
5 * PaStiX analyse control parameters function.
6 *
7 * @copyright 1998-2025 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8 * Univ. Bordeaux. All rights reserved.
9 *
10 * @version 6.4.0
11 * @author Pascal Henon
12 * @author Mathieu Faverge
13 * @date 2024-07-05
14 *
15 **/
16#include <stdio.h>
17#include <stdlib.h>
18#include <sys/stat.h>
19#include <unistd.h>
20
21#include "common.h"
22#include "elimintree.h"
23#include "cost.h"
24#include "extendVector.h"
25#include "cand.h"
26#include "blendctrl.h"
27#include "perf.h"
28
29/**
30 *******************************************************************************
31 *
32 * @ingroup blend_dev_ctrl
33 *
34 * @brief Return the communication cost between two cores
35 *
36 *******************************************************************************
37 *
38 * @param[in] ctrl
39 * The Blend control data structure that holds the cluster architecture
40 *
41 * @param[in] clustsrc
42 * The source cluster of the communication
43 *
44 * @param[in] clustdst
45 * The remote cluster of the communication
46 *
47 * @param[in] sync_comm_nbr
48 * The number of simultaneous communication between clustsrc and clustdst
49 *
50 * @param[out] startup
51 * On exit, holds the startup/latency cost of the communication between
52 * the two nodes.
53 *
54 * @param[out] bandwidth
55 * On exit, holds the bandwidth of the communication between the two
56 * nodes.
57 *
58 *******************************************************************************/
59void
61 pastix_int_t clustsrc,
62 pastix_int_t clustdst,
63 pastix_int_t sync_comm_nbr,
64 double *startup,
65 double *bandwidth)
66{
67 assert((clustsrc >= 0) && (clustsrc < ctrl->clustnbr));
68 assert((clustdst >= 0) && (clustdst < ctrl->clustnbr));
69 assert((sync_comm_nbr > 0) && (sync_comm_nbr <= ctrl->clustnbr));
70
71 if(clustsrc == clustdst)
72 {
73 *startup = 0.;
74 *bandwidth = 0.;
75 return;
76 }
77
78 /* Shared Memory */
79 if( ctrl->clust2smp[clustsrc] == ctrl->clust2smp[clustdst] )
80 {
81 switch (sync_comm_nbr)
82 {
83 case 1:
84 case 2:
85 *startup = SHARED_STARTUP_1;
86 *bandwidth = SHARED_BANDWIDTH_1;
87 return;
88 case 3:
89 case 4:
90 *startup = SHARED_STARTUP_2;
91 *bandwidth = SHARED_BANDWIDTH_2;
92 return;
93 case 5:
94 case 6:
95 case 7:
96 case 8:
97 *startup = SHARED_STARTUP_4;
98 *bandwidth = SHARED_BANDWIDTH_4;
99 return;
100 default:
101 *startup = SHARED_STARTUP_8;
102 *bandwidth = SHARED_BANDWIDTH_8;
103 return;
104 }
105 }
106 else
107 {
108 switch (sync_comm_nbr)
109 {
110 case 1:
111 case 2:
112 *startup = CLUSTER_STARTUP_1;
113 *bandwidth = CLUSTER_BANDWIDTH_1;
114 return;
115 case 3:
116 case 4:
117 *startup = CLUSTER_STARTUP_2;
118 *bandwidth = CLUSTER_BANDWIDTH_2;
119 return;
120 case 5:
121 case 6:
122 case 7:
123 case 8:
124 *startup = CLUSTER_STARTUP_4;
125 *bandwidth = CLUSTER_BANDWIDTH_4;
126 return;
127 default:
128 *startup = CLUSTER_STARTUP_8;
129 *bandwidth = CLUSTER_BANDWIDTH_8;
130 return;
131 }
132 }
133}
134
135/**
136 *******************************************************************************
137 *
138 * @ingroup blend_dev_ctrl
139 *
140 * @brief Initialize the Blend control structure.
141 *
142 *******************************************************************************
143 *
144 * @param[inout] pastix_data
145 * The pastix_data structure of the problem instance. Integer
146 * parameters that are used to build the Blend control
147 * structure. IPARM_TASKS2D_LEVEL, IPARM_TASKS2D_WIDTH,
148 * IPARM_COMPRESS_WHEN, IPARM_COMPRESS_MIN_WIDTH, IPARM_INCOMPLETE,
149 * IPARM_MAX_BLOCKSIZE, IPARM_MIN_BLOCKSIZE, IPARM_THREAD_NBR, and
150 * IPARM_VERBOSE are used in this function.
151 *
152 * @param[inout] ctrl
153 * The Blend control data structure to initialize.
154 *
155 *******************************************************************************
156 *
157 * @retval PASTIX_SUCCESS on successful exit
158 * @retval PASTIX_ERR_BADPARAMETER if one parameter is incorrect.
159 *
160 *******************************************************************************/
161int
163 BlendCtrl *ctrl )
164{
165 pastix_int_t procnum = pastix_data->inter_node_procnum;
166 pastix_int_t procnbr = pastix_data->inter_node_procnbr;
167 pastix_int_t *iparm = pastix_data->iparm;
168 double *dparm = pastix_data->dparm;
169 pastix_int_t local_coresnbr = iparm[IPARM_THREAD_NBR];
170 pastix_int_t local_thrdsnbr = iparm[IPARM_THREAD_NBR];
171 pastix_int_t i;
172
173 /* Check parameters */
174 if( ctrl == NULL )
175 {
176 pastix_print_error( "blendCtrlInit: Illegal ctrl parameter\n" );
178 }
179 if( procnum < 0 )
180 {
181 pastix_print_error( "blendCtrlInit: Illegal procnum parameter\n" );
183 }
184 if( procnbr < 1 )
185 {
186 pastix_print_error( "blendCtrlInit: Illegal procnbr parameter\n" );
188 }
189 if( local_coresnbr < 1 )
190 {
191 pastix_print_error( "blendCtrlInit: Illegal local_coresnbr parameter\n" );
193 }
194 if( local_thrdsnbr < 1 )
195 {
196 pastix_print_error( "blendCtrlInit: Illegal local_thrdsnbr parameter\n" );
198 }
199 if( procnum >= procnbr )
200 {
201 pastix_print_error( "blendCtrlInit: Incompatible values of procnum(%d) and procnbr (%d)\n",
202 (int) procnum, (int) procnbr);
204 }
205
206 /* Initialize options */
207 ctrl->count_ops = 1;
208#if defined(PASTIX_DEBUG_BLEND)
209 ctrl->debug = 1;
210#else
211 ctrl->debug = 0;
212#endif
213 ctrl->timer = 1;
214 ctrl->ricar = iparm[IPARM_INCOMPLETE];
215 ctrl->leader = 0;
216
217 /* Proportional Mapping options */
218 ctrl->allcand = iparm[IPARM_ALLCAND];
219 ctrl->nocrossproc = 0;
220 ctrl->costlevel = 1;
221
222 /* Spliting options */
223 ctrl->blcolmin = iparm[IPARM_MIN_BLOCKSIZE];
224 ctrl->blcolmax = iparm[IPARM_MAX_BLOCKSIZE];
225 ctrl->up_after_split = 0;
226 if(ctrl->blcolmin > ctrl->blcolmax)
227 {
228 pastix_print_error( "Parameter error : blocksize max < blocksize min (cf. iparm.txt)." );
229 assert(ctrl->blcolmin <= ctrl->blcolmax);
230 }
231
232 /* 2D options */
233 ctrl->level_tasks2d = iparm[IPARM_TASKS2D_LEVEL];
234 ctrl->width_tasks2d = iparm[IPARM_TASKS2D_WIDTH];
235
236 /* Save iparm for other options */
237 ctrl->iparm = iparm;
238 ctrl->dparm = dparm;
239 if ( (ctrl->iparm[IPARM_VERBOSE] >= 2) &&
240 (pastix_data->dir_local == NULL) )
241 {
242 pastix_gendirectories( pastix_data );
243 }
244 ctrl->dirname = pastix_data->dir_local;
245
246 /*
247 * Initialize architecture description
248 */
249 /* Id and number of MPI processes */
250 ctrl->clustnum = procnum;
251 ctrl->clustnbr = procnbr;
252
253 /* Local informations */
254 ctrl->local_nbcores = local_coresnbr;
255 ctrl->local_nbthrds = local_thrdsnbr;
256 ctrl->local_nbctxts = ctrl->local_nbthrds;
257
258 /* Total information (should require a MPI_Reduce if different informations on each node) */
259 ctrl->total_nbcores = ctrl->local_nbcores * procnbr;
260 ctrl->total_nbthrds = ctrl->local_nbthrds * procnbr;
261
262 /* Create the array of associativity bewteen MPI process ids and SMP node ids */
263 /* Rq: We could use a MPI reduction for irregular pattern */
264 /* TODO: insert back the number of MPI processes per node */
265 MALLOC_INTERN(ctrl->clust2smp, ctrl->clustnbr, pastix_int_t);
266 for(i=0; i < ctrl->clustnbr; i++) {
267 ctrl->clust2smp[i] = i;
268 }
269
270 /* Create the array of associativity bewteen core ids and MPI process ids */
271 /* Rq: We could use a MPI reduction for irregular pattern */
272 MALLOC_INTERN(ctrl->core2clust, ctrl->total_nbcores, pastix_int_t);
273 for(i=0; i < ctrl->total_nbcores; i++) {
274 ctrl->core2clust[i] = i / ctrl->local_nbcores;
275 }
276
277 ctrl->etree = NULL;
278 ctrl->costmtx = NULL;
279 ctrl->candtab = NULL;
280
281#ifdef PASTIX_DYNSCHED
282 MALLOC_INTERN(ctrl->btree, 1, BubbleTree);
283#endif
284
285 return PASTIX_SUCCESS;
286}
287
288
289/**
290 *******************************************************************************
291 *
292 * @ingroup blend_dev_ctrl
293 *
294 * @brief Finalize the Blend control structure.
295 *
296 *******************************************************************************
297 *
298 * @param[inout] ctrl
299 * The Blend control data structure to free.
300 *
301 *******************************************************************************/
302void
304{
305 if(ctrl->clust2smp) {
306 memFree_null(ctrl->clust2smp);
307 }
308 if(ctrl->core2clust) {
309 memFree_null(ctrl->core2clust);
310 }
311 if(ctrl->candtab) {
312 candExit( ctrl->candtab );
313 ctrl->candtab = NULL;
314 }
315}
BEGIN_C_DECLS typedef int pastix_int_t
Definition datatypes.h:51
void candExit(Cand *candtab)
Exit and free the candtab structure given.
Definition cand.c:83
pastix_int_t * core2clust
Definition blendctrl.h:79
pastix_int_t up_after_split
Definition blendctrl.h:55
pastix_int_t leader
Definition blendctrl.h:34
pastix_int_t ricar
Definition blendctrl.h:33
EliminTree * etree
Definition blendctrl.h:96
pastix_int_t * clust2smp
Definition blendctrl.h:77
pastix_int_t debug
Definition blendctrl.h:30
pastix_int_t local_nbcores
Definition blendctrl.h:74
pastix_int_t allcand
Definition blendctrl.h:40
pastix_int_t costlevel
Definition blendctrl.h:43
double * dparm
Definition blendctrl.h:87
pastix_int_t width_tasks2d
Definition blendctrl.h:63
const char * dirname
Definition blendctrl.h:88
pastix_int_t clustnbr
Definition blendctrl.h:71
pastix_int_t clustnum
Definition blendctrl.h:70
pastix_int_t blcolmin
Definition blendctrl.h:50
pastix_int_t blcolmax
Definition blendctrl.h:51
pastix_int_t local_nbctxts
Definition blendctrl.h:76
Cand * candtab
Definition blendctrl.h:98
pastix_int_t level_tasks2d
Definition blendctrl.h:62
pastix_int_t local_nbthrds
Definition blendctrl.h:75
pastix_int_t timer
Definition blendctrl.h:31
CostMatrix * costmtx
Definition blendctrl.h:97
pastix_int_t total_nbcores
Definition blendctrl.h:72
pastix_int_t count_ops
Definition blendctrl.h:29
pastix_int_t total_nbthrds
Definition blendctrl.h:73
pastix_int_t nocrossproc
Definition blendctrl.h:41
pastix_int_t * iparm
Definition blendctrl.h:86
int blendCtrlInit(pastix_data_t *pastix_data, BlendCtrl *ctrl)
Initialize the Blend control structure.
Definition blendctrl.c:162
void getCommunicationCosts(const BlendCtrl *ctrl, pastix_int_t clustsrc, pastix_int_t clustdst, pastix_int_t sync_comm_nbr, double *startup, double *bandwidth)
Return the communication cost between two cores.
Definition blendctrl.c:60
void blendCtrlExit(BlendCtrl *)
Finalize the Blend control structure.
Definition blendctrl.c:303
The type and structure definitions.
Definition blendctrl.h:28
void pastix_gendirectories(pastix_data_t *pastix_data)
Generate a unique temporary directory to store output files.
Definition api.c:85
@ IPARM_TASKS2D_LEVEL
Definition api.h:90
@ IPARM_MIN_BLOCKSIZE
Definition api.h:88
@ IPARM_TASKS2D_WIDTH
Definition api.h:91
@ IPARM_VERBOSE
Definition api.h:36
@ IPARM_MAX_BLOCKSIZE
Definition api.h:89
@ IPARM_ALLCAND
Definition api.h:92
@ IPARM_INCOMPLETE
Definition api.h:95
@ IPARM_THREAD_NBR
Definition api.h:118
@ PASTIX_SUCCESS
Definition api.h:367
@ PASTIX_ERR_BADPARAMETER
Definition api.h:374
int inter_node_procnum
Definition pastixdata.h:84
int inter_node_procnbr
Definition pastixdata.h:83
pastix_int_t * iparm
Definition pastixdata.h:70
char * dir_local
Definition pastixdata.h:111
double * dparm
Definition pastixdata.h:71
Main PaStiX data structure.
Definition pastixdata.h:68