~ubuntu-branches/ubuntu/trusty/scotch/trusty

« back to all changes in this revision

Viewing changes to src/scotch/dggath.c

  • Committer: Bazaar Package Importer
  • Author(s): "Adam C. Powell, IV", Christophe Trophime, Adam C. Powell, IV
  • Date: 2010-12-29 13:07:19 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20101229130719-jwalolw5d6av6wqx
Tags: 5.1.11.dfsg-1
[Christophe Trophime]
* New upstream release
* Forward-ported patches to version 5.1.10b.
* Install scotch headers properly.
* Fix chrpath commands in debian/rules.
* Fix (pt)scotch library install paths.
* Fix lintian errors and warnings.

[Adam C. Powell, IV]
* Forward-ported patches to version 5.1.11.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2008,2010 ENSEIRB, INRIA & CNRS
 
2
**
 
3
** This file is part of the Scotch software package for static mapping,
 
4
** graph partitioning and sparse matrix ordering.
 
5
**
 
6
** This software is governed by the CeCILL-C license under French law
 
7
** and abiding by the rules of distribution of free software. You can
 
8
** use, modify and/or redistribute the software under the terms of the
 
9
** CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
 
10
** URL: "http://www.cecill.info".
 
11
** 
 
12
** As a counterpart to the access to the source code and rights to copy,
 
13
** modify and redistribute granted by the license, users are provided
 
14
** only with a limited warranty and the software's author, the holder of
 
15
** the economic rights, and the successive licensors have only limited
 
16
** liability.
 
17
** 
 
18
** In this respect, the user's attention is drawn to the risks associated
 
19
** with loading, using, modifying and/or developing or reproducing the
 
20
** software by the user in light of its specific status of free software,
 
21
** that may mean that it is complicated to manipulate, and that also
 
22
** therefore means that it is reserved for developers and experienced
 
23
** professionals having in-depth computer knowledge. Users are therefore
 
24
** encouraged to load and test the software's suitability as regards
 
25
** their requirements in conditions enabling the security of their
 
26
** systems and/or data to be ensured and, more generally, to use and
 
27
** operate it in the same conditions as regards security.
 
28
** 
 
29
** The fact that you are presently reading this means that you have had
 
30
** knowledge of the CeCILL-C license and that you accept its terms.
 
31
*/
 
32
/************************************************************/
 
33
/**                                                        **/
 
34
/**   NAME       : dggath.c                                **/
 
35
/**                                                        **/
 
36
/**   AUTHOR     : Francois PELLEGRINI                     **/
 
37
/**                                                        **/
 
38
/**   FUNCTION   : This program gathers the fragments of a **/
 
39
/**                distributed graph and saves it as a     **/
 
40
/**                centralized source graph.               **/
 
41
/**                This module contains the main function. **/
 
42
/**                                                        **/
 
43
/**   DATES      : # Version 5.1  : from : 26 oct 2008     **/
 
44
/**                                 to   : 26 oct 2008     **/
 
45
/**                                                        **/
 
46
/************************************************************/
 
47
 
 
48
/*
 
49
**  The defines and includes.
 
50
*/
 
51
 
 
52
#define DGGATH
 
53
#define SCOTCH_PTSCOTCH
 
54
 
 
55
#include "module.h"
 
56
#include "common.h"
 
57
#include "ptscotch.h"
 
58
#include "dggath.h"
 
59
 
 
60
/*
 
61
**  The static and global definitions.
 
62
*/
 
63
 
 
64
static int                  C_fileNum = 0;        /* Number of file in arg list */
 
65
static File                 C_fileTab[C_FILENBR] = { /* File array              */
 
66
                              { "-", NULL, "r" },
 
67
                              { "-", NULL, "w" } };
 
68
 
 
69
static const char *         C_usageList[] = {
 
70
  "dggath [<input (distributed) source file> [<output centralized source file>]] <options>",
 
71
  "  -c       : Check the input graph after loading",
 
72
  "  -h       : Display this help",
 
73
  "  -r<num>  : Set root process for centralized files (default is 0)",
 
74
  "  -V       : Print program version and copyright",
 
75
  NULL };
 
76
 
 
77
/*********************/
 
78
/*                   */
 
79
/* The main routine. */
 
80
/*                   */
 
81
/*********************/
 
82
 
 
83
int
 
84
main (
 
85
int                 argc,
 
86
char *              argv[])
 
87
{
 
88
  SCOTCH_Graph *      cgrfptr;
 
89
  SCOTCH_Graph        cgrfdat;
 
90
  SCOTCH_Dgraph       dgrfdat;
 
91
  int                 procglbnbr;
 
92
  int                 proclocnum;
 
93
  int                 protglbnum;                 /* Root process */
 
94
  int                 flagval;
 
95
  int                 i;
 
96
  int                 reduloctab[2];
 
97
  int                 reduglbtab[2];
 
98
#ifdef SCOTCH_PTHREAD
 
99
  int                 thrdlvlreqval;
 
100
  int                 thrdlvlproval;
 
101
#endif /* SCOTCH_PTHREAD */
 
102
 
 
103
  errorProg ("dggath");
 
104
 
 
105
#ifdef SCOTCH_PTHREAD
 
106
  thrdlvlreqval = MPI_THREAD_MULTIPLE;
 
107
  if (MPI_Init_thread (&argc, &argv, thrdlvlreqval, &thrdlvlproval) != MPI_SUCCESS)
 
108
    errorPrint ("main: Cannot initialize (1)");
 
109
  if (thrdlvlreqval > thrdlvlproval)
 
110
    errorPrint ("main: MPI implementation is not thread-safe: recompile without SCOTCH_PTHREAD");
 
111
#else /* SCOTCH_PTHREAD */
 
112
  if (MPI_Init (&argc, &argv) != MPI_SUCCESS)
 
113
    errorPrint ("main: Cannot initialize (2)");
 
114
#endif /* SCOTCH_PTHREAD */
 
115
 
 
116
  MPI_Comm_size (MPI_COMM_WORLD, &procglbnbr);    /* Get communicator data */
 
117
  MPI_Comm_rank (MPI_COMM_WORLD, &proclocnum);
 
118
  protglbnum = 0;                                 /* Assume root process is process 0 */
 
119
 
 
120
  if ((argc >= 2) && (argv[1][0] == '?')) {       /* If need for help */
 
121
    usagePrint (stdout, C_usageList);
 
122
    return     (0);
 
123
  }
 
124
 
 
125
  flagval = C_FLAGNONE;
 
126
 
 
127
  for (i = 0; i < C_FILENBR; i ++)                /* Set default stream pointers */
 
128
    C_fileTab[i].pntr = (C_fileTab[i].mode[0] == 'r') ? stdin : stdout;
 
129
 
 
130
  for (i = 1; i < argc; i ++) {                   /* Loop for all option codes                        */
 
131
    if ((argv[i][0] != '-') || (argv[i][1] == '\0') || (argv[i][1] == '.')) { /* If found a file name */
 
132
      if (C_fileNum < C_FILEARGNBR)               /* File name has been given                         */
 
133
        C_fileTab[C_fileNum ++].name = argv[i];
 
134
      else
 
135
        errorPrint ("main: too many file names given");
 
136
    }
 
137
    else {                                        /* If found an option name */
 
138
      switch (argv[i][1]) {
 
139
        case 'C' :
 
140
        case 'c' :
 
141
          flagval |= C_FLAGCHECK;
 
142
          break;
 
143
#ifdef SCOTCH_DEBUG_ALL
 
144
        case 'D' :
 
145
        case 'd' :
 
146
          flagval |= C_FLAGDEBUG;
 
147
          break;
 
148
#endif /* SCOTCH_DEBUG_ALL */
 
149
        case 'H' :                                /* Give the usage message */
 
150
        case 'h' :
 
151
          usagePrint (stdout, C_usageList);
 
152
          return     (0);
 
153
        case 'R' :                                /* Root process (if necessary) */
 
154
        case 'r' :
 
155
          protglbnum = atoi (&argv[i][2]);
 
156
          if ((protglbnum < 0)           ||
 
157
              (protglbnum >= procglbnbr) ||
 
158
              ((protglbnum == 0) && (argv[i][2] != '0'))) {
 
159
            errorPrint ("main: invalid root process number");
 
160
          }
 
161
          break;
 
162
        case 'V' :
 
163
        case 'v' :
 
164
          fprintf (stderr, "dggath, version " SCOTCH_VERSION_STRING "\n");
 
165
          fprintf (stderr, "Copyright 2008,2010 ENSEIRB, INRIA & CNRS, France\n");
 
166
          fprintf (stderr, "This software is libre/free software under CeCILL-C -- see the user's manual for more information\n");
 
167
          return  (0);
 
168
        default :
 
169
          errorPrint ("main: unprocessed option (\"%s\")", argv[i]);
 
170
      }
 
171
    }
 
172
  }
 
173
 
 
174
#ifdef SCOTCH_DEBUG_ALL
 
175
  if ((flagval & C_FLAGDEBUG) != 0) {
 
176
    fprintf (stderr, "Proc %4d of %d, pid %d\n", proclocnum, procglbnbr, getpid ());
 
177
    if (proclocnum == protglbnum) {               /* Synchronize on keybord input */
 
178
      char           c;
 
179
 
 
180
      printf ("Waiting for key press...\n");
 
181
      scanf  ("%c", &c);
 
182
    }
 
183
    MPI_Barrier (MPI_COMM_WORLD);
 
184
  }
 
185
#endif /* SCOTCH_DEBUG_ALL */
 
186
 
 
187
  fileBlockOpenDist (C_fileTab, C_FILENBR, procglbnbr, proclocnum, protglbnum); /* Open all files */
 
188
 
 
189
  if (C_filepntrsrcout == NULL) {
 
190
    cgrfptr = NULL;
 
191
    reduloctab[0] =
 
192
    reduloctab[1] = 0;
 
193
  }
 
194
  else {
 
195
    cgrfptr = &cgrfdat;
 
196
    reduloctab[0] = 1;
 
197
    reduloctab[1] = proclocnum;
 
198
  }
 
199
  if (MPI_Allreduce (reduloctab, reduglbtab, 2, MPI_INT, MPI_SUM, MPI_COMM_WORLD) != MPI_SUCCESS)
 
200
    errorPrint ("main: communication error");
 
201
 
 
202
  if (reduglbtab[0] != 1)
 
203
    errorPrint ("main: should have only one root");
 
204
  if (reduglbtab[1] != protglbnum)
 
205
    errorPrint ("main: root process mismatch");
 
206
 
 
207
  SCOTCH_dgraphInit (&dgrfdat, MPI_COMM_WORLD);
 
208
  SCOTCH_dgraphLoad (&dgrfdat, C_filepntrsrcinp, -1, 0);
 
209
 
 
210
  if ((flagval & C_FLAGCHECK) != 0)
 
211
    SCOTCH_dgraphCheck (&dgrfdat);
 
212
 
 
213
  SCOTCH_graphInit    (&cgrfdat);
 
214
  SCOTCH_dgraphGather (&dgrfdat, cgrfptr);
 
215
  if (cgrfptr != NULL)
 
216
    SCOTCH_graphSave (cgrfptr, C_filepntrsrcout);
 
217
 
 
218
  fileBlockClose (C_fileTab, C_FILENBR);          /* Always close explicitely to end eventual (un)compression tasks */
 
219
 
 
220
  SCOTCH_graphExit  (&cgrfdat);
 
221
  SCOTCH_dgraphExit (&dgrfdat);
 
222
 
 
223
  MPI_Finalize ();
 
224
#ifdef COMMON_PTHREAD
 
225
  pthread_exit ((void *) 0);                      /* Allow potential (un)compression tasks to complete */
 
226
#endif /* COMMON_PTHREAD */
 
227
  return (0);
 
228
}