FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecmw_dlb_mesh2graph.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 "hecmw_repart.h"
7 
8 void find_new_v8(int new_v8[24]) {
9  new_v8[0] = 1;
10  new_v8[1] = 3;
11  new_v8[2] = 4;
12  new_v8[1 * 3] = 0;
13  new_v8[1 * 3 + 1] = 2;
14  new_v8[1 * 3 + 2] = 5;
15  new_v8[2 * 3] = 1;
16  new_v8[2 * 3 + 1] = 3;
17  new_v8[2 * 3 + 2] = 6;
18  new_v8[3 * 3] = 0;
19  new_v8[3 * 3 + 1] = 2;
20  new_v8[3 * 3 + 2] = 7;
21  new_v8[4 * 3] = 0;
22  new_v8[4 * 3 + 1] = 5;
23  new_v8[4 * 3 + 2] = 7;
24  new_v8[5 * 3] = 1;
25  new_v8[5 * 3 + 1] = 4;
26  new_v8[5 * 3 + 2] = 6;
27  new_v8[6 * 3] = 2;
28  new_v8[6 * 3 + 1] = 5;
29  new_v8[6 * 3 + 2] = 7;
30  new_v8[7 * 3] = 3;
31  new_v8[7 * 3 + 1] = 4;
32  new_v8[7 * 3 + 2] = 6;
33  return;
34 }
35 
36 void find_new_v6(int new_v6[18]) {
37  new_v6[0] = 1;
38  new_v6[1] = 2;
39  new_v6[2] = 3;
40  new_v6[1 * 3] = 0;
41  new_v6[1 * 3 + 1] = 2;
42  new_v6[1 * 3 + 2] = 4;
43  new_v6[2 * 3] = 0;
44  new_v6[2 * 3 + 1] = 1;
45  new_v6[2 * 3 + 2] = 5;
46  new_v6[3 * 3] = 0;
47  new_v6[3 * 3 + 1] = 4;
48  new_v6[3 * 3 + 2] = 5;
49  new_v6[4 * 3] = 1;
50  new_v6[4 * 3 + 1] = 3;
51  new_v6[4 * 3 + 2] = 5;
52  new_v6[5 * 3] = 2;
53  new_v6[5 * 3 + 1] = 3;
54  new_v6[5 * 3 + 2] = 4;
55  return;
56 }
57 
58 void find_new_v4(int new_v4[12]) {
59  new_v4[0] = 1;
60  new_v4[1] = 2;
61  new_v4[2] = 3;
62  new_v4[1 * 3] = 0;
63  new_v4[1 * 3 + 1] = 2;
64  new_v4[1 * 3 + 2] = 3;
65  new_v4[2 * 3] = 0;
66  new_v4[2 * 3 + 1] = 1;
67  new_v4[2 * 3 + 2] = 3;
68  new_v4[3 * 3] = 0;
69  new_v4[3 * 3 + 1] = 1;
70  new_v4[3 * 3 + 2] = 2;
71  return;
72 }
73 
74 void add8_adj_link(Adj_find *adj_link, int id_elem,
75  struct hecmwST_local_mesh *mesh, int new_v8[24]) {
76  Adj_find *p1, *p2;
77  int i, k, m;
78  long long j;
79  int new_v, id_node, flag_hit;
80  long long ncon;
81 
82  ncon = mesh->elem_node_index[id_elem + 1] - mesh->elem_node_index[id_elem];
83  if (ncon != 8)
85  "The type of element is conflict with its index: data error\n");
86  for (j = mesh->elem_node_index[id_elem];
87  j < mesh->elem_node_index[id_elem + 1]; j++) {
88  id_node = mesh->elem_node_item[j] - 1;
89  if ((id_node > mesh->n_node) || (id_node < 0))
90  HECMW_dlb_print_exit("There is something wrong in index_elem\n");
91  if (id_node < mesh->nn_internal) {
92  for (k = 0; k < 3; k++) {
93  new_v = mesh->elem_node_item
94  [mesh->elem_node_index[id_elem] +
95  new_v8[(j - mesh->elem_node_index[id_elem]) * 3 + k]] -
96  1;
97  flag_hit = 0;
98  p1 = adj_link[id_node].next_vertex;
99  for (m = 0; m < adj_link[id_node].vertex_num; m++) {
100  if (new_v == p1->vertex_num) {
101  flag_hit = 1;
102  break;
103  }
104  p1 = p1->next_vertex;
105  }
106  if (flag_hit == 0) { /* adding the vertex new_v */
107  p1 = (Adj_find *)malloc(sizeof(Adj_find));
108  if (p1 == NULL) {
109  fprintf(stderr, "There is no enough memory for p1 in adj_link\n");
110  exit(EXIT_FAILURE);
111  }
112  p2 = adj_link[id_node].next_vertex;
113  adj_link[id_node].vertex_num++;
114  adj_link[id_node].next_vertex = p1;
115  p1->next_vertex = p2;
116  p1->vertex_num = new_v;
117  }
118  }
119  }
120  }
121  return;
122 }
123 
124 void add6_adj_link(Adj_find *adj_link, int id_elem,
125  struct hecmwST_local_mesh *mesh, int new_v6[18]) {
126  Adj_find *p1, *p2;
127  int i, k, m;
128  long long j;
129  int new_v, id_node, flag_hit;
130  long long ncon;
131 
132  ncon = mesh->elem_node_index[id_elem + 1] - mesh->elem_node_index[id_elem];
133  if (ncon != 6)
135  "The type of element is conflict with its index: data error\n");
136  for (j = mesh->elem_node_index[id_elem];
137  j < mesh->elem_node_index[id_elem + 1]; j++) {
138  id_node = mesh->elem_node_item[j] - 1;
139  if ((id_node >= mesh->n_node) || (id_node < 0))
140  HECMW_dlb_print_exit("There is something wrong in index_elem\n");
141  if (id_node < mesh->nn_internal) {
142  for (k = 0; k < 3; k++) {
143  new_v = mesh->elem_node_item
144  [mesh->elem_node_index[id_elem] +
145  new_v6[(j - mesh->elem_node_index[id_elem]) * 3 + k]] -
146  1;
147  flag_hit = 0;
148  p1 = adj_link[id_node].next_vertex;
149  for (m = 0; m < adj_link[id_node].vertex_num; m++) {
150  if (new_v == p1->vertex_num) {
151  flag_hit = 1;
152  break;
153  }
154  p1 = p1->next_vertex;
155  }
156  if (flag_hit == 0) { /* adding the vertex new_v */
157  p1 = (Adj_find *)malloc(sizeof(Adj_find));
158  if (p1 == NULL) {
159  fprintf(stderr, "There is no enough memory for p1 in adj_link\n");
160  exit(EXIT_FAILURE);
161  }
162  p2 = adj_link[id_node].next_vertex;
163  adj_link[id_node].vertex_num++;
164  adj_link[id_node].next_vertex = p1;
165  p1->next_vertex = p2;
166  p1->vertex_num = new_v;
167  }
168  }
169  }
170  }
171  return;
172 }
173 
174 void add4_adj_link(Adj_find *adj_link, int id_elem,
175  struct hecmwST_local_mesh *mesh, int new_v4[12]) {
176  Adj_find *p1, *p2;
177  int i, k, m;
178  long long j;
179  int new_v, id_node, flag_hit;
180  long long ncon;
181 
182  ncon = mesh->elem_node_index[id_elem + 1] - mesh->elem_node_index[id_elem];
183  if (ncon != 4)
185  "The type of element is conflict with its index: data error\n");
186  for (j = mesh->elem_node_index[id_elem];
187  j < mesh->elem_node_index[id_elem + 1]; j++) {
188  id_node = mesh->elem_node_item[j] - 1;
189  if ((id_node >= mesh->n_node) || (id_node < 0))
190  HECMW_dlb_print_exit("There is something wrong in index_elem\n");
191  if (id_node < mesh->nn_internal) {
192  for (k = 0; k < 3; k++) {
193  new_v = mesh->elem_node_item
194  [mesh->elem_node_index[id_elem] +
195  new_v4[(j - mesh->elem_node_index[id_elem]) * 3 + k]] -
196  1;
197  flag_hit = 0;
198  p1 = adj_link[id_node].next_vertex;
199  for (m = 0; m < adj_link[id_node].vertex_num; m++) {
200  if (new_v == p1->vertex_num) {
201  flag_hit = 1;
202  break;
203  }
204  p1 = p1->next_vertex;
205  }
206  if (flag_hit == 0) { /* adding the vertex new_v */
207  p1 = (Adj_find *)malloc(sizeof(Adj_find));
208  if (p1 == NULL) HECMW_dlb_memory_exit("Adj_find: p1");
209  p2 = adj_link[id_node].next_vertex;
210  adj_link[id_node].vertex_num++;
211  adj_link[id_node].next_vertex = p1;
212  p1->next_vertex = p2;
213  p1->vertex_num = new_v;
214  }
215  }
216  }
217  }
218  return;
219 }
220 
221 void adj_link_free(Adj_find *adj_link, int num) {
222  Adj_find *p1, *p2;
223  int i, j;
224  for (i = 0; i < num; i++) {
225  p1 = adj_link[i].next_vertex;
226  for (j = 0; j < adj_link[i].vertex_num; j++) {
227  p2 = p1;
228  p1 = p1->next_vertex;
229  free(p2);
230  }
231  }
232  free(adj_link);
233  return;
234 }
235 
236 void mesh2graph(struct hecmwST_local_mesh *mesh, GraphType *graph,
237  Control_para *ctl_para, int stat_para[NUM_CONTROL_PARAS],
239  int i, j, k, m;
240  int mynode, pesize;
241  Adj_find *adj_link;
242  Adj_find *p1, *p2;
243  int new_v8[3 * 8], new_v4[3 * 4], new_v6[3 * 6];
244  int nvtxs = 0, nedges = 0, global_num_node = 0;
245 
246  int readew = -1, readvw = -1, dummy, edge;
247  int *vtxdist, *xadj, *adjncy, *vwgts, *adjwgts;
248  int wgtflag, numflag, ncon, nparts, edgecut, options[4];
249  float *tpwgts, *ubvec, itr;
250  HECMW_Status stat;
251  int *tmp_index, tmp_nvtxs, tmp_sum, tmp_pe, tmp_lid;
252  FILE *fp_test, *fp_wgts;
253  char test_file[128];
254  float *xyz;
255  int ndim;
256  int tmp_int;
257  int flag_count;
258 
259  HECMW_Comm_rank(repart_comm, &mynode);
260  HECMW_Comm_size(repart_comm, &pesize);
261  /*
262  mynode=mesh->my_rank;
263  pesize=mesh->PEtotMESH;
264  */
265  /*
266  fprintf(stderr, "In PE %d pesize=%d\n", mynode, pesize);
267  fprintf(stderr, "wgtflag=%d \n", ctl_para->wgtflag);
268  fprintf(stderr, "ncon=%d\n", ctl_para->num_repartition);
269  */
270  if (mynode == 0)
271  fprintf(stderr,
272  "Start transform original mesh data into graph structure of "
273  "ParMetis\n");
274 
275  if (pesize > 1)
276  HECMW_Allreduce(&mesh->nn_internal, &global_num_node, 1, HECMW_INT,
278  else
279  global_num_node = mesh->nn_internal;
280  /*
281  fprintf(stderr, "the global node number is %d\n", global_num_node);
282  */
283  result->t_node = global_num_node;
284  nvtxs = mesh->nn_internal;
285  graph->vtxdist = (int *)calloc((pesize + 1), sizeof(int));
286  if (graph->vtxdist == NULL) HECMW_dlb_memory_exit("graph->vtxdist");
287  if (mynode == 0) {
288  graph->vtxdist[0] = 0;
289  graph->vtxdist[1] = nvtxs;
290  tmp_sum = nvtxs;
291  for (i = 1; i < pesize; i++) {
292  HECMW_Recv(&tmp_nvtxs, 1, HECMW_INT, i, HECMW_ANY_TAG, repart_comm,
293  &stat);
294  tmp_sum += tmp_nvtxs;
295  graph->vtxdist[i + 1] = tmp_sum;
296  }
297  for (i = 1; i < pesize; i++)
298  HECMW_Send(graph->vtxdist, pesize + 1, HECMW_INT, i, 0, repart_comm);
299  } else {
300  HECMW_Send(&nvtxs, 1, HECMW_INT, 0, 0, repart_comm);
301  HECMW_Recv(graph->vtxdist, pesize + 1, HECMW_INT, 0, HECMW_ANY_TAG,
302  repart_comm, &stat);
303  }
304  /*
305  if(mynode==0) {
306  for(i=0;i<pesize+1;i++)
307  fprintf(stderr, "vtxdist=%d ", graph->vtxdist[i]);
308  fprintf(stderr, "\n");
309  }
310  */
311 
312  adj_link = (Adj_find *)calloc(mesh->nn_internal, sizeof(Adj_find));
313  if (adj_link == NULL) HECMW_dlb_memory_exit("adj_link");
314  for (i = 0; i < mesh->nn_internal; i++) adj_link[i].vertex_num = 0;
315  find_new_v8(new_v8);
316  find_new_v6(new_v6);
317  find_new_v4(new_v4);
318  for (i = 0; i < mesh->n_elem; i++) {
319  flag_count = 1;
320  if (mesh->hecmw_flag_adapt == 1) {
321  if (mesh->adapt_type[i] != 0) flag_count = 0;
322  }
323  if (flag_count == 1) {
324  if (mesh->elem_type[i] == 341)
325  add4_adj_link(adj_link, i, mesh, new_v4);
326  else if (mesh->elem_type[i] == 351)
327  add6_adj_link(adj_link, i, mesh, new_v6);
328  else if (mesh->elem_type[i] == 361)
329  add8_adj_link(adj_link, i, mesh, new_v8);
330  }
331  }
332  for (i = 0; i < mesh->nn_internal; i++) nedges += adj_link[i].vertex_num;
333  graph->xadj = (int *)calloc(nvtxs + 1, sizeof(int));
334  graph->adjncy = (int *)calloc(nedges, sizeof(int));
335  if ((graph->xadj == NULL) || (graph->adjncy == NULL))
336  HECMW_dlb_memory_exit("graph: xadj and adjncy");
337  m = 0;
338  graph->xadj[0] = 0;
339  for (i = 0; i < mesh->nn_internal; i++) {
340  graph->xadj[i + 1] = m + adj_link[i].vertex_num;
341  p1 = adj_link[i].next_vertex;
342  for (j = 0; j < adj_link[i].vertex_num; j++) {
343  if (p1->vertex_num < mesh->nn_internal)
344  graph->adjncy[m + j] = graph->vtxdist[mynode] + p1->vertex_num;
345  else {
346  tmp_pe = mesh->node_ID[p1->vertex_num * 2 + 1];
347  tmp_lid = mesh->node_ID[p1->vertex_num * 2] - 1;
348  graph->adjncy[m + j] = graph->vtxdist[tmp_pe] + tmp_lid;
349  }
350  p1 = p1->next_vertex;
351  }
352  m += adj_link[i].vertex_num;
353  }
354  adj_link_free(adj_link, mesh->nn_internal);
355  /*
356  sprintf(test_file, "test.%d", mynode);
357  fp_test=fopen(test_file, "w");
358  tmp_int=0;
359  for(i=0;i<mesh->n_internal;i++) {
360  fprintf(fp_test, "%d %d\n", i+1,
361  graph->xadj[i+1]-graph->xadj[i]);
362  if((graph->xadj[i+1]-graph->xadj[i])==27) {
363  tmp_int++;
364  fprintf(stderr, "the num of 27 edges is in PE %d
365  nodeid is %d\n", mynode, i+1);
366  }
367  for(j=graph->xadj[i];j<graph->xadj[i+1];j++)
368  fprintf(fp_test, "%d ", graph->adjncy[j]+1);
369  fprintf(fp_test, "\n");
370  }
371  fprintf(stderr, "the num of 27 edges is %d in PE %d\n",
372  tmp_int, mynode);
373  fclose(fp_test);
374  */
375  graph->gnvtxs = global_num_node;
376  graph->ncon = 0;
377  graph->nobj = 0;
378  wgtflag = ctl_para->wgtflag;
379  numflag = 0;
380  ncon = ctl_para->num_criteria;
381  nparts = ctl_para->num_repartition;
382  /* graph->vwgt=(int *)calloc(nvtxs, sizeof(int));
383  if(graph->vwgt==NULL) {
384  fprintf(stderr, "There is no enough memory for vwgt\n");
385  HECMW_Finalize();
386  exit(0);
387  }
388  for(i=0;i<nvtxs;i++)
389  graph->vwgt[i]=1;
390  */
391  /* tpwgts=(float *)calloc(pesize, sizeof(float));
392  if(tpwgts==NULL) {
393  fprintf(stderr, "There is no enough memory for tpwgts\n");
394  HECMW_Finalize();
395  exit(0);
396  }
397  for(i=0;i<pesize;i++)
398  tpwgts[i]=ctl_para;
399 
400  ubvec=(float *)calloc(ncon, sizeof(float));
401  if(ubvec==NULL)
402  HECMW_dlb_memory_exit("ubvec");
403  for(i=0;i<ncon;i++)
404  ubvec[i]=1.05;
405  */
406  options[0] = 1;
407  options[1] = 3;
408  options[2] = 1;
409  options[3] = 1;
410  edgecut = 0;
411  result->part = (int *)calloc(nvtxs, sizeof(int));
412  if (result->part == NULL) HECMW_dlb_memory_exit("result: part");
413 
414  /* xyz=(float *)calloc(mesh->n_internal*3, sizeof(float));
415  for(i=0;i<mesh->n_internal;i++) {
416  xyz[i*3]=(float)mesh->node[i];
417  xyz[i*3+1]=(float)mesh->node[i+mesh->n_node];
418  xyz[i*3+2]=(float)mesh->node[i+2*mesh->n_node];
419  }
420  ndim=3;
421  ParMETIS_V3_PartGeomKway(graph->vtxdist, graph->xadj, graph->adjncy, NULL,
422  NULL, &wgtflag,
423  &numflag, &ndim, xyz, &ncon, &nparts, tpwgts, ubvec, options,
424  &edgecut, result->part, &repart_comm);
425  result->edgecut=edgecut;
426  */
427  if (strncmp(ctl_para->adaptive_repartition, "off", 3) == 0) {
428  if (ctl_para->wgtflag == 0)
429  ParMETIS_V3_PartKway(graph->vtxdist, graph->xadj, graph->adjncy, NULL,
430  NULL, &(ctl_para->wgtflag), &numflag,
431  &(ctl_para->num_criteria),
432  &(ctl_para->num_repartition), ctl_para->machine_wgt,
433  ctl_para->balance_rate, options, &edgecut,
434  result->part, &repart_comm);
435  else if ((stat_para[6] != 0) && (stat_para[7] == 0)) {
436  vwgts = (int *)calloc(mesh->nn_internal, sizeof(int));
437  if (vwgts == NULL) HECMW_dlb_memory_exit("vwgts");
438  fp_wgts = fopen(ctl_para->vwgt_filename, "r");
439  if (fp_wgts == NULL) {
440  fprintf(stderr, "control file wrong: vwgt_filename\n");
441  exit(EXIT_FAILURE);
442  }
443  for (i = 0; i < mesh->nn_internal; i++) fscanf(fp_wgts, "%d", &vwgts[i]);
444  fclose(fp_wgts);
445  ParMETIS_V3_PartKway(graph->vtxdist, graph->xadj, graph->adjncy, vwgts,
446  NULL, &(ctl_para->wgtflag), &numflag,
447  &(ctl_para->num_criteria),
448  &(ctl_para->num_repartition), ctl_para->machine_wgt,
449  ctl_para->balance_rate, options, &edgecut,
450  result->part, &repart_comm);
451  free(vwgts);
452  } else if ((stat_para[6] == 0) && (stat_para[7] != 0)) {
453  adjwgts = (int *)calloc(graph->xadj[mesh->nn_internal], sizeof(int));
454  if (adjwgts == NULL) HECMW_dlb_memory_exit("adjwgts");
455  fp_wgts = fopen(ctl_para->adjwgt_filename, "r");
456  if (fp_wgts == NULL) {
457  fprintf(stderr, "control file wrong: adjwgt_filename\n");
458  exit(EXIT_FAILURE);
459  }
460  for (i = 0; i < graph->xadj[mesh->nn_internal]; i++)
461  fscanf(fp_wgts, "%d", &adjwgts[i]);
462  fclose(fp_wgts);
463  ParMETIS_V3_PartKway(graph->vtxdist, graph->xadj, graph->adjncy, NULL,
464  adjwgts, &(ctl_para->wgtflag), &numflag,
465  &(ctl_para->num_criteria),
466  &(ctl_para->num_repartition), ctl_para->machine_wgt,
467  ctl_para->balance_rate, options, &edgecut,
468  result->part, &repart_comm);
469  free(adjwgts);
470  } else if ((stat_para[6] != 0) && (stat_para[7] != 0)) {
471  vwgts = (int *)calloc(mesh->nn_internal, sizeof(int));
472  if (vwgts == NULL) HECMW_dlb_memory_exit("vwgts");
473  fp_wgts = fopen(ctl_para->vwgt_filename, "r");
474  if (fp_wgts == NULL) {
475  fprintf(stderr, "control file wrong: vwgt_filename\n");
476  exit(EXIT_FAILURE);
477  }
478  for (i = 0; i < mesh->nn_internal; i++) fscanf(fp_wgts, "%d", &vwgts[i]);
479  fclose(fp_wgts);
480  adjwgts = (int *)calloc(graph->xadj[mesh->nn_internal], sizeof(int));
481  if (adjwgts == NULL) HECMW_dlb_memory_exit("adjwgts");
482  fp_wgts = fopen(ctl_para->adjwgt_filename, "r");
483  if (fp_wgts == NULL) {
484  fprintf(stderr, "control file wrong: adjwgt_filename\n");
485  exit(EXIT_FAILURE);
486  }
487  for (i = 0; i < graph->xadj[mesh->nn_internal]; i++)
488  fscanf(fp_wgts, "%d", &adjwgts[i]);
489  fclose(fp_wgts);
490  ParMETIS_V3_PartKway(graph->vtxdist, graph->xadj, graph->adjncy, vwgts,
491  adjwgts, &(ctl_para->wgtflag), &numflag,
492  &(ctl_para->num_criteria),
493  &(ctl_para->num_repartition), ctl_para->machine_wgt,
494  ctl_para->balance_rate, options, &edgecut,
495  result->part, &repart_comm);
496  free(adjwgts);
497  free(vwgts);
498  }
499 
500  result->edgecut = edgecut;
501  } else if (strncmp(ctl_para->adaptive_repartition, "on", 2) == 0) {
502  if (ctl_para->wgtflag == 0)
503  ParMETIS_V3_AdaptiveRepart(
504  graph->vtxdist, graph->xadj, graph->adjncy, NULL, NULL, NULL,
505  &(ctl_para->wgtflag), &numflag, &(ctl_para->num_criteria),
506  &(ctl_para->num_repartition), ctl_para->machine_wgt,
507  ctl_para->balance_rate, &(ctl_para->itr_rate), options, &edgecut,
508  result->part, &repart_comm);
509 
510  else if ((stat_para[6] != 0) && (stat_para[7] == 0)) {
511  vwgts = (int *)calloc(mesh->nn_internal, sizeof(int));
512  if (vwgts == NULL) HECMW_dlb_memory_exit("vwgts");
513  fp_wgts = fopen(ctl_para->vwgt_filename, "r");
514  if (fp_wgts == NULL) {
515  fprintf(stderr, "control file wrong: vwgt_filename\n");
516  exit(EXIT_FAILURE);
517  }
518  for (i = 0; i < mesh->nn_internal; i++) fscanf(fp_wgts, "%d", &vwgts[i]);
519  fclose(fp_wgts);
520  ParMETIS_V3_AdaptiveRepart(
521  graph->vtxdist, graph->xadj, graph->adjncy, vwgts, NULL, NULL,
522  &(ctl_para->wgtflag), &numflag, &(ctl_para->num_criteria),
523  &(ctl_para->num_repartition), ctl_para->machine_wgt,
524  ctl_para->balance_rate, &(ctl_para->itr_rate), options, &edgecut,
525  result->part, &repart_comm);
526  free(vwgts);
527  } else if ((stat_para[6] == 0) && (stat_para[7] != 0)) {
528  adjwgts = (int *)calloc(graph->xadj[mesh->nn_internal], sizeof(int));
529  if (adjwgts == NULL) HECMW_dlb_memory_exit("adjwgts");
530  fp_wgts = fopen(ctl_para->adjwgt_filename, "r");
531  if (fp_wgts == NULL) {
532  fprintf(stderr, "control file wrong: adjwgt_filename\n");
533  exit(EXIT_FAILURE);
534  }
535  for (i = 0; i < graph->xadj[mesh->nn_internal]; i++)
536  fscanf(fp_wgts, "%d", &adjwgts[i]);
537  fclose(fp_wgts);
538  ParMETIS_V3_AdaptiveRepart(
539  graph->vtxdist, graph->xadj, graph->adjncy, NULL, NULL, adjwgts,
540  &(ctl_para->wgtflag), &numflag, &(ctl_para->num_criteria),
541  &(ctl_para->num_repartition), ctl_para->machine_wgt,
542  ctl_para->balance_rate, &(ctl_para->itr_rate), options, &edgecut,
543  result->part, &repart_comm);
544  free(adjwgts);
545  } else if ((stat_para[6] != 0) && (stat_para[7] != 0)) {
546  vwgts = (int *)calloc(mesh->nn_internal, sizeof(int));
547  if (vwgts == NULL) HECMW_dlb_memory_exit("vwgts");
548  fp_wgts = fopen(ctl_para->vwgt_filename, "r");
549  if (fp_wgts == NULL) {
550  fprintf(stderr, "control file wrong: vwgt_filename\n");
551  exit(EXIT_FAILURE);
552  }
553  for (i = 0; i < mesh->nn_internal; i++) fscanf(fp_wgts, "%d", &vwgts[i]);
554  fclose(fp_wgts);
555  adjwgts = (int *)calloc(graph->xadj[mesh->nn_internal], sizeof(int));
556  if (adjwgts == NULL) HECMW_dlb_memory_exit("adjwgts");
557  fp_wgts = fopen(ctl_para->adjwgt_filename, "r");
558  if (fp_wgts == NULL) {
559  fprintf(stderr, "control file wrong: adjwgt_filename\n");
560  exit(EXIT_FAILURE);
561  }
562  for (i = 0; i < graph->xadj[mesh->nn_internal]; i++)
563  fscanf(fp_wgts, "%d", &adjwgts[i]);
564  fclose(fp_wgts);
565  ParMETIS_V3_AdaptiveRepart(
566  graph->vtxdist, graph->xadj, graph->adjncy, vwgts, NULL, adjwgts,
567  &(ctl_para->wgtflag), &numflag, &(ctl_para->num_criteria),
568  &(ctl_para->num_repartition), ctl_para->machine_wgt,
569  ctl_para->balance_rate, &(ctl_para->itr_rate), options, &edgecut,
570  result->part, &repart_comm);
571  free(adjwgts);
572  free(vwgts);
573  }
574 
575  result->edgecut = edgecut;
576  }
577  /* write test file */
578  /* for(i=0;i<mesh->n_internal;i++) {
579  fprintf(fp_test, "%d \n", result->part[i]);
580  }
581 
582  fclose(fp_test);
583  */
584  free(graph->xadj);
585  free(graph->adjncy);
586 
587  return;
588 }
int HECMW_Comm_rank(HECMW_Comm comm, int *rank)
Definition: hecmw_comm.c:18
int HECMW_Comm_size(HECMW_Comm comm, int *size)
Definition: hecmw_comm.c:37
int HECMW_Allreduce(void *sendbuf, void *recvbuf, int count, HECMW_Datatype datatype, HECMW_Op op, HECMW_Comm comm)
Definition: hecmw_comm.c:404
int HECMW_Send(void *buffer, int count, HECMW_Datatype datatype, int dest, int tag, HECMW_Comm comm)
Definition: hecmw_comm.c:201
int HECMW_Recv(void *buffer, int count, HECMW_Datatype datatype, int source, int tag, HECMW_Comm comm, HECMW_Status *status)
Definition: hecmw_comm.c:251
#define HECMW_INT
Definition: hecmw_config.h:48
MPI_Status HECMW_Status
Definition: hecmw_config.h:36
MPI_Comm HECMW_Comm
Definition: hecmw_config.h:30
#define HECMW_SUM
Definition: hecmw_config.h:60
int HECMW_ANY_TAG
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
void HECMW_dlb_print_exit(char *var)
void HECMW_dlb_memory_exit(char *var)
void mesh2graph(struct hecmwST_local_mesh *mesh, GraphType *graph, Control_para *ctl_para, int stat_para[NUM_CONTROL_PARAS], Result_part *result, HECMW_Comm repart_comm)
void find_new_v8(int new_v8[24])
void add6_adj_link(Adj_find *adj_link, int id_elem, struct hecmwST_local_mesh *mesh, int new_v6[18])
void find_new_v4(int new_v4[12])
void find_new_v6(int new_v6[18])
void adj_link_free(Adj_find *adj_link, int num)
void add8_adj_link(Adj_find *adj_link, int id_elem, struct hecmwST_local_mesh *mesh, int new_v8[24])
void add4_adj_link(Adj_find *adj_link, int id_elem, struct hecmwST_local_mesh *mesh, int new_v4[12])
#define NULL
int repart_comm
Definition: hecmw_repart.h:70
#define NUM_CONTROL_PARAS
Definition: hecmw_repart.h:27
struct option_rec options[]
specify command line option name and executing function name.
Definition: main.c:286
struct _adj_find_struct * next_vertex
Definition: hecmw_repart.h:60
char adjwgt_filename[128]
Definition: hecmw_repart.h:47
char vwgt_filename[128]
Definition: hecmw_repart.h:46
char adaptive_repartition[4]
Definition: hecmw_repart.h:35
long long * elem_node_index
Definition: hecmw_struct.h:195