1 /* Copyright 2004,2007,2008,2010-2012,2014 Universite de Bordeaux, 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       : gmk_hy.c                                **/
35 /**                                                        **/
36 /**   AUTHOR     : Francois PELLEGRINI                     **/
37 /**                                                        **/
38 /**   FUNCTION   : Creates the source graph for hypercube  **/
39 /**                graphs.                                 **/
40 /**                                                        **/
41 /**   DATES      : # Version 2.0  : from : 03 nov 1994     **/
42 /**                                 to     03 nov 1994     **/
43 /**                # Version 3.0  : from : 11 jul 1995     **/
44 /**                                 to     11 jul 1995     **/
45 /**                # Version 3.2  : from : 03 jun 1997     **/
46 /**                                 to   : 03 jun 1997     **/
47 /**                # Version 3.3  : from : 06 oct 1998     **/
48 /**                                 to   : 06 oct 1998     **/
49 /**                # Version 3.4  : from : 03 feb 2000     **/
50 /**                                 to   : 03 feb 2000     **/
51 /**                # Version 5.0  : from : 23 dec 2007     **/
52 /**                                 to   : 16 map 2008     **/
53 /**                # Version 5.1  : from : 01 jul 2010     **/
54 /**                                 to   : 14 feb 2011     **/
55 /**                # Version 6.0  : from : 01 jan 2012     **/
56 /**                                 to   : 12 nov 2014     **/
57 /**                                                        **/
58 /************************************************************/
59 
60 /*
61 **  The defines and includes.
62 */
63 
64 #define GMK_HY
65 
66 #include "module.h"
67 #include "common.h"
68 #include "scotch.h"
69 #include "gmk_hy.h"
70 
71 /*
72 **  The static definitions.
73 */
74 
75 static int                  C_paraNum = 0;        /* Number of parameters       */
76 static int                  C_fileNum = 0;        /* Number of file in arg list */
77 static File                 C_fileTab[C_FILENBR] = { /* The file array          */
78                               { "w" } };
79 
80 static const char *         C_usageList[] = {
81   "gmk_hy <dim> [<output source file>] <options>",
82   "  -h  : Display this help",
83   "  -V  : Print program version and copyright",
84   NULL };
85 
86 /****************************************/
87 /*                                      */
88 /* The main routine, which computes the */
89 /* source graph description.            */
90 /*                                      */
91 /****************************************/
92 
93 int
main(int argc,char * argv[])94 main (
95 int                         argc,
96 char *                      argv[])
97 {
98   SCOTCH_Num          hdim = 1;                   /* Graph dimension      */
99   SCOTCH_Num          hnbr;                       /* Number of vertices   */
100   SCOTCH_Num          hbit;                       /* Most significant bit */
101   SCOTCH_Num          hvrt;
102   SCOTCH_Num          hngb;
103   int                 i;
104 
105   errorProg ("gmk_hy");
106 
107   if ((argc >= 2) && (argv[1][0] == '?')) {       /* If need for help */
108     usagePrint (stdout, C_usageList);
109     exit       (0);
110   }
111 
112   fileBlockInit (C_fileTab, C_FILENBR);           /* Set default stream pointers */
113 
114   for (i = 1; i < argc; i ++) {                   /* Loop for all option codes                        */
115     if ((argv[i][0] != '-') || (argv[i][1] == '\0') || (argv[i][1] == '.')) { /* If found a file name */
116       if (C_paraNum < 1) {                        /* If number of parameters not reached              */
117         if ((hdim = atoi (argv[i])) < 1) {        /* Get the dimension                                */
118           errorPrint ("main: invalid dimension '%s'", argv[i]);
119           exit       (1);
120         }
121         C_paraNum ++;
122         continue;                                 /* Process the other parameters */
123       }
124       if (C_fileNum < C_FILEARGNBR)               /* A file name has been given */
125         fileBlockName (C_fileTab, C_fileNum ++) = argv[i];
126       else {
127         errorPrint ("main: too many file names given");
128         exit       (1);
129       }
130     }
131     else {                                        /* If found an option name */
132       switch (argv[i][1]) {
133         case 'H' :                                /* Give the usage message */
134         case 'h' :
135           usagePrint (stdout, C_usageList);
136           exit       (0);
137         case 'V' :
138           fprintf (stderr, "gmk_hy, version " SCOTCH_VERSION_STRING "\n");
139           fprintf (stderr, "Copyright 2004,2007,2008,2010-2012,2014 IPB, Universite de Bordeaux, INRIA & CNRS\n");
140           fprintf (stderr, "This software is libre/free software under CeCILL-C -- see the user's manual for more information\n");
141           return  (0);
142         default :
143           errorPrint ("main: unprocessed option '%s'", argv[i]);
144           exit       (1);
145       }
146     }
147   }
148 
149   fileBlockOpen (C_fileTab, C_FILENBR);           /* Open all files */
150 
151   hnbr = 1 <<  hdim;                              /* Compute number of vertices */
152   hbit = 1 << (hdim - 1);                         /* Compute highest bit value  */
153 
154   fprintf (C_filepntrsrcout, "0\n" SCOTCH_NUMSTRING "\t" SCOTCH_NUMSTRING "\n0\t000\n",
155            (SCOTCH_Num) hnbr,                     /* Print number of vertices     */
156            (SCOTCH_Num) (hdim * hnbr));           /* Print number of edges (arcs) */
157 
158   for (hvrt = 0; hvrt < hnbr; hvrt ++) {          /* For all vertices */
159     fprintf (C_filepntrsrcout, "" SCOTCH_NUMSTRING "",
160              (SCOTCH_Num) hdim);                  /* Output number of neighbors         */
161     for (hngb = hbit; hngb > 0; hngb >>= 1)       /* For all vertex bits                */
162       fprintf (C_filepntrsrcout, "\t" SCOTCH_NUMSTRING, /* Write corresponding neighbor */
163                (SCOTCH_Num) (hvrt ^ hngb));
164     fprintf (C_filepntrsrcout, "\n");
165   }
166 
167   fileBlockClose (C_fileTab, C_FILENBR);          /* Always close explicitely to end eventual (un)compression tasks */
168 
169 #ifdef COMMON_PTHREAD
170   pthread_exit ((void *) 0);                      /* Allow potential (un)compression tasks to complete */
171 #endif /* COMMON_PTHREAD */
172   return (0);
173 }
174