org/objectweb/proactive/ext/scilab/test/SciTestLibrary.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.io.File;
00034 import java.util.HashMap;
00035 import java.util.Vector;
00036 
00037 import javasci.SciData;
00038 import javasci.SciDoubleMatrix;
00039 
00040 import org.objectweb.proactive.ProActive;
00041 import org.objectweb.proactive.core.ProActiveException;
00042 import org.objectweb.proactive.core.node.Node;
00043 import org.objectweb.proactive.core.util.wrapper.BooleanWrapper;
00044 import org.objectweb.proactive.ext.scilab.SciDeployEngine;
00045 import org.objectweb.proactive.ext.scilab.SciEngine;
00046 import org.objectweb.proactive.ext.scilab.SciResult;
00047 import org.objectweb.proactive.ext.scilab.SciTask;
00048 import org.objectweb.proactive.filetransfer.FileTransfer;
00049 import org.objectweb.proactive.filetransfer.FileVector;
00050 
00051 
00052 public class SciTestLibrary {
00053     private HashMap mapEngine;
00054 
00055     public SciTestLibrary(String nameVN, String pathDescriptor,
00056         String[] arrayEngine, String localSource, String remoteDest)
00057         throws ProActiveException {
00058 
00059         //Deployment
00060          mapEngine = SciDeployEngine.deploy(nameVN, pathDescriptor, arrayEngine);
00061 
00062           //Activation
00063           Vector<BooleanWrapper> listStateEngine = new Vector<BooleanWrapper>();
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           //Transfer
00070           Object[] arrayKey = mapEngine.keySet().toArray();
00071           try{
00072                   FileVector fv;
00073                   for(int i=0; i<arrayKey.length; i++){
00074                           Node node = SciDeployEngine.getEngineNode((String)arrayKey[i]);
00075                           System.out.println("Sending file to:"+node.getNodeInformation().getURL());
00076                           fv=FileTransfer.pushFile(node, new File(localSource), new File(remoteDest));
00077                           fv.waitForAll();
00078                   }
00079           }catch(Exception e){
00080                   System.out.println("Printing exception");
00081                   e.printStackTrace();
00082           }
00083 
00084 
00085           //Loading
00086           SciTask sciTaskEnv;
00087           SciEngine sciEngine;
00088           for(int i=0; i<arrayKey.length; i++){
00089                   sciTaskEnv = new SciTask("sciEnv" + arrayKey[i]);
00090                       sciTaskEnv.setJob("exec('" + remoteDest + "');");
00091                       sciEngine = (SciEngine) this.mapEngine.get(arrayKey[i]);
00092                       sciEngine.execute(sciTaskEnv);
00093           }
00094 
00095           //Call Function
00096               SciTask sciTaskCallFun;
00097               SciResult sciResult;
00098               SciData dataIn;
00099               SciData dataOut;
00100               for(int i=0; i<arrayKey.length; i++){
00101                       sciTaskCallFun = new SciTask("sciCallFun" + arrayKey[i]);
00102                       dataIn = new SciDoubleMatrix("x", 1, 1, new double[]{i});
00103                       dataOut = new SciData("z");
00104                       sciTaskCallFun.addDataIn(dataIn);
00105                       sciTaskCallFun.addDataOut(dataOut);
00106                       sciTaskCallFun.setJob(dataOut.getName() + "= mult(" + dataIn.getName() + "," +  dataIn.getName() + ");");
00107                       sciEngine = (SciEngine) this.mapEngine.get(arrayKey[i]);
00108                       sciResult = sciEngine.execute(sciTaskCallFun);
00109                       System.out.println(sciResult.get(dataOut.getName()));
00110               }
00111               
00112               for(int i=0; i<arrayKey.length; i++){
00113                   sciEngine = (SciEngine) this.mapEngine.get(arrayKey[i]);
00114                         try{
00115                                 sciEngine.exit();
00116                         }catch(RuntimeException e ){
00117                         }
00118               }
00119               System.exit(0);
00120     }
00121 
00122     public static void main(String[] args) throws ProActiveException {
00123         if (args.length != 5) {
00124             System.out.println("Invalid number of parameter : " + args.length);
00125             return;
00126         }
00127 
00128         int nbEngine = Integer.parseInt(args[2]);
00129         String[] arrayId = new String[nbEngine];
00130 
00131         for (int i = 0; i < nbEngine; i++) {
00132             arrayId[i] = "Scilab" + i;
00133         }
00134 
00135         new SciTestLibrary(args[0], args[1], arrayId, args[3], args[4]);
00136     }
00137 }

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