org/objectweb/proactive/benchmarks/timit/util/observing/commobserv/CommEventData.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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 }

Generated on Mon Jan 22 15:16:04 2007 for ProActive by  doxygen 1.5.1