org/objectweb/proactive/ext/scilab/test/SciTest3.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.ext.scilab.test;
00032 
00033 import java.util.HashMap;
00034 import java.util.Vector;
00035 
00036 import javasci.SciData;
00037 import javasci.SciDoubleMatrix;
00038 
00039 import org.objectweb.proactive.ProActive;
00040 import org.objectweb.proactive.core.util.wrapper.BooleanWrapper;
00041 import org.objectweb.proactive.ext.scilab.SciDeployEngine;
00042 import org.objectweb.proactive.ext.scilab.SciEngine;
00043 import org.objectweb.proactive.ext.scilab.SciResult;
00044 import org.objectweb.proactive.ext.scilab.SciTask;
00045 
00046 public class SciTest3 {
00047         private String arrayEngine[];
00048         private HashMap mapEngine;
00049         private int countEngine = 0;
00050         
00051         public SciTest3(String nameVN, String pathDescriptor, String[] arrayEngine){
00052                 
00053                 Vector<BooleanWrapper> listStateEngine = new Vector<BooleanWrapper>();
00054                 this.arrayEngine = arrayEngine;
00055                 SciData m1 = new SciDoubleMatrix("a",1, 1, new double[]{10});
00056             SciData m2 = new SciDoubleMatrix("b",1, 1, new double[]{20});
00057             SciData m3 = new SciData("x");
00058             SciData m4 = new SciData("y");
00059                         
00060             //Deployment
00061             mapEngine = SciDeployEngine.deploy(nameVN, pathDescriptor, arrayEngine);
00062                 
00063             //Activation
00064                 for(int i=0; i<mapEngine.size(); i++){
00065                         listStateEngine.add(((SciEngine) mapEngine.get(arrayEngine[i])).activate());
00066                 }
00067                 
00068                 ProActive.waitForAll(listStateEngine);
00069                 
00070                 for(int i=0; i<mapEngine.size(); i++){
00071                         if(!listStateEngine.get(i).booleanValue()){
00072                                 System.out.println("->Activation Error");
00073                                 return;
00074                         }
00075                 }
00076                 
00077                 //Computation
00078                 SciEngine sciEngine;
00079                 
00080                 SciTask task1 = new SciTask("id1");
00081                 task1.addDataIn(m1);
00082                 task1.addDataIn(m2);
00083                 task1.addDataOut(m3);
00084                 task1.setJob("x = a+b;");
00085                 
00086                 sciEngine = (SciEngine) mapEngine.get(this.getNextEngine());
00087                 
00088                 //asynchronous call
00089                 SciResult result1 = sciEngine.execute(task1);
00090                 
00091                 SciTask task3 = new SciTask("id3");
00092                 task3.addDataIn(m1);
00093                 task3.addDataOut(m1);
00094                 task3.setJob("a = a*2;");
00095                 
00096                 sciEngine = (SciEngine) mapEngine.get(this.getNextEngine());
00097         //asynchronous call
00098                 SciResult result3 = sciEngine.execute(task3);
00099                 
00100                 
00101                 SciTask task2 = new SciTask("id2");
00102                 
00103                 //wait value
00104                 task2.addDataIn(result1.get("x"));
00105                 task2.addDataIn(m2);
00106                 task2.addDataOut(m4);
00107                 task2.setJob("y = x+b;");
00108                 
00109                 sciEngine = (SciEngine) mapEngine.get(this.getNextEngine());
00110         //asynchronous call
00111                 SciResult result2 = sciEngine.execute(task2);
00112                 
00113                 System.out.println(result1.get("x").toString());
00114                 System.out.println(result3.get("a").toString());
00115                 System.out.println(result2.get("y").toString());
00116                 
00117                 //SciDeployEngine.killAll();
00118                 System.exit(0);
00119         }
00120         
00121         
00122         //get id of the nex engine 
00123         public String getNextEngine(){
00124                 countEngine++;
00125                 if(countEngine == mapEngine.size()){
00126                         countEngine = 0;
00127                 }
00128                 return arrayEngine[countEngine];
00129         }
00130         
00131         public static void main(String[] args) {
00132                 if(args.length != 3){
00133                         System.out.println("Invalid number of parameter : " + args.length);
00134                         return;
00135                 }
00136                 
00137                 int nbEngine = Integer.parseInt(args[2]);
00138                 String arrayId[] = new String[nbEngine];
00139                 
00140                 for(int i=0; i< nbEngine; i++){
00141                         arrayId[i] = "Scilab" + i;
00142                 }
00143                 
00144                 new SciTest3(args[0], args[1], arrayId);
00145         }
00146 }

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