9ad9801f9e56ae30b5964074de6c7bdcc1a8d966
[IRC.git] / Robust / src / Benchmarks / SingleTM / SSCA2 / SSCA2.java
1 /* =============================================================================
2  *
3  * ssca2.java
4  *
5  * =============================================================================
6  * 
7  * Unless otherwise noted, the following license applies to STAMP files:
8  * 
9  * Copyright (c) 2007, Stanford University
10  * All rights reserved.
11  * 
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are
14  * met:
15  * 
16  *     * Redistributions of source code must retain the above copyright
17  *       notice, this list of conditions and the following disclaimer.
18  * 
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
22  *       distribution.
23  * 
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.
27  * 
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.
39  *
40  * =============================================================================
41  */
42
43 public class SSCA2 extends Thread {
44   /*
45    * Tuple for Scalable Data Generation
46    * stores startVertex, endVertex, long weight and other info
47    */
48   GraphSDG SDGdata;
49
50   /**
51    * The graph data structure for this benchmark - see defs.h
52    **/
53   Graph G;
54
55   /**
56    *
57    */
58   ComputeGraph computeGraphArgs;
59
60   /**
61    * thread id
62    **/
63   int threadid;
64
65   /**
66    * Total number of threads
67    **/
68   int numThread;
69
70   /**
71    * Global Arguments 
72    **/
73   Globals glb;
74
75
76   /**
77    *  Gen scalable data
78    **/
79   GenScalData gsd;
80
81   /**
82    **
83    **/
84   GetStartLists getStartListsArg;
85
86
87   Alg_Radix_Smp radixsort;
88
89   public SSCA2(int myId, int numThread, Globals glb, ComputeGraph computeGraphArgs, 
90       GenScalData gsd, GetStartLists getStartListsArg, Alg_Radix_Smp radixsort) {
91     this.threadid = myId;
92     this.numThread = numThread;
93     this.glb = glb;
94     this.computeGraphArgs = computeGraphArgs;
95     this.G = computeGraphArgs.GPtr;
96     this.SDGdata = computeGraphArgs.SDGdataPtr;
97     this.gsd = gsd;
98     this. getStartListsArg = getStartListsArg;
99     this.radixsort = radixsort;
100   }
101
102   public void run() {
103 #ifdef USE_PARALLEL_DATA_GENERATION
104     /* Generate Scaldata */
105     Barrier.enterBarrier();
106     GenScalData.genScalData(threadid, numThread, glb, SDGdata, gsd, radixsort);
107     Barrier.enterBarrier();
108 #endif
109
110 #ifdef ENABLE_KERNEL1
111     /* Kernel 1 */
112     Barrier.enterBarrier();
113     ComputeGraph.computeGraph(threadid, numThread, glb, computeGraphArgs);
114     Barrier.enterBarrier();
115 #endif /* Enable Kernel1 */
116
117 #ifdef ENABLE_KERNEL2
118     /* Kernel 2 */
119     Barrier.enterBarrier();
120     GetStartLists.getStartLists(threadid, numThread, glb, getStartListsArg);
121     Barrier.enterBarrier();
122 #endif /* Enable Kernel2 */
123   }   
124
125   /* =============================================================================
126    * main
127    * =============================================================================
128    */
129   public static void main(String[] args) {
130     /*
131      * Tuple for Scalable Data Generation
132      * stores startVertex, endVertex, long weight and other info
133      */
134     GraphSDG SDGdata = new GraphSDG();
135
136     /*
137      * The graph data structure for this benchmark - see defs.h
138      */
139     Graph G = new Graph();
140
141     /*
142      * The Global arguments
143      */
144     ComputeGraph computeGraphArgs = new ComputeGraph();
145     long starttime;
146     long stoptime;
147
148     computeGraphArgs.GPtr       = G;
149     computeGraphArgs.SDGdataPtr = SDGdata;
150     /* -------------------------------------------------------------------------
151      * Preamble
152      * -------------------------------------------------------------------------
153      */
154
155     /*
156      * User Interface: Configurable parameters, and global program control
157      */
158
159     System.out.println("\nHPCS SSCA #2 Graph Analysis Executable Specification:");
160     System.out.println("\nRunning...\n\n");
161
162     Globals glb = new Globals();
163
164     GetUserParameters gup = new GetUserParameters(glb);
165     gup.getUserParameters(args, glb);
166
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);
175
176     /* Initiate Barriers */
177     Barrier.setBarrier(glb.THREADS);
178
179     SSCA2[] ssca = new SSCA2[glb.THREADS];
180     int nthreads = glb.THREADS;
181
182     GenScalData gsd = new GenScalData();
183
184     Alg_Radix_Smp radixsort = new Alg_Radix_Smp();
185
186     GetStartLists getStartListsArg = new GetStartLists();
187     getStartListsArg.GPtr                = G;
188
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);
192     }
193
194     for(int i = 1; i<nthreads; i++) {
195       ssca[i].start();
196     }
197     System.out.println("\nScalable Data Generator - genScalData() beginning execution...\n");
198     starttime=System.currentTimeMillis();
199
200 #ifdef USE_PARALLEL_DATA_GENERATION
201
202     /*
203      * Scalable Data Generator
204      */
205     parallel_work_genScalData(nthreads, glb, SDGdata, gsd, radixsort);
206
207 #else
208
209     GenScalData.genScalData_seq(glb, SDGdata, gsd, radixsort);
210
211 #endif
212
213     stoptime=System.currentTimeMillis();
214     System.out.println("\n\tgenScalData() completed execution.");
215     System.out.println("Time="+(stoptime-starttime));
216
217 #ifdef ENABLE_KERNEL1
218
219     /* -------------------------------------------------------------------------
220      * Kernel 1 - Graph Construction
221      *
222      * From the input edges, construct the graph 'G'
223      * -------------------------------------------------------------------------
224      */
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));
231 #endif
232
233 #ifdef ENABLE_KERNEL2
234
235     /* -------------------------------------------------------------------------
236      * Kernel 2 - Find Max weight and sought string
237      * -------------------------------------------------------------------------
238      */
239
240     getStartListsArg.GPtr                = G;
241     getStartListsArg.maxIntWtListPtr     = null;
242     getStartListsArg.maxIntWtListSize    = 0;
243     getStartListsArg.soughtStrWtListPtr  = null;
244     getStartListsArg.soughtStrWtListSize = 0;
245
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");
249
250 #endif // ENABLE_KERNEL2 
251
252 #ifdef ENABLE_KERNEL3
253
254 #  ifndef ENABLE_KERNEL2
255 #    error KERNEL3 requires KERNEL2
256 #  endif
257 #endif
258
259 #ifdef ENABLE_KERNEL3
260
261     /* -------------------------------------------------------------------------
262      * Kernel 3 - Graph Extraction
263      * -------------------------------------------------------------------------
264      */
265     VList[] intWtVList = null;
266     VList[] strWtVList = null;
267
268     System.out.println("\nKernel 3 - FindSubGraphs() beginning execution...\n");
269
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];
274
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;
283
284       parallel_work_FindSubGraphs0(findSubGraphs0Arg);
285       */
286
287     } else if (glb.K3_DS == 1) {
288
289       /* TODO Add files for KERNEL 3
290       intWtVList = new VL[getStartListsArg.maxIntWtListSize];
291       strWtVList = new VL[getStartListsArg.soughtStrWtListSize];
292
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;
301
302       parallel_work_FindSubGraphs1(findSubGraphs1Arg);
303       */
304
305     } else if (glb.K3_DS == 2) {
306
307       /* TODO Add files for KERNEL 3
308       intWtVList = new VL[getStartListsArg.maxIntWtListSize];
309       strWtVList = new VL[getStartListsArg.soughtStrWtListSize];
310
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;
319
320       parallel_work_FindSubGraphs2(findSubGraphs2Arg);
321       */
322
323     } else {
324       ;
325     }
326
327     System.out.println("\n\tFindSubGraphs() completed execution.\n");
328
329 #endif /* ENABLE_KERNEL3 */
330
331 #ifdef ENABLE_KERNEL4
332
333     /* -------------------------------------------------------------------------
334      * Kernel 4 - Graph Clustering
335      * -------------------------------------------------------------------------
336      */
337
338     System.out.println("\nKernel 4 - cutClusters() beginning execution...\n");
339     parallel_work_cutClusters(G);
340     System.out.println("\n\tcutClusters() completed execution.\n");
341
342 #endif /* ENABLE_KERNEL4 */
343
344     System.exit(0);
345   }
346
347   /**
348    * Work done by primary thread in parallel with other threads
349    **/
350
351 #ifdef USE_PARALLEL_DATA_GENERATION
352
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();
357   }
358
359 #endif
360
361 #ifdef ENABLE_KERNEL1
362
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();
367   }
368
369 #endif
370
371 #ifdef ENABLE_KERNEL2
372
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();
377   }
378
379 #endif
380
381 #ifdef ENABLE_KERNEL3
382
383   /*TODO add files for KERNEL 3
384   public static void parallel_work_FindSubGraphs0(FindSubGraphs0_arg_t findSubGraphs0Arg) {
385     Barrier.enterBarrier();
386     Barrier.enterBarrier();
387   }
388
389   public static void parallel_work_FindSubGraphs1(FindSubGraphs1_arg_t findSubGraphs1Arg) {
390     Barrier.enterBarrier();
391     Barrier.enterBarrier();
392   }
393
394   public static void parallel_work_FindSubGraphs2(FindSubGraphs2_arg_t findSubGraphs2Arg) {
395     Barrier.enterBarrier();
396     Barrier.enterBarrier();
397   }
398   */
399
400 #endif
401
402 #ifdef ENABLE_KERNEL4
403
404   public static void parallel_work_cutClusters(Graph G) {
405     Barrier.enterBarrier();
406     Barrier.enterBarrier();
407   }
408
409 #endif
410
411 }
412
413 /* =============================================================================
414  *
415  * End of ssca2.java
416  *
417  * =============================================================================
418  */