33dde4823a944471f225e8053332c23a7676fe81
[IRC.git] / Robust / src / Benchmarks / oooJava / power / Power.java
1 /**
2  * A Java implementation of the <tt>power</tt> Olden benchmark. The original
3  * algorithm is from the following paper:
4  * <p>
5  * <cite> S. Lumetta, L. Murphy, X. Li, D. Culler, and I. Khalil. "Decentralized
6  * optimal power pricing: The development of a parallel program." Supercomputing
7  * '93, 243-249 </cite>
8  * <p>
9  * Note - the number of customers is fixed at 10,000 for this benchmark. We
10  * create a data structure that contains 1 root (the (power substation). There
11  * are 10 main feeders from the root and each feeder branches to 20 lateral
12  * nodes. Each lateral node is the head of a line of five branch nodes and each
13  * branch has 10 customers. In total, there are 10,000 customers (and 1201
14  * internal nodes).
15  * <p>
16  * The power pricing problems sets the price of each customer's power
17  * consumption so that the economic efficiency of the whole community is
18  * maximized.
19  **/
20 public class Power {
21         /**
22          * Should we print the results as we run the benchmark
23          **/
24 //      static boolean printResults;
25         /**
26          * Print information messages?
27          **/
28 //      static boolean printMsgs;
29
30         /**
31          * The main routine which creates the power network and runs the simulation
32          * 
33          * @param args
34          *            the command line args
35          **/
36         public static void main(String args[]) {
37
38                 boolean printResults = false;
39                 boolean printMsgs =true;
40                 // the input size is fixed, but the user may want the result printed
41                 // parseCmdLine(args);
42
43                 // initial pass
44                 long start0 = System.currentTimeMillis();
45 //              Root r = new Root(10, 20, 5, 10);
46 //              Root r = new Root(24, 18, 5, 10);
47 //              Root r = new Root(22, 20, 5, 10);
48                 Root r = new Root(21, 20, 5, 10);
49 //              Root r = new Root(20, 20, 5, 10);
50                 long end0 = System.currentTimeMillis();
51
52                 long start1 = System.currentTimeMillis();
53                 r.compute();
54                 r.nextIter(false, 0.7, 0.14);
55
56                 while (true) {
57                         r.compute();
58                         if (printResults)
59                                 System.out.println(r);
60
61                         if (r.reachedLimit())
62                                 break;
63
64                         r.nextIter(printResults);
65                 } /* while */
66
67                 long end1 = System.currentTimeMillis();
68
69                 if (printMsgs) {
70                         System.out.println("Power build time " + (end0 - start0) / 1000.0);
71                         System.out
72                                         .println("Power compute time " + (end1 - start1) / 1000.0);
73                         System.out.println("Power total time " + (end1 - start0) / 1000.0);
74                 }
75                 System.out.println("Done!");
76         }
77
78         /**
79          * Parse the command line options.
80          * 
81          * @param args
82          *            the command line options.
83          **/
84         /*
85          * private static final void parseCmdLine(String args[]) { int i = 0; String
86          * arg;
87          * 
88          * while (i < args.length && args[i].startsWith("-")) { arg = args[i++]; if
89          * (arg.equals("-h")) { usage(); } else if (arg.equals("-p")) { printResults
90          * = true; } else if (arg.equals("-m")) { printMsgs = true; } } }
91          */
92
93         /**
94          * The usage routine which describes the program options.
95          **/
96         private static final void usage() {
97                 System.out.println("usage: java Power [-p] [-m] [-h]");
98                 System.out.println("    -p (print results)");
99                 System.out.println("    -m (print informative messages)");
100                 System.out.println("    -h (this message)");
101                 System.exit(0);
102         }
103
104 }