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