FrontISTR  6.0.0
Large-scale structural analysis program with finit element method
matrix_repart.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 "hecmw_util.h"
9 
10 #ifdef HECMW_WITH_METIS
11 #include "metis.h"
12 #endif
13 
14 #include "matrix2graph.h"
15 #include "separator.h"
17 
18 void bi_part_directive(int *neqns, int *nttbr, int *irow, int *jcol,
19  int *num_graph1, int *num_graph2, int *num_separator) {
20 #ifdef HECMW_WITH_METIS
21  graph_type *graph;
22  int num_of_row, num_of_col, num_of_nzero;
23 
24  int *perm, *iperm;
25 
26  num_of_row = *neqns;
27  num_of_col = *neqns;
28  num_of_nzero = *nttbr;
29 
30  graph = (graph_type *)malloc(sizeof(graph_type));
31  if (graph == NULL) separator_memory_exit("graph");
32 
33  fprintf(stderr, "Start transforming matrix to graph\n");
34  matrix2graph(num_of_row, num_of_col, num_of_nzero, irow, jcol, graph);
35  fprintf(stderr,
36  "Graph Information "
37  "---------------------------------------------------\n");
38  fprintf(stderr, "#Vertices: %d, #Edges: %d\n\n", graph->nvtxs,
39  graph->nedges / 2);
40  perm = (int *)calloc(num_of_col, sizeof(int));
41  iperm = (int *)calloc(num_of_col, sizeof(int));
42  if ((perm == NULL) || (iperm == NULL))
43  separator_memory_exit("matrix_repart: perm, iperm");
44 
45  {
46  /* The graph and the permutation are sized by the number of equations, so
47  * they stay int; idx_t copies are needed only because METIS 5 takes them */
48  idx_t options[METIS_NOPTIONS];
49  idx_t nvtxs_metis = graph->nvtxs;
50  idx_t *xadj_metis, *adjncy_metis, *perm_metis, *iperm_metis;
51  int i;
52 
53  xadj_metis = (idx_t *)calloc(num_of_col + 1, sizeof(idx_t));
54  adjncy_metis = (idx_t *)calloc(graph->nedges, sizeof(idx_t));
55  perm_metis = (idx_t *)calloc(num_of_col, sizeof(idx_t));
56  iperm_metis = (idx_t *)calloc(num_of_col, sizeof(idx_t));
57  if ((xadj_metis == NULL) || (adjncy_metis == NULL) ||
58  (perm_metis == NULL) || (iperm_metis == NULL))
59  separator_memory_exit("matrix_repart: metis arrays");
60 
61  for (i = 0; i <= num_of_col; i++) xadj_metis[i] = graph->xadj[i];
62  for (i = 0; i < graph->nedges; i++) adjncy_metis[i] = graph->adjncy[i];
63 
64  METIS_SetDefaultOptions(options);
65  options[METIS_OPTION_COMPRESS] = 0;
66  METIS_NodeND(&nvtxs_metis, xadj_metis, adjncy_metis, NULL, options,
67  perm_metis, iperm_metis);
68 
69  for (i = 0; i < num_of_col; i++) {
70  perm[i] = (int)perm_metis[i];
71  iperm[i] = (int)iperm_metis[i];
72  }
73 
74  free(xadj_metis);
75  free(adjncy_metis);
76  free(perm_metis);
77  free(iperm_metis);
78  }
79  /* copy to separator */
80 
81  *num_graph1 = separator->num_of_lgraph;
82  *num_graph2 = separator->num_of_rgraph;
83  *num_separator = separator->num_of_separator;
84 
85  free(perm);
86  free(iperm);
87  free(graph->xadj);
88  free(graph->adjncy);
89  free(graph);
90 
91 #else
92  fprintf(
93  stderr,
94  "Error: Direct Parallel Solver not available. Please install Metis.\n");
96 #endif
97 
98  return;
99 }
100 
101 void bi_part_directive_(int *neqns, int *nttbr, int *irow, int *jcol,
102  int *num_graph1, int *num_graph2, int *num_separator) {
103  bi_part_directive(neqns, nttbr, irow, jcol, num_graph1, num_graph2,
104  num_separator);
105 }
106 
107 void bi_part_directive__(int *neqns, int *nttbr, int *irow, int *jcol,
108  int *num_graph1, int *num_graph2, int *num_separator) {
109  bi_part_directive(neqns, nttbr, irow, jcol, num_graph1, num_graph2,
110  num_separator);
111 }
112 
113 void BI_PART_DIRECTIVE(int *neqns, int *nttbr, int *irow, int *jcol,
114  int *num_graph1, int *num_graph2, int *num_separator) {
115  bi_part_directive(neqns, nttbr, irow, jcol, num_graph1, num_graph2,
116  num_separator);
117 }
HECMW_Comm HECMW_comm_get_comm(void)
Definition: hecmw_comm.c:751
#define NULL
void HECMW_abort(HECMW_Comm comm)
Definition: hecmw_util.c:88
long long idx_t
struct option_rec options[]
specify command line option name and executing function name.
Definition: main.c:283
void matrix2graph(int num_of_row, int num_of_col, int num_of_nzero, int *irow, int *jcol, graph_type *graph)
Definition: matrix2graph.c:12
Separator_result * separator
Definition: matrix_repart.c:16
void bi_part_directive__(int *neqns, int *nttbr, int *irow, int *jcol, int *num_graph1, int *num_graph2, int *num_separator)
void bi_part_directive(int *neqns, int *nttbr, int *irow, int *jcol, int *num_graph1, int *num_graph2, int *num_separator)
Definition: matrix_repart.c:18
void bi_part_directive_(int *neqns, int *nttbr, int *irow, int *jcol, int *num_graph1, int *num_graph2, int *num_separator)
void BI_PART_DIRECTIVE(int *neqns, int *nttbr, int *irow, int *jcol, int *num_graph1, int *num_graph2, int *num_separator)
void separator_memory_exit(char *var)
Definition: mem_util.c:10
int * xadj
Definition: matrix2graph.h:13
int * adjncy
Definition: matrix2graph.h:14