adding a test case
[IRC.git] / Robust / src / Benchmarks / Prefetch / MicroBenchmarks / MultiMCWritecommit.java
1 public class WriteArrayObj extends Thread {
2   WriteArrayObj[] mywa;
3   int nthreads;
4   int val, lower, start;
5
6   public WriteArrayObj() {
7   }
8
9   public WriteArrayObj(int lower, WriteArrayObj[] wa, int nthreads, int start) {
10     this.lower = lower;
11     mywa = wa;
12     this.nthreads = nthreads;
13     this.start = start;
14   }
15
16   public void run() {
17     Barrier barr;
18     barr = new Barrier("128.195.136.162");
19     //Create array objects locally
20     atomic { //Remote machine aborts come from here
21       for(int i=lower; i<nthreads*nthreads; i=i+nthreads) {
22         mywa[i] = global new WriteArrayObj();
23         //System.printString("Creating " + i + " element\n");
24       }
25     }
26
27     Barrier.enterBarrier(barr);
28     //System.clearPrefetchCache(); //without invalidation it always reads an old array object therefore we need a clearCache
29     //Write into array elements
30     Integer val;
31      for(int j=0; j<10000; j++) {
32       atomic {
33         val = global new Integer(10);
34         for(int i=start;i<start+nthreads; i++) {
35         //System.printString("Reading element " + i + "\n");
36           mywa[i].val = val.intValue();
37         }
38       }
39     }
40   }
41
42   public static void main(String[] args) {
43     int nthreads;
44     BarrierServer mybarr;
45     if(args.length>0) {
46       nthreads = Integer.parseInt(args[0]);
47     }
48
49     int[] mid = new int[8];
50     mid[0] = (128<<24)|(195<<16)|(136<<8)|162; //dc-1.calit2
51         mid[1] = (128<<24)|(195<<16)|(136<<8)|163; //dc-2.calit2
52         mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3.calit2
53         mid[3] = (128<<24)|(195<<16)|(136<<8)|165; //dc-4.calit2
54         mid[4] = (128<<24)|(195<<16)|(136<<8)|166; //dc-5.calit2
55         mid[5] = (128<<24)|(195<<16)|(136<<8)|167; //dc-6.calit2
56         mid[6] = (128<<24)|(195<<16)|(136<<8)|168; //dc-7.calit2
57         mid[7] = (128<<24)|(195<<16)|(136<<8)|169; //dc-8.calit2
58  
59
60     WriteArrayObj[] wao;
61     atomic {
62       wao=global new WriteArrayObj[nthreads*nthreads]; //create array of objects
63       mybarr = global new BarrierServer(nthreads);
64     }
65     mybarr.start(mid[0]);
66
67     WriteArrayObjWrap[] wawrap = new WriteArrayObjWrap[nthreads];
68
69     atomic {
70       for(int i=0;i<nthreads; i++) {
71         int start = i * nthreads; 
72         wawrap[i] = new WriteArrayObjWrap(global new WriteArrayObj(i,wao, nthreads,start));
73       }
74     }
75
76     boolean waitfordone=true;
77     while(waitfordone) {
78       atomic { //Master aborts come from here
79         if (mybarr.done)
80           waitfordone=false;
81       }
82     }
83
84     for(int i =0; i<nthreads; i++)
85       wawrap[i].wa.start(mid[i]);
86
87     for(int i =0; i<nthreads; i++)
88       wawrap[i].wa.join();
89
90         System.printString("Finished\n");
91   }
92 }