KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > examples > matrix > Launcher


1 /*
2  * Launcher.java
3  *
4  * Copyright 1997 - 2001 INRIA Project Oasis. All Rights Reserved.
5  *
6  * This software is the proprietary information of INRIA Sophia Antipolis.
7  * 2004 route des lucioles, BP 93 , FR-06902 Sophia Antipolis
8  * Use is subject to license terms.
9  *
10  * @author ProActive Team
11  * @version ProActive 0.7 (October 2001)
12  *
13  * ===================================================================
14  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
15  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL INRIA, THE OASIS PROJECT OR
18  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
21  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
24  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  * ===================================================================
27  *
28  */

29 package org.objectweb.proactive.examples.matrix;
30
31 import org.apache.log4j.Logger;
32 import org.objectweb.proactive.core.node.Node;
33 import org.objectweb.proactive.core.node.NodeException;
34 import org.objectweb.proactive.core.node.NodeFactory;
35
36
37 public class Launcher implements java.io.Serializable JavaDoc {
38     
39         static Logger logger = Logger.getLogger(Launcher.class.getName());
40
41     Node[] nodesList;
42
43     public Launcher () {}
44   
45     public Launcher (String JavaDoc[] nodesNameList) throws NodeException {
46     nodesList = new Node[nodesNameList.length];
47     for (int i=0; i<nodesNameList.length; i++) {
48         nodesList[i] = NodeFactory.getNode(nodesNameList[i]);
49     }
50     }
51
52
53     // MAIN !!!
54
public void start(Matrix m1, Matrix m2, int i) {
55     // DISTRIBUTED MULTIPLICATION
56

57     int matrixSize=m1.getWidth();
58
59
60     long startTime;
61     long endTime;
62     
63     startTime = System.currentTimeMillis();
64
65     //System.out.println("Multiplication!!!!! ");
66
Matrix groupResult =multiply(m1,m2/*group*/);
67
68     //endTime = System.currentTimeMillis() - startTime;
69
//System.out.println(" Distributed Multiplication : " + endTime + " millisecondes\n");
70

71
72     //startTime = System.currentTimeMillis();
73

74     // RECONSTRUCTION
75
try {
76         Matrix result = reconstruction(groupResult,matrixSize); }
77     catch (Exception JavaDoc e) {}
78     
79
80     endTime = System.currentTimeMillis() - startTime;
81     logger.info("\n Result (" +i+ ") : Total time spent = " + endTime + " millisecondes");
82
83     //System.out.println(result);
84
}
85
86
87     public Matrix createMatrix(int size) {
88     Matrix m = new Matrix(size,size);
89     m.initializeWithRandomValues();
90     return m;
91     }
92
93
94     public Matrix distribute (Matrix m) {
95     Matrix verticalSubMatrixGroup = null;
96     verticalSubMatrixGroup = m.transformIntoActiveVerticalSubMatrixGroup(nodesList);
97
98     return verticalSubMatrixGroup;
99     }
100
101
102     public Matrix multiply (Matrix m, Matrix group) {
103     Matrix ma = group.localMultiplyForGroup(m);
104     return ma;
105     }
106
107
108     public Matrix reconstruction (Matrix group, int size) {
109     Matrix result = null;
110
111     result = new Matrix(group,size);
112
113     return result;
114     }
115     
116
117     public String JavaDoc getString(Matrix m) {
118     return m.toString();
119     }
120
121 }
122
Popular Tags