1 /* Copyright 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 : 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 : 14 feb 2011 **/
45 /** # Version 6.0 : from : 01 jan 2012 **/
46 /** to : 12 nov 2014 **/
47 /** **/
48 /************************************************************/
49
50 /*
51 ** The defines and includes.
52 */
53
54 #define DGGATH
55 #define SCOTCH_PTSCOTCH
56
57 #include "module.h"
58 #include "common.h"
59 #include "ptscotch.h"
60 #include "dggath.h"
61
62 /*
63 ** The static and global definitions.
64 */
65
66 static int C_fileNum = 0; /* Number of file in arg list */
67 static File C_fileTab[C_FILENBR] = { /* File array */
68 { "r" },
69 { "w" } };
70
71 static const char * C_usageList[] = {
72 "dggath [<input (distributed) source file> [<output centralized source file>]] <options>",
73 " -c : Check the input graph after loading",
74 " -h : Display this help",
75 " -r<num> : Set root process for centralized files (default is 0)",
76 " -V : Print program version and copyright",
77 NULL };
78
79 /*********************/
80 /* */
81 /* The main routine. */
82 /* */
83 /*********************/
84
85 int
main(int argc,char * argv[])86 main (
87 int argc,
88 char * argv[])
89 {
90 SCOTCH_Graph * cgrfptr;
91 SCOTCH_Graph cgrfdat;
92 SCOTCH_Dgraph dgrfdat;
93 int procglbnbr;
94 int proclocnum;
95 int protglbnum; /* Root process */
96 int flagval;
97 int i;
98 int reduloctab[2];
99 int reduglbtab[2];
100 #ifdef SCOTCH_PTHREAD
101 int thrdlvlreqval;
102 int thrdlvlproval;
103 #endif /* SCOTCH_PTHREAD */
104
105 errorProg ("dggath");
106
107 #ifdef SCOTCH_PTHREAD
108 thrdlvlreqval = MPI_THREAD_MULTIPLE;
109 if (MPI_Init_thread (&argc, &argv, thrdlvlreqval, &thrdlvlproval) != MPI_SUCCESS)
110 errorPrint ("main: Cannot initialize (1)");
111 if (thrdlvlreqval > thrdlvlproval)
112 errorPrint ("main: MPI implementation is not thread-safe: recompile without SCOTCH_PTHREAD");
113 #else /* SCOTCH_PTHREAD */
114 if (MPI_Init (&argc, &argv) != MPI_SUCCESS)
115 errorPrint ("main: Cannot initialize (2)");
116 #endif /* SCOTCH_PTHREAD */
117
118 MPI_Comm_size (MPI_COMM_WORLD, &procglbnbr); /* Get communicator data */
119 MPI_Comm_rank (MPI_COMM_WORLD, &proclocnum);
120 protglbnum = 0; /* Assume root process is process 0 */
121
122 if ((argc >= 2) && (argv[1][0] == '?')) { /* If need for help */
123 usagePrint (stdout, C_usageList);
124 return (0);
125 }
126
127 flagval = C_FLAGNONE;
128
129 fileBlockInit (C_fileTab, C_FILENBR); /* Set default stream pointers */
130
131 for (i = 1; i < argc; i ++) { /* Loop for all option codes */
132 if ((argv[i][0] != '-') || (argv[i][1] == '\0') || (argv[i][1] == '.')) { /* If found a file name */
133 if (C_fileNum < C_FILEARGNBR) /* File name has been given */
134 fileBlockName (C_fileTab, C_fileNum ++) = argv[i];
135 else
136 errorPrint ("main: too many file names given");
137 }
138 else { /* If found an option name */
139 switch (argv[i][1]) {
140 case 'C' :
141 case 'c' :
142 flagval |= C_FLAGCHECK;
143 break;
144 #ifdef SCOTCH_DEBUG_ALL
145 case 'D' :
146 case 'd' :
147 flagval |= C_FLAGDEBUG;
148 break;
149 #endif /* SCOTCH_DEBUG_ALL */
150 case 'H' : /* Give the usage message */
151 case 'h' :
152 usagePrint (stdout, C_usageList);
153 return (0);
154 case 'R' : /* Root process (if necessary) */
155 case 'r' :
156 protglbnum = atoi (&argv[i][2]);
157 if ((protglbnum < 0) ||
158 (protglbnum >= procglbnbr) ||
159 ((protglbnum == 0) && (argv[i][2] != '0'))) {
160 errorPrint ("main: invalid root process number");
161 }
162 break;
163 case 'V' :
164 case 'v' :
165 fprintf (stderr, "dggath, version " SCOTCH_VERSION_STRING "\n");
166 fprintf (stderr, "Copyright 2008,2010-2012,2014 IPB, Universite de Bordeaux, INRIA & CNRS, France\n");
167 fprintf (stderr, "This software is libre/free software under CeCILL-C -- see the user's manual for more information\n");
168 return (0);
169 default :
170 errorPrint ("main: unprocessed option '%s'", argv[i]);
171 }
172 }
173 }
174
175 #ifdef SCOTCH_DEBUG_ALL
176 if ((flagval & C_FLAGDEBUG) != 0) {
177 fprintf (stderr, "Proc %4d of %d, pid %d\n", proclocnum, procglbnbr, getpid ());
178 if (proclocnum == protglbnum) { /* Synchronize on keybord input */
179 char c;
180
181 printf ("Waiting for key press...\n");
182 scanf ("%c", &c);
183 }
184 MPI_Barrier (MPI_COMM_WORLD);
185 }
186 #endif /* SCOTCH_DEBUG_ALL */
187
188 fileBlockOpenDist (C_fileTab, C_FILENBR, procglbnbr, proclocnum, protglbnum); /* Open all files */
189
190 if (C_filepntrsrcout == NULL) {
191 cgrfptr = NULL;
192 reduloctab[0] =
193 reduloctab[1] = 0;
194 }
195 else {
196 cgrfptr = &cgrfdat;
197 reduloctab[0] = 1;
198 reduloctab[1] = proclocnum;
199 }
200 if (MPI_Allreduce (reduloctab, reduglbtab, 2, MPI_INT, MPI_SUM, MPI_COMM_WORLD) != MPI_SUCCESS)
201 errorPrint ("main: communication error");
202
203 if (reduglbtab[0] != 1)
204 errorPrint ("main: should have only one root");
205 if (reduglbtab[1] != protglbnum)
206 errorPrint ("main: root process mismatch");
207
208 SCOTCH_dgraphInit (&dgrfdat, MPI_COMM_WORLD);
209 SCOTCH_dgraphLoad (&dgrfdat, C_filepntrsrcinp, -1, 0);
210
211 if ((flagval & C_FLAGCHECK) != 0)
212 SCOTCH_dgraphCheck (&dgrfdat);
213
214 SCOTCH_graphInit (&cgrfdat);
215 SCOTCH_dgraphGather (&dgrfdat, cgrfptr);
216 if (cgrfptr != NULL)
217 SCOTCH_graphSave (cgrfptr, C_filepntrsrcout);
218
219 fileBlockClose (C_fileTab, C_FILENBR); /* Always close explicitely to end eventual (un)compression tasks */
220
221 SCOTCH_graphExit (&cgrfdat);
222 SCOTCH_dgraphExit (&dgrfdat);
223
224 MPI_Finalize ();
225 #ifdef COMMON_PTHREAD
226 pthread_exit ((void *) 0); /* Allow potential (un)compression tasks to complete */
227 #endif /* COMMON_PTHREAD */
228 return (0);
229 }
230