1e0d50e604ae1a8ffe8ceb7b8b1f984249900c07
[IRC.git] / Robust / src / Benchmarks / Prefetch / MicroBenchmarks / dsm / Simple.java
1 public class Simple extends Thread {
2   Counting mycount;
3         int id;
4   public Simple(Counting mycount, int i) {
5     this.mycount = mycount;
6                 this.id = i;
7   }
8
9   public void run() {
10     
11                 int threadid;
12
13     atomic {
14                         threadid = id;
15 //                      System.println("\n##threadid: " + threadid + "\n");
16                 }
17 //    if(threadid == ((128<<24)|(195<<16)|(180<<8)|24))
18   //         System.exit(0);
19
20                         for(int i = 0;  i < 1000; i++) {
21         atomic {
22 //                                      System.println("##threadid: " + threadid);
23                                         mycount.increment();
24                                 }
25
26 //        if(threadid == ((128<<24)|(195<<16)|(180<<8)|21)) {
27           for(int j =0;j< 4;j++)  {
28             atomic {
29  //             System.out.println("##Threadid " + j + " : " + getStatus(j));
30             }
31           }
32  //       }
33                         }
34         
35         FileOutputStream output = new FileOutputStream("output"+threadid);
36         int cc;
37
38         atomic {
39             cc = mycount.count;
40         }
41
42     String outStr = "Count = " + cc + "\n";
43     output.write(outStr.getBytes());                          
44                 System.out.println("\n\n\nFinished!!!!!!\n\n\n\n");
45     output.close();
46     
47                 
48   }
49
50   public static void main(String[] args) {
51     Simple[] s;
52     Counting c;
53     int numthreads = 3;
54     int[] mid = new int[numthreads];
55     FileOutputStream out = new FileOutputStream("output");
56
57 /*              mid[0] = (128<<24)|(195<<16)|(180<<8)|26; //dw-7
58         mid[1] = (128<<24)|(195<<16)|(180<<8)|24; //dw-5
59                 mid[2] = (128<<24)|(195<<16)|(180<<8)|21; //dw-2
60 */
61 //              mid[1] = (128<<24)|(195<<16)|(180<<8)|22; //dw-3
62         mid[0] = (128<<24)|(195<<16)|(136<<8)|162; //dc-1
63                 mid[1] = (128<<24)|(195<<16)|(136<<8)|163; //dc-2
64                 mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3
65                 mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3
66                 mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3
67                 mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3
68                 mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3
69                 mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3
70 //              mid[3] = (128<<24)|(195<<16)|(136<<8)|165; //dc-4
71
72
73                 atomic {
74       
75       c = global new Counting();
76       s = global new Simple[numthreads];
77       for(int i = 0; i < numthreads; i++) {
78         s[i] = global new Simple(c, mid[i]);
79       }
80       
81     }
82
83     ccc od = new ccc();
84     ddd ad = new ddd();
85     od.increment();
86
87     od.increment(3);
88       
89     od = (ccc)ad;
90
91     od.increment(5);
92
93
94
95     
96                 System.out.println("##Done creating objects");
97     Simple tmp;
98     for(int i = 0; i <  numthreads; i++) {
99       atomic {
100         tmp = s[i];
101       }
102                         System.out.println("##Temp gets simple object; start temp simple object");
103 //      tmp.start(mid[i]);
104       Thread.myStart(tmp,mid[i]);
105     }
106
107     System.out.println("\n\n##DONE starting Threads\n");
108
109     for(int i = 0; i < numthreads; i++) {
110       atomic {
111         tmp = s[i];
112       }
113       System.out.println("##Wait\n");
114       tmp.join();
115     }
116     //print count
117     int finalcount;
118     atomic {
119       finalcount = c.count;
120     }
121
122     String outStr = "Count = " + finalcount + "\n";
123     out.write(outStr.getBytes());
124     System.printString("Count = "+finalcount+"\n");
125     out.close();
126     
127   }
128
129 }
130
131 class Counting {
132   global int count;
133   public Counting() {
134     this.count = 0;
135   }
136
137   public increment() {
138     count = count + 1;
139   }
140 }
141
142 class ccc {
143   int dd;
144   public ccc() {
145     this.dd = 0;
146   }
147
148   public increment() {
149     dd++;
150   }
151
152   public increment(int o) {
153     dd += o;
154   }
155 }
156
157 class ddd extends ccc {
158
159   public ddd() {
160     this.dd = 0;
161   }
162   public increment(int u)
163   {
164     dd = u;
165   }
166 }