1 /* =============================================================================
5 * =============================================================================
7 * Unless otherwise noted, the following license applies to STAMP files:
9 * Copyright (c) 2007, Stanford University
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are
16 * * Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
19 * * Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
24 * * Neither the name of Stanford University nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
29 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
38 * THE POSSIBILITY OF SUCH DAMAGE.
40 * =============================================================================
43 public class SSCA2 extends Thread {
45 * Tuple for Scalable Data Generation
46 * stores startVertex, endVertex, long weight and other info
51 * The graph data structure for this benchmark - see defs.h
58 ComputeGraph computeGraphArgs;
66 * Total number of threads
84 GetStartLists getStartListsArg;
87 Alg_Radix_Smp radixsort;
89 public SSCA2(int myId, int numThread, Globals glb, ComputeGraph computeGraphArgs,
90 GenScalData gsd, GetStartLists getStartListsArg, Alg_Radix_Smp radixsort) {
92 this.numThread = numThread;
94 this.computeGraphArgs = computeGraphArgs;
95 this.G = computeGraphArgs.GPtr;
96 this.SDGdata = computeGraphArgs.SDGdataPtr;
98 this. getStartListsArg = getStartListsArg;
99 this.radixsort = radixsort;
103 #ifdef USE_PARALLEL_DATA_GENERATION
104 /* Generate Scaldata */
105 Barrier.enterBarrier();
106 GenScalData.genScalData(threadid, numThread, glb, SDGdata, gsd, radixsort);
107 Barrier.enterBarrier();
110 #ifdef ENABLE_KERNEL1
112 Barrier.enterBarrier();
113 ComputeGraph.computeGraph(threadid, numThread, glb, computeGraphArgs);
114 Barrier.enterBarrier();
115 #endif /* Enable Kernel1 */
117 #ifdef ENABLE_KERNEL2
119 Barrier.enterBarrier();
120 GetStartLists.getStartLists(threadid, numThread, glb, getStartListsArg);
121 Barrier.enterBarrier();
122 #endif /* Enable Kernel2 */
125 /* =============================================================================
127 * =============================================================================
129 public static void main(String[] args) {
131 * Tuple for Scalable Data Generation
132 * stores startVertex, endVertex, long weight and other info
134 GraphSDG SDGdata = new GraphSDG();
137 * The graph data structure for this benchmark - see defs.h
139 Graph G = new Graph();
142 * The Global arguments
144 ComputeGraph computeGraphArgs = new ComputeGraph();
148 computeGraphArgs.GPtr = G;
149 computeGraphArgs.SDGdataPtr = SDGdata;
150 /* -------------------------------------------------------------------------
152 * -------------------------------------------------------------------------
156 * User Interface: Configurable parameters, and global program control
159 System.out.println("\nHPCS SSCA #2 Graph Analysis Executable Specification:");
160 System.out.println("\nRunning...\n\n");
162 Globals glb = new Globals();
164 GetUserParameters gup = new GetUserParameters(glb);
165 gup.getUserParameters(args, glb);
167 System.out.println("Number of processors: " + glb.THREADS);
168 System.out.println("Problem Scale: " + glb.SCALE);
169 System.out.println("Max parallel edges: " + glb.MAX_PARAL_EDGES);
170 System.out.println("Percent int weights: " + glb.PERC_INT_WEIGHTS);
171 System.out.println("Probability unidirectional: " + glb.PROB_UNIDIRECTIONAL);
172 System.out.println("Probability inter-clique: " + glb.PROB_INTERCL_EDGES);
173 System.out.println("Subgraph edge length: " + glb.SUBGR_EDGE_LENGTH);
174 System.out.println("Kernel 3 data structure: " + glb.K3_DS);
176 /* Initiate Barriers */
177 Barrier.setBarrier(glb.THREADS);
179 SSCA2[] ssca = new SSCA2[glb.THREADS];
180 int nthreads = glb.THREADS;
182 GenScalData gsd = new GenScalData();
184 Alg_Radix_Smp radixsort = new Alg_Radix_Smp();
186 GetStartLists getStartListsArg = new GetStartLists();
187 getStartListsArg.GPtr = G;
189 /* Create and Start Threads */
190 for(int i = 1; i<nthreads; i++) {
191 ssca[i] = new SSCA2(i, nthreads, glb, computeGraphArgs, gsd, getStartListsArg, radixsort);
194 for(int i = 1; i<nthreads; i++) {
197 System.out.println("\nScalable Data Generator - genScalData() beginning execution...\n");
198 starttime=System.currentTimeMillis();
200 #ifdef USE_PARALLEL_DATA_GENERATION
203 * Scalable Data Generator
205 parallel_work_genScalData(nthreads, glb, SDGdata, gsd, radixsort);
209 GenScalData.genScalData_seq(glb, SDGdata, gsd, radixsort);
213 stoptime=System.currentTimeMillis();
214 System.out.println("\n\tgenScalData() completed execution.");
215 System.out.println("Time="+(stoptime-starttime));
217 #ifdef ENABLE_KERNEL1
219 /* -------------------------------------------------------------------------
220 * Kernel 1 - Graph Construction
222 * From the input edges, construct the graph 'G'
223 * -------------------------------------------------------------------------
225 System.out.println("\nKernel 1 - computeGraph() beginning execution...");
226 starttime=System.currentTimeMillis();
227 parallel_work_computeGraph(nthreads, glb, computeGraphArgs);
228 stoptime=System.currentTimeMillis();
229 System.out.println("\n\tcomputeGraph() completed execution.\n");
230 System.out.println("Time="+(stoptime-starttime));
233 #ifdef ENABLE_KERNEL2
235 /* -------------------------------------------------------------------------
236 * Kernel 2 - Find Max weight and sought string
237 * -------------------------------------------------------------------------
240 getStartListsArg.GPtr = G;
241 getStartListsArg.maxIntWtListPtr = null;
242 getStartListsArg.maxIntWtListSize = 0;
243 getStartListsArg.soughtStrWtListPtr = null;
244 getStartListsArg.soughtStrWtListSize = 0;
246 System.out.println("\nKernel 2 - getStartLists() beginning execution...\n");
247 parallel_work_getStartLists(nthreads, glb, getStartListsArg);
248 System.out.println("\n\tgetStartLists() completed execution.\n");
250 #endif // ENABLE_KERNEL2
252 #ifdef ENABLE_KERNEL3
254 # ifndef ENABLE_KERNEL2
255 # error KERNEL3 requires KERNEL2
259 #ifdef ENABLE_KERNEL3
261 /* -------------------------------------------------------------------------
262 * Kernel 3 - Graph Extraction
263 * -------------------------------------------------------------------------
265 VList[] intWtVList = null;
266 VList[] strWtVList = null;
268 System.out.println("\nKernel 3 - FindSubGraphs() beginning execution...\n");
270 if (glb.K3_DS == 0) {
271 /* TODO Add files for KERNEL 3
272 intWtVList = new VList[G.numVertices * getStartListsArg.maxIntWtListSize];
273 strWtVList = new VList[G.numVertices * getStartListsArg.soughtStrWtListSize];
275 FindSubGraphs0_arg_t findSubGraphs0Arg;
276 findSubGraphs0Arg.GPtr = G;
277 findSubGraphs0Arg.intWtVList = intWtVList;
278 findSubGraphs0Arg.strWtVList = strWtVList;
279 findSubGraphs0Arg.maxIntWtList = getStartListsArg.maxIntWtList;
280 findSubGraphs0Arg.maxIntWtListSize = getStartListsArg.maxIntWtListSize;
281 findSubGraphs0Arg.soughtStrWtList = getStartListsArg.soughtStrWtList;
282 findSubGraphs0Arg.soughtStrWtListSize = getStartListsArg.soughtStrWtListSize;
284 parallel_work_FindSubGraphs0(findSubGraphs0Arg);
287 } else if (glb.K3_DS == 1) {
289 /* TODO Add files for KERNEL 3
290 intWtVList = new VL[getStartListsArg.maxIntWtListSize];
291 strWtVList = new VL[getStartListsArg.soughtStrWtListSize];
293 FindSubGraphs1_arg_t findSubGraphs1Arg;
294 findSubGraphs1Arg.GPtr = G;
295 findSubGraphs1Arg.intWtVLList = intWtVLList;
296 findSubGraphs1Arg.strWtVLList = strWtVLList;
297 findSubGraphs1Arg.maxIntWtList = maxIntWtList;
298 findSubGraphs1Arg.maxIntWtListSize = maxIntWtListSize;
299 findSubGraphs1Arg.soughtStrWtList = soughtStrWtList;
300 findSubGraphs1Arg.soughtStrWtListSize = soughtStrWtListSize;
302 parallel_work_FindSubGraphs1(findSubGraphs1Arg);
305 } else if (glb.K3_DS == 2) {
307 /* TODO Add files for KERNEL 3
308 intWtVList = new VL[getStartListsArg.maxIntWtListSize];
309 strWtVList = new VL[getStartListsArg.soughtStrWtListSize];
311 FindSubGraphs2_arg_t findSubGraphs2Arg;
312 findSubGraphs2Arg.GPtr = G;
313 findSubGraphs2Arg.intWtVDList = intWtVDList;
314 findSubGraphs2Arg.strWtVDList = strWtVDList;
315 findSubGraphs2Arg.maxIntWtList = maxIntWtList;
316 findSubGraphs2Arg.maxIntWtListSize = maxIntWtListSize;
317 findSubGraphs2Arg.soughtStrWtList = soughtStrWtList;
318 findSubGraphs2Arg.soughtStrWtListSize = soughtStrWtListSize;
320 parallel_work_FindSubGraphs2(findSubGraphs2Arg);
327 System.out.println("\n\tFindSubGraphs() completed execution.\n");
329 #endif /* ENABLE_KERNEL3 */
331 #ifdef ENABLE_KERNEL4
333 /* -------------------------------------------------------------------------
334 * Kernel 4 - Graph Clustering
335 * -------------------------------------------------------------------------
338 System.out.println("\nKernel 4 - cutClusters() beginning execution...\n");
339 parallel_work_cutClusters(G);
340 System.out.println("\n\tcutClusters() completed execution.\n");
342 #endif /* ENABLE_KERNEL4 */
348 * Work done by primary thread in parallel with other threads
351 #ifdef USE_PARALLEL_DATA_GENERATION
353 public static void parallel_work_genScalData(int numThread, Globals glb, GraphSDG SDGdata, GenScalData gsd, Alg_Radix_Smp radixsort) {
354 Barrier.enterBarrier();
355 GenScalData.genScalData(0, numThread, glb, SDGdata, gsd, radixsort); // threadId = 0 because primary thread
356 Barrier.enterBarrier();
361 #ifdef ENABLE_KERNEL1
363 public static void parallel_work_computeGraph(int numThread, Globals glb, ComputeGraph computeGraphArgs) {
364 Barrier.enterBarrier();
365 ComputeGraph.computeGraph(0, numThread, glb, computeGraphArgs);
366 Barrier.enterBarrier();
371 #ifdef ENABLE_KERNEL2
373 public static void parallel_work_getStartLists(int numThread, Globals glb, GetStartLists getStartListsArg) {
374 Barrier.enterBarrier();
375 GetStartLists.getStartLists(0, numThread, glb, getStartListsArg);
376 Barrier.enterBarrier();
381 #ifdef ENABLE_KERNEL3
383 /*TODO add files for KERNEL 3
384 public static void parallel_work_FindSubGraphs0(FindSubGraphs0_arg_t findSubGraphs0Arg) {
385 Barrier.enterBarrier();
386 Barrier.enterBarrier();
389 public static void parallel_work_FindSubGraphs1(FindSubGraphs1_arg_t findSubGraphs1Arg) {
390 Barrier.enterBarrier();
391 Barrier.enterBarrier();
394 public static void parallel_work_FindSubGraphs2(FindSubGraphs2_arg_t findSubGraphs2Arg) {
395 Barrier.enterBarrier();
396 Barrier.enterBarrier();
402 #ifdef ENABLE_KERNEL4
404 public static void parallel_work_cutClusters(Graph G) {
405 Barrier.enterBarrier();
406 Barrier.enterBarrier();
413 /* =============================================================================
417 * =============================================================================