00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030  
00031 package org.objectweb.proactive.benchmarks.timit.util.observing.commobserv;
00032 
00033 import org.objectweb.proactive.benchmarks.timit.util.observing.EventData;
00034 
00041 public class CommEventData implements EventData {
00042 
00046     private static final long serialVersionUID = -5062574158941020818L;
00047 
00048     private String name;
00049 
00050     private int subjectRank;
00051 
00052     private int[] markedCommunication;
00053 
00054     private int[][] allValues;
00055 
00069     public CommEventData(String name, int groupSize, int subjectRank) {
00070         this.name = name;
00071         this.markedCommunication = new int[groupSize];
00072         this.subjectRank = subjectRank;
00073     }
00074 
00082     public void setData(Object object) {
00083         this.markedCommunication = (int[]) object;
00084     }
00085 
00091     public String getName() {
00092         return this.name;
00093     }
00094 
00101     public Object getData() {
00102         return this.markedCommunication.clone();
00103     }
00104 
00125     public Object collapseWith(EventData anotherData, int anotherRank) {
00126         int length = this.markedCommunication.length;
00127         if (this.allValues == null) {
00128             this.allValues = new int[length][length];
00129             System.arraycopy(this.markedCommunication, 0,
00130                     this.allValues[this.subjectRank], 0, length);
00131         }
00132         if (anotherData.equals(this)) {
00133             return this.allValues.clone();
00134         }
00135 
00136         int[] anotherCommArray = (int[]) anotherData.getData();
00137 
00138         for (int i = 0; i < length; i++) {
00139             this.allValues[anotherRank][i] += anotherCommArray[i];
00140         }
00141 
00142         return this.allValues.clone();
00143     }
00144 
00153     public void mark(int targetRank, double value) {
00154         this.markedCommunication[targetRank] += (int) value;
00155     }
00156 
00162     public Object getFinalized() {
00163         return this.allValues.clone();
00164     }
00165 
00172     public String toString() {
00173 
00174         if (this.allValues == null) {
00175             return "";
00176         }
00177         String res = "\n";
00178 
00179         int maxLength = ("" + getMaxValue(this.allValues)).length();
00180         StringBuilder sb = null;
00181         String[] lines = new String[this.allValues.length];
00182         int i, j;
00183 
00184         for (i = 0; i < this.allValues.length; i++) {
00185             lines[i] = "";
00186             for (j = 0; j < this.allValues.length; j++) {
00187                 sb = new StringBuilder(lines[i]);
00188                 sb.append(String.format("%1$" + maxLength + "s",
00189                         this.allValues[i][j])
00190                         + " ");
00191                 lines[i] = sb.toString();
00192             }
00193         }
00194 
00195         for (i = lines.length - 1; i >= 0; i--) {
00196             res += lines[i] + "\n";
00197         }
00198 
00199         return res;
00200     }
00201 
00209     public static int getMaxValue(int[][] a) {
00210         int i, j, max = 0;
00211 
00212         for (i = 0; i < a.length; i++) {
00213             for (j = 0; j < a.length; j++) {
00214                 if (a[i][j] > max) {
00215                     max = a[i][j];
00216                 }
00217             }
00218         }
00219         return max;
00220     }
00221 }