org/objectweb/proactive/ext/scilab/test/SciTestCalcium.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.Serializable;
00034 
00035 import javasci.SciData;
00036 import javasci.SciDoubleMatrix;
00037 
00038 import org.objectweb.proactive.calcium.Calcium;
00039 import org.objectweb.proactive.calcium.ResourceManager;
00040 import org.objectweb.proactive.calcium.Stream;
00041 import org.objectweb.proactive.calcium.exceptions.MuscleException;
00042 import org.objectweb.proactive.calcium.exceptions.PanicException;
00043 import org.objectweb.proactive.calcium.interfaces.Execute;
00044 import org.objectweb.proactive.calcium.interfaces.Skeleton;
00045 import org.objectweb.proactive.calcium.proactive.ProActiveManager;
00046 import org.objectweb.proactive.calcium.skeletons.Farm;
00047 import org.objectweb.proactive.calcium.skeletons.Seq;
00048 import org.objectweb.proactive.calcium.statistics.StatsGlobal;
00049 import org.objectweb.proactive.ext.scilab.SciEngineWorker;
00050 import org.objectweb.proactive.ext.scilab.SciResult;
00051 import org.objectweb.proactive.ext.scilab.SciTask;
00052 
00053 public class SciTestCalcium implements Serializable{
00054 
00055         private Skeleton<SciTask> root;
00056         private String descriptorPath;
00057         private String nameVN;
00058         
00059         private class SciExecute implements Execute<SciTask>{
00060                 public SciTask execute(SciTask sciTask) {
00061                         SciResult sciResult = SciEngineWorker.executeTask(sciTask);
00062                         sciTask.setListDataOut(sciResult.getList());
00063                         return sciTask;
00064                 }
00065         }
00066         
00067         public SciTestCalcium(String nameVN, String descriptorPath){
00068                 this.nameVN = nameVN;
00069                 this.descriptorPath = descriptorPath;
00070         }
00071         
00072         public void solve(){
00073                 ResourceManager manager= new ProActiveManager(descriptorPath, nameVN);
00074                 //ResourceManager manager= new MultiThreadedManager(1);
00075                 
00076                 Calcium calcium = new Calcium(manager);
00077                 this.root = new Farm<SciTask>(new Seq<SciTask>(new SciExecute()));
00078                 Stream<SciTask> stream = calcium.newStream(root);
00079 
00080                 
00081                 SciTask sciTask;
00082                 
00083                 for(int i=0; i<10; i++){
00084                         sciTask = new SciTask("ScilabTask" + i);
00085                         SciDoubleMatrix sciMatrix = new SciDoubleMatrix("M", 1, 1, new double[]{i});
00086                         
00087                         sciTask.addDataIn(sciMatrix);
00088                         sciTask.addDataOut(sciMatrix);
00089                         sciTask.setJob(sciMatrix.getName() + "=" +  sciMatrix.getName() + "* 2;");
00090                         stream.input(sciTask);
00091                 }
00092                 
00093                 calcium.boot();
00094 
00095                 try {
00096                         SciTask res = stream.getResult();
00097                         while(res != null){
00098                                 for(int i=0; i< res.getListDataOut().size(); i++){
00099                                         SciData sciData = (SciData) res.getListDataOut().get(i);
00100                                         System.out.println(sciData.toString());
00101                                 }
00102                                 res = stream.getResult();
00103                         }
00104                         
00105                         
00106                 } catch (MuscleException e) {
00107                         e.printStackTrace();
00108                 } catch (PanicException e) {
00109                         e.printStackTrace();
00110                 }
00111                 calcium.shutdown();
00112                 StatsGlobal stats = calcium.getStatsGlobal();
00113                 System.out.println(stats);
00114         }
00115         
00116         public static void main(String[] args) {
00117                 if(args.length !=2){
00118                         System.out.println("Invalid number of parameter : " + args.length);
00119                         return;
00120                 }
00121                 
00122                 SciTestCalcium st = new SciTestCalcium(args[0], args[1]);
00123                 st.solve();
00124         }
00125         
00126 
00127 }

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