1 /* Copyright 2011,2012,2014,2015 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 : test_scotch_dgraph_band.c **/
35 /** **/
36 /** AUTHOR : Francois PELLEGRINI **/
37 /** **/
38 /** FUNCTION : This module tests the operation of **/
39 /** the SCOTCH_dgraphBand() routine. **/
40 /** **/
41 /** DATES : # Version 6.0 : from : 10 nov 2011 **/
42 /** to 02 mar 2015 **/
43 /** **/
44 /************************************************************/
45
46 /*
47 ** The defines and includes.
48 */
49
50 #include <mpi.h>
51 #include <stdio.h>
52 #if (((defined __STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || (defined HAVE_STDINT_H))
53 #include <stdint.h>
54 #endif /* (((defined __STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || (defined HAVE_STDINT_H)) */
55 #include <stdlib.h>
56 #include <sys/time.h>
57 #include <sys/types.h>
58 #include <pthread.h>
59 #include <unistd.h>
60
61 #include "ptscotch.h"
62
63 #define errorProg SCOTCH_errorProg
64 #define errorPrint SCOTCH_errorPrint
65
66 /*********************/
67 /* */
68 /* The main routine. */
69 /* */
70 /*********************/
71
72 int
main(int argc,char * argv[])73 main (
74
75 int argc,
76 char * argv[])
77 {
78 MPI_Comm proccomm;
79 int procglbnbr; /* Number of processes sharing graph data */
80 int proclocnum; /* Number of this process */
81 SCOTCH_Num vertglbnbr;
82 SCOTCH_Num vertlocnbr;
83 SCOTCH_Num * fronloctab;
84 SCOTCH_Num baseval;
85 SCOTCH_Dgraph grafdat;
86 SCOTCH_Dgraph bandgrafdat;
87 SCOTCH_Num bandvertglbnbr;
88 SCOTCH_Num bandvertlocnbr;
89 SCOTCH_Num * bandvlblloctab;
90 FILE * file;
91 int procnum;
92 #ifdef SCOTCH_PTHREAD
93 int thrdlvlreqval;
94 int thrdlvlproval;
95 #endif /* SCOTCH_PTHREAD */
96
97 errorProg (argv[0]);
98
99 #ifdef SCOTCH_PTHREAD
100 thrdlvlreqval = MPI_THREAD_MULTIPLE;
101 if (MPI_Init_thread (&argc, &argv, thrdlvlreqval, &thrdlvlproval) != MPI_SUCCESS)
102 errorPrint ("main: Cannot initialize (1)");
103 if (thrdlvlreqval > thrdlvlproval)
104 errorPrint ("main: MPI implementation is not thread-safe: recompile without SCOTCH_PTHREAD");
105 #else /* SCOTCH_PTHREAD */
106 if (MPI_Init (&argc, &argv) != MPI_SUCCESS)
107 errorPrint ("main: Cannot initialize (2)");
108 #endif /* SCOTCH_PTHREAD */
109
110 if (argc != 2) {
111 errorPrint ("main: invalid number of parameters");
112 exit (1);
113 }
114
115 proccomm = MPI_COMM_WORLD;
116 MPI_Comm_size (proccomm, &procglbnbr); /* Get communicator data */
117 MPI_Comm_rank (proccomm, &proclocnum);
118
119 fprintf (stderr, "Proc %2d of %2d, pid %d\n", proclocnum, procglbnbr, getpid ());
120
121 #ifdef SCOTCH_CHECK_NOAUTO
122 if (proclocnum == 0) { /* Synchronize on keybord input */
123 char c;
124
125 printf ("Waiting for key press...\n");
126 scanf ("%c", &c);
127 }
128 #endif /* SCOTCH_CHECK_NOAUTO */
129
130 if (MPI_Barrier (proccomm) != MPI_SUCCESS) { /* Synchronize for debug */
131 errorPrint ("main: cannot communicate");
132 return (1);
133 }
134
135 if (SCOTCH_dgraphInit (&grafdat, proccomm) != 0) { /* Initialize source graph */
136 errorPrint ("main: cannot initialize graph (1)");
137 return (1);
138 }
139
140 file = NULL;
141 if ((proclocnum == 0) &&
142 ((file = fopen (argv[1], "r")) == NULL)) {
143 errorPrint ("main: cannot open graph file");
144 return (1);
145 }
146
147 if (SCOTCH_dgraphLoad (&grafdat, file, 0, 0) != 0) {
148 errorPrint ("main: cannot load graph");
149 return (1);
150 }
151
152 if (file != NULL)
153 fclose (file);
154
155 if (MPI_Barrier (proccomm) != MPI_SUCCESS) { /* Synchronize for debug */
156 errorPrint ("main: cannot communicate");
157 return (1);
158 }
159
160 SCOTCH_dgraphData (&grafdat, NULL, &vertglbnbr, &vertlocnbr, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
161
162 if ((fronloctab = malloc (vertlocnbr * sizeof (SCOTCH_Num))) == NULL) {
163 errorPrint ("main: cannot allocate frontier array");
164 return (1);
165 }
166
167 if (SCOTCH_dgraphInit (&bandgrafdat, proccomm) != 0) { /* Initialize band graph */
168 errorPrint ("main: cannot initialize graph (2)");
169 return (1);
170 }
171
172 fronloctab[0] = 0;
173
174 if (SCOTCH_dgraphBand (&grafdat, (proclocnum == 1) ? 1 : 0, fronloctab, 4, &bandgrafdat) != 0) {
175 errorPrint ("main: cannot compute band graph");
176 return (1);
177 }
178
179 free (fronloctab);
180
181 SCOTCH_dgraphData (&bandgrafdat, &baseval, &bandvertglbnbr, &bandvertlocnbr, NULL, NULL, NULL, NULL, NULL, &bandvlblloctab, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
182
183 for (procnum = 0; procnum < procglbnbr; procnum ++) {
184 SCOTCH_Num bandvertlocnum;
185
186 MPI_Barrier (proccomm);
187
188 if (procnum == proclocnum) {
189 if ((file = fopen ("/tmp/test_scotch_dgraph_band.map", (procnum == 0) ? "w" : "a+")) == NULL) {
190 errorPrint ("main: cannot open mapping file");
191 return (1);
192 }
193
194 if (procnum == 0)
195 fprintf (file, "%ld\n", (long) bandvertglbnbr);
196
197 for (bandvertlocnum = 0; bandvertlocnum < bandvertlocnbr; bandvertlocnum ++)
198 fprintf (file, "%ld\t1\n", (long) bandvlblloctab[bandvertlocnum]);
199
200 fclose (file);
201 }
202 }
203
204 SCOTCH_dgraphExit (&bandgrafdat);
205 SCOTCH_dgraphExit (&grafdat);
206
207 MPI_Finalize ();
208 exit (0);
209 }
210