FrontISTR 5.2.0
Large-scale structural analysis program with finit element method
Loading...
Searching...
No Matches
hecmw_part_log.c
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright (c) 2019 FrontISTR Commons
3 * This software is released under the MIT License, see LICENSE.txt
4 *****************************************************************************/
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include <errno.h>
10
11#include "hecmw_msgno.h"
12#include "hecmw_error.h"
13#include "hecmw_malloc.h"
14#include "hecmw_part_define.h"
15#include "hecmw_part_log.h"
16
17static int is_init = 0;
18
19static int n_node_g = 0;
20
21static int n_elem_g = 0;
22
23static int *n_node = NULL;
24
25static int *nn_internal = NULL;
26
27static int *n_elem = NULL;
28
29static int *ne_internal = NULL;
30
31static int *n_neighbor_pe = NULL;
32
33static int n_domain = 0;
34
35static int depth = 0;
36
37static long long int n_edge = 0;
38
39static int n_edgecut = 0;
40
41static char part_type[HECMW_NAME_LEN] = "";
42
43static char part_method[HECMW_NAME_LEN] = "";
44
45static char part_contact[HECMW_NAME_LEN] = "";
46
47/*================================================================================================*/
48
49static void clean_log(void) {
50 HECMW_free(n_node);
51 HECMW_free(n_elem);
52 HECMW_free(nn_internal);
53 HECMW_free(ne_internal);
54 HECMW_free(n_neighbor_pe);
55
56 n_node = NULL;
57 n_elem = NULL;
58 nn_internal = NULL;
59 ne_internal = NULL;
60
61 is_init = 0;
62 n_node_g = 0;
63 n_elem_g = 0;
64 n_domain = 0;
65 depth = 0;
66 n_edge = 0;
67 n_edgecut = 0;
68 memset(part_type, '\0', HECMW_NAME_LEN);
69 memset(part_method, '\0', HECMW_NAME_LEN);
70}
71
72extern int HECMW_part_init_log(int _n_domain) {
73 if (is_init) {
75 return 0;
76 } else {
77 is_init = 1;
78 }
79
80 if (_n_domain < 1) {
82 goto error;
83 }
84
85 n_domain = _n_domain;
86
87 n_node = (int *)HECMW_calloc(n_domain, sizeof(int));
88 if (n_node == NULL) {
89 HECMW_set_error(errno, "");
90 goto error;
91 }
92
93 n_elem = (int *)HECMW_calloc(n_domain, sizeof(int));
94 if (n_elem == NULL) {
95 HECMW_set_error(errno, "");
96 goto error;
97 }
98
99 nn_internal = (int *)HECMW_calloc(n_domain, sizeof(int));
100 if (nn_internal == NULL) {
101 HECMW_set_error(errno, "");
102 goto error;
103 }
104
105 ne_internal = (int *)HECMW_calloc(n_domain, sizeof(int));
106 if (ne_internal == NULL) {
107 HECMW_set_error(errno, "");
108 goto error;
109 }
110
111 n_neighbor_pe = (int *)HECMW_calloc(n_domain, sizeof(int));
112 if (n_neighbor_pe == NULL) {
113 HECMW_set_error(errno, "");
114 goto error;
115 }
116
117 return 0;
118
119error:
120 return -1;
121}
122
123/*================================================================================================*/
124
125extern int HECMW_part_set_log_part_type(int _part_type) {
126 if (is_init == 0) {
128 goto error;
129 }
130
131 switch (_part_type) {
133 strcpy(part_type, "NODE-BASED");
134 break;
135
137 strcpy(part_type, "ELEMENT-BASED");
138 break;
139
140 default:
142 goto error;
143 }
144
145 return 0;
146
147error:
148 return -1;
149}
150
151extern int HECMW_part_set_log_part_method(int _part_method) {
152 if (is_init == 0) {
154 return -1;
155 }
156
157 switch (_part_method) {
159 strcpy(part_method, "RCB");
160 break;
161
163 strcpy(part_method, "kMETIS");
164 break;
165
167 strcpy(part_method, "pMETIS");
168 break;
169
170 default:
172 return -1;
173 }
174
175 return 0;
176}
177
178extern int HECMW_part_set_log_part_depth(int _depth) {
179 if (is_init == 0) {
181 return -1;
182 }
183
184 if (_depth < 1) {
186 return -1;
187 }
188
189 depth = _depth;
190
191 return 0;
192}
193
194extern int HECMW_part_set_log_part_contact(int _part_contact) {
195 if (is_init == 0) {
197 return -1;
198 }
199
200 switch (_part_contact) {
202 strcpy(part_contact, "AGGREGATE");
203 break;
204
206 strcpy(part_contact, "DISTRIBUTE");
207 break;
208
210 strcpy(part_contact, "SIMPLE");
211 break;
212
214 strcpy(part_contact, "DEFAULT");
215 break;
216
217 default:
218 strcpy(part_contact, "not set");
219 break;
220 }
221
222 return 0;
223}
224
225extern int HECMW_part_set_log_n_edgecut(long long int _n_edge, int _n_edgecut) {
226 if (is_init == 0) {
228 return -1;
229 }
230
231 if (_n_edgecut < 0) {
233 return -1;
234 }
235
236 if (_n_edge < 1) {
238 return -1;
239 }
240
241 n_edge = _n_edge;
242 n_edgecut = _n_edgecut;
243
244 return 0;
245}
246
247extern int HECMW_part_set_log_n_node_g(int _n_node_g) {
248 if (is_init == 0) {
250 return -1;
251 }
252
253 if (_n_node_g < 1) {
254 HECMW_set_error(HECMW_PART_E_NNODE_MIN, "%d", _n_node_g);
255 return -1;
256 }
257
258 n_node_g = _n_node_g;
259
260 return 0;
261}
262
263extern int HECMW_part_set_log_n_elem_g(int _n_elem_g) {
264 if (is_init == 0) {
266 return -1;
267 }
268
269 if (_n_elem_g < 1) {
270 HECMW_set_error(HECMW_PART_E_NELEM_MIN, "%d", _n_elem_g);
271 return -1;
272 }
273
274 n_elem_g = _n_elem_g;
275
276 return 0;
277}
278
279extern int HECMW_part_set_log_n_node(int domain, int _n_node) {
280 if (is_init == 0) {
282 return -1;
283 }
284
285 if (domain < 0) {
287 return -1;
288 }
289 if (domain >= n_domain) {
291 return -1;
292 }
293
294 if (_n_node < 1) {
296 return -1;
297 }
298
299 n_node[domain] = _n_node;
300
301 return 0;
302}
303
304extern int HECMW_part_set_log_n_elem(int domain, int _n_elem) {
305 if (is_init == 0) {
307 return -1;
308 }
309
310 if (domain < 0) {
312 return -1;
313 }
314 if (domain >= n_domain) {
316 return -1;
317 }
318
319 if (_n_elem < 1) {
321 return -1;
322 }
323
324 n_elem[domain] = _n_elem;
325
326 return 0;
327}
328
329extern int HECMW_part_set_log_nn_internal(int domain, int _nn_internal) {
330 if (is_init == 0) {
332 return -1;
333 }
334
335 if (domain < 0) {
337 return -1;
338 }
339 if (domain >= n_domain) {
341 return -1;
342 }
343
344 if (_nn_internal < 0) {
346 return -1;
347 }
348 if (_nn_internal > n_node[domain]) {
350 return -1;
351 }
352
353 nn_internal[domain] = _nn_internal;
354
355 return 0;
356}
357
358extern int HECMW_part_set_log_ne_internal(int domain, int _ne_internal) {
359 if (is_init == 0) {
361 return -1;
362 }
363
364 if (domain < 0) {
366 return -1;
367 }
368 if (domain >= n_domain) {
370 return -1;
371 }
372
373 if (_ne_internal < 0) {
374 HECMW_set_error(HECMW_PART_E_NEINT_MIN, "%d", _ne_internal);
375 return -1;
376 }
377
378 if (_ne_internal > n_elem[domain]) {
379 HECMW_set_error(HECMW_PART_E_NEINT_MAX, "%d", _ne_internal);
380 return -1;
381 }
382
383 ne_internal[domain] = _ne_internal;
384
385 return 0;
386}
387
388extern int HECMW_part_set_log_n_neighbor_pe(int domain, int _n_neighbor_pe) {
389 if (is_init == 0) {
391 return -1;
392 }
393
394 if (domain < 0) {
396 return -1;
397 }
398 if (domain >= n_domain) {
400 return -1;
401 }
402
403 if (_n_neighbor_pe < 0) {
405 return -1;
406 }
407
408 n_neighbor_pe[domain] = _n_neighbor_pe;
409
410 return 0;
411}
412
413/*================================================================================================*/
414
415extern int HECMW_part_print_log(void) {
416 int i;
417 FILE *fp;
418
419 if (is_init == 0) {
421 return -1;
422 }
423
424 if ((fp = fopen(HECMW_PART_LOG_NAME, "w")) == NULL) {
425 HECMW_set_error(errno, "log file for partitioner");
426 return -1;
427 }
428
429 fprintf(fp, "# log file for partitioner ( %s )\n", HECMW_get_date());
430 fprintf(fp, "\n");
431
432 /* conditions */
433 fprintf(fp, "# conditions\n");
434 fprintf(fp, "number of sub-domains : %d\n", n_domain);
435 fprintf(fp, "partitioning type : %s\n", part_type);
436 fprintf(fp, "partitioning method : %s\n", part_method);
437 fprintf(fp, "depth of overlapping : %d\n", depth);
438 fprintf(fp, "contact partitioning : %s\n", part_contact);
439 if (n_domain == 1) {
440 fprintf(fp, "number of edgecut : ----- / -----\n");
441 } else {
442 fprintf(fp, "number of edgecut : %d / %lld\n", n_edgecut, n_edge);
443 }
444
445 fprintf(fp, "\n");
446
447 /* information of entire mesh */
448 fprintf(fp, "# information of entire mesh\n");
449 fprintf(fp, "number of nodes : %d\n", n_node_g);
450 fprintf(fp, "number of elements : %d\n", n_elem_g);
451
452 fprintf(fp, "\n");
453
454 /* information of distributed mesh */
455 fprintf(fp, "# information of distributed mesh\n");
456 fprintf(fp, "domain, nodes, int. nodes, elems, int. elems, neighbor PE\n");
457
458 for (i = 0; i < n_domain; i++) {
459 fprintf(fp, "%6d %12d %12d %12d %12d %12d\n", i, n_node[i], nn_internal[i],
460 n_elem[i], ne_internal[i], n_neighbor_pe[i]);
461 }
462
463 /* close file */
464 if (fclose(fp)) {
465 HECMW_set_error(HECMW_PART_E_FILE_CLOSE, "log file for partitioner");
466 return -1;
467 }
468
469 return 0;
470}
471
472extern void HECMW_part_finalize_log(void) { clean_log(); }
#define HECMW_NAME_LEN
Definition: hecmw_config.h:70
int HECMW_set_error(int errorno, const char *fmt,...)
Definition: hecmw_error.c:37
#define NULL
int HECMW_log(int loglv, const char *fmt,...)
Definition: hecmw_log.c:260
#define HECMW_LOG_WARN
Definition: hecmw_log.h:17
#define HECMW_calloc(nmemb, size)
Definition: hecmw_malloc.h:21
#define HECMW_free(ptr)
Definition: hecmw_malloc.h:24
char * HECMW_strmsg(int msgno)
Definition: hecmw_msg.c:31
#define HECMW_PART_E_NEDGECUT_LOWER
#define HECMW_PART_E_DOMAIN_MIN
#define HECMW_PART_E_FILE_CLOSE
#define HECMW_PART_METHOD_PMETIS
#define HECMW_PART_E_NEDGECUTA_LOWER
#define HECMW_PART_E_NELEM_MIN
#define HECMW_PART_E_NNODE_MIN
#define HECMW_PART_E_DOMAIN_MAX
#define HECMW_PART_E_INVALID_NDOMAIN
#define HECMW_PART_E_INVALID_PMETHOD
#define HECMW_PART_E_INVALID_PTYPE
#define HECMW_PART_METHOD_RCB
#define HECMW_PART_E_NNINT_MIN
#define HECMW_PART_LOG_NAME
#define HECMW_PART_CONTACT_DEFAULT
#define HECMW_PART_W_LOG_INIT_ALREADY
#define HECMW_PART_E_INVALID_PDEPTH
#define HECMW_PART_TYPE_NODE_BASED
#define HECMW_PART_METHOD_KMETIS
#define HECMW_PART_CONTACT_DISTRIBUTE
#define HECMW_PART_CONTACT_SIMPLE
#define HECMW_PART_E_NNINT_MAX
#define HECMW_PART_CONTACT_AGGREGATE
#define HECMW_PART_E_NEINT_MAX
#define HECMW_PART_E_NNEIGHBORPE_LOWER
#define HECMW_PART_E_LOG_INIT_NOT_YET
#define HECMW_PART_E_NEINT_MIN
#define HECMW_PART_TYPE_ELEMENT_BASED
int HECMW_part_set_log_n_neighbor_pe(int domain, int _n_neighbor_pe)
int HECMW_part_set_log_part_contact(int _part_contact)
int HECMW_part_set_log_part_type(int _part_type)
void HECMW_part_finalize_log(void)
int HECMW_part_set_log_n_node_g(int _n_node_g)
int HECMW_part_set_log_part_depth(int _depth)
int HECMW_part_set_log_n_node(int domain, int _n_node)
int HECMW_part_set_log_n_elem(int domain, int _n_elem)
int HECMW_part_init_log(int _n_domain)
int HECMW_part_print_log(void)
int HECMW_part_set_log_n_edgecut(long long int _n_edge, int _n_edgecut)
int HECMW_part_set_log_nn_internal(int domain, int _nn_internal)
int HECMW_part_set_log_n_elem_g(int _n_elem_g)
int HECMW_part_set_log_part_method(int _part_method)
int HECMW_part_set_log_ne_internal(int domain, int _ne_internal)
char * HECMW_get_date(void)
Definition: hecmw_util.c:29