~elmer-csc-ubuntu/elmercsc/devel

« back to all changes in this revision

Viewing changes to elmergrid/src/metis-5.1.0/programs/m2gmetis.c

  • Committer: GitHub
  • Author(s): Peter R
  • Date: 2017-10-04 13:47:14 UTC
  • mfrom: (575.1.17)
  • Revision ID: git-v1:91780af69137b74ec539fedc4ad70c9ec52d732a
Merge pull request #115 from ElmerCSC/metis_update

Updated to new Metis API for devel branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 1994-2011, Regents of the University of Minnesota
 
3
 *
 
4
 * m2gmetis.c
 
5
 *
 
6
 * Drivers for the mesh-to-graph coversion routines
 
7
 *
 
8
 * Started 5/28/11
 
9
 * George
 
10
 *
 
11
 * $Id: m2gmetis.c 10498 2011-07-06 16:41:38Z karypis $
 
12
 *
 
13
 */
 
14
 
 
15
#include "metisbin.h"
 
16
 
 
17
 
 
18
 
 
19
/*************************************************************************/
 
20
/*! Let the game begin! */
 
21
/*************************************************************************/
 
22
int main(int argc, char *argv[])
 
23
{
 
24
  mesh_t *mesh;
 
25
  graph_t *graph;
 
26
  params_t *params;
 
27
  int status=0;
 
28
 
 
29
  params = parse_cmdline(argc, argv);
 
30
 
 
31
  gk_startcputimer(params->iotimer);
 
32
  mesh = ReadMesh(params);
 
33
 
 
34
  gk_stopcputimer(params->iotimer);
 
35
 
 
36
  if (mesh->ncon > 1) {
 
37
    printf("*** Meshes with more than one balancing constraint are not supported yet.\n");
 
38
    exit(0);
 
39
  }
 
40
 
 
41
  M2GPrintInfo(params, mesh);
 
42
 
 
43
  graph = CreateGraph();
 
44
 
 
45
  gk_malloc_init();
 
46
  gk_startcputimer(params->parttimer);
 
47
 
 
48
  switch (params->gtype) {
 
49
    case METIS_GTYPE_DUAL:
 
50
      status = METIS_MeshToDual(&mesh->ne, &mesh->nn, mesh->eptr, mesh->eind, 
 
51
                   &params->ncommon, &params->numflag, &graph->xadj, &graph->adjncy);
 
52
 
 
53
      if (status == METIS_OK) {
 
54
        graph->nvtxs  = mesh->ne;
 
55
        graph->nedges = graph->xadj[graph->nvtxs]; 
 
56
        graph->ncon   = 1;
 
57
      }
 
58
      break;
 
59
 
 
60
    case METIS_GTYPE_NODAL:
 
61
      status = METIS_MeshToNodal(&mesh->ne, &mesh->nn, mesh->eptr, mesh->eind, 
 
62
                   &params->numflag, &graph->xadj, &graph->adjncy);
 
63
 
 
64
      if (status == METIS_OK) {
 
65
        graph->nvtxs  = mesh->nn;
 
66
        graph->nedges = graph->xadj[graph->nvtxs]; 
 
67
        graph->ncon   = 1;
 
68
      }
 
69
      break;
 
70
  }
 
71
 
 
72
  gk_stopcputimer(params->parttimer);
 
73
  if (gk_GetCurMemoryUsed() != 0)
 
74
        printf("***It seems that Metis did not free all of its memory! Report this.\n");
 
75
  params->maxmemory = gk_GetMaxMemoryUsed();
 
76
  gk_malloc_cleanup(0);
 
77
 
 
78
  if (status != METIS_OK) {
 
79
    printf("\n***Metis returned with an error.\n");
 
80
  }
 
81
  else {
 
82
    /* Write the graph */
 
83
    gk_startcputimer(params->iotimer);
 
84
    WriteGraph(graph, params->outfile);
 
85
    gk_stopcputimer(params->iotimer);
 
86
 
 
87
    M2GReportResults(params, mesh, graph);
 
88
  }
 
89
 
 
90
  FreeGraph(&graph);
 
91
  FreeMesh(&mesh);
 
92
  gk_free((void **)&params->filename, &params->outfile, &params, LTERM);
 
93
}
 
94
 
 
95
 
 
96
/*************************************************************************/
 
97
/*! This function prints run parameters */
 
98
/*************************************************************************/
 
99
void M2GPrintInfo(params_t *params, mesh_t *mesh)
 
100
 
101
  printf("******************************************************************************\n");
 
102
  printf("%s", METISTITLE);
 
103
  printf(" (HEAD: %s, Built on: %s, %s)\n", SVNINFO, __DATE__, __TIME__);
 
104
  printf(" size of idx_t: %zubits, real_t: %zubits, idx_t *: %zubits\n", 
 
105
      8*sizeof(idx_t), 8*sizeof(real_t), 8*sizeof(idx_t *));
 
106
  printf("\n");
 
107
  printf("Mesh Information ------------------------------------------------------------\n");
 
108
  printf(" Name: %s, #Elements: %"PRIDX", #Nodes: %"PRIDX"\n", 
 
109
      params->filename, mesh->ne, mesh->nn); 
 
110
  
 
111
  printf("Options ---------------------------------------------------------------------\n");
 
112
  printf(" gtype=%s, ncommon=%"PRIDX", outfile=%s\n", 
 
113
      gtypenames[params->gtype], params->ncommon, params->outfile);
 
114
 
 
115
  printf("\n");
 
116
}
 
117
 
 
118
 
 
119
/*************************************************************************/
 
120
/*! This function does any post-metis reporting */
 
121
/*************************************************************************/
 
122
void M2GReportResults(params_t *params, mesh_t *mesh, graph_t *graph)
 
123
 
124
 
 
125
  gk_startcputimer(params->reporttimer);
 
126
 
 
127
  printf(" - #nvtxs: %"PRIDX", #edges: %"PRIDX"\n", graph->nvtxs, graph->nedges);
 
128
 
 
129
  gk_stopcputimer(params->reporttimer);
 
130
 
 
131
 
 
132
  printf("\nTiming Information ----------------------------------------------------------\n");
 
133
  printf("  I/O:          \t\t %7.3"PRREAL" sec\n", gk_getcputimer(params->iotimer));
 
134
  printf("  Partitioning: \t\t %7.3"PRREAL" sec   (METIS time)\n", gk_getcputimer(params->parttimer));
 
135
  printf("  Reporting:    \t\t %7.3"PRREAL" sec\n", gk_getcputimer(params->reporttimer));
 
136
  printf("\nMemory Information ----------------------------------------------------------\n");
 
137
  printf("  Max memory used:\t\t %7.3"PRREAL" MB\n", (real_t)(params->maxmemory/(1024.0*1024.0)));
 
138
  printf("******************************************************************************\n");
 
139
 
 
140
}