org/objectweb/proactive/ext/scilab/util/GridMatrix.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.util;
00032 
00033 import javasci.SciData;
00034 import javasci.SciDoubleMatrix;
00035 
00036 import org.objectweb.proactive.ext.scilab.SciTask;
00037 import org.objectweb.proactive.ext.scilab.monitor.SciEventListener;
00038 import org.objectweb.proactive.ext.scilab.monitor.ScilabService;
00042 public class GridMatrix {
00057         public static FutureDoubleMatrix calMandelbrot(ScilabService service, String name,  int xres, int yres, double xmin, double xmax, double ymin, double ymax, int precision, int nbBloc){
00058                 FutureDoubleMatrix res = new FutureDoubleMatrix(name, xres, yres);
00059                 
00060                 service.addEventListenerTask(new MandelbrotEventListener (service, nbBloc, res));
00061                 
00062                 SciTask sciTask;
00063                 boolean isSend;
00064                 int nbRow = (int) yres/nbBloc;
00065                 double sizeBloc = (double) ((ymax - ymin)/nbBloc);
00066                 
00067                 double y1 = ymin;
00068                 double y2 = ymin + sizeBloc;
00069                 for(int i=0; i< nbBloc; i++){
00070                         sciTask = new SciTask(name + i );
00071                         sciTask.addDataOut(new SciData(name + i));
00072                         sciTask.setJob(SciMath.formulaMandelbrot(name + i, nbRow, xres, xmin, xmax, y1, y2, precision));
00073                         service.sendTask(sciTask);
00074                         y1 = y2;
00075                         y2 += sizeBloc;
00076                 }
00077                 return res;
00078         }
00079         
00080         
00089         public static FutureDoubleMatrix calPi(ScilabService service, String name, int precision, int nbBloc){
00090                 FutureDoubleMatrix res = new FutureDoubleMatrix(name, 1, 1);
00091                 int sizeBloc = precision/nbBloc;
00092                 service.addEventListenerTask(new PiEventListener (service, nbBloc, res));
00093                 
00094                 SciTask sciTask;
00095                 boolean isSend;
00096                 for(int i=0; i<nbBloc; i++){
00097                         sciTask = new SciTask(name + i);
00098                         sciTask.addDataOut(new SciData("pi" + i));
00099                         sciTask.setJob(SciMath.formulaPi("pi" + i, i, sizeBloc));
00100                         service.sendTask(sciTask);
00101                 }
00102                 return res;
00103         }
00104         
00117         public static FutureDoubleMatrix mult(ScilabService service, String name, double [] matrix1, int nbRow1, int nbCol1, double [] matrix2, int nbRow2, int nbCol2){
00118                 
00119                 FutureDoubleMatrix res = new FutureDoubleMatrix(name, nbRow2, nbCol2);
00120         
00121                 SciEventListener eventListener = new MultEventListener(service, res);
00122                 service.addEventListenerTask(eventListener);
00123                 int nbTask = service.getNbEngine();
00124                 
00125                 if(matrix1.length != nbRow1*nbCol1 || matrix2.length != nbRow2*nbCol2 || nbCol1 !=nbRow2){
00126                         System.out.println("---------------INVALID MATRIX FOR MULTIPLICATION-----------------");
00127                         return null;
00128                         
00129                 }
00130 
00131                 SciDoubleMatrix sciMatrix = new SciDoubleMatrix("M", nbRow1, nbCol1, matrix1);
00132                 
00133                 
00134                 boolean isSend;
00135                 int nbRow = nbRow2;
00136                 int nbCol = nbCol2/nbTask;
00137                 int sizeSubMatrix = nbRow * nbCol;
00138                 
00139                 for(int i=0; i<nbTask; i++){
00140                         double []subMatrix = new double[sizeSubMatrix];
00141                         
00142                         
00143                         for(int j=0; j<sizeSubMatrix; j++){
00144                                 subMatrix[j] = matrix2[j + i*sizeSubMatrix];
00145                         }
00146                         
00147                         
00148                         SciDoubleMatrix sciSubMatrix = new SciDoubleMatrix("M" + i, nbRow, nbCol, subMatrix);
00149                         SciTask sciTask = new SciTask(name + i);
00150                         sciTask.addDataIn(sciMatrix);
00151                         sciTask.addDataIn(sciSubMatrix);
00152                         sciTask.addDataOut(new SciData("M" + i));
00153                         sciTask.setJob(sciSubMatrix.getName() + "=" + sciMatrix.getName() + "*" + sciSubMatrix.getName()+ ";");
00154                         service.sendTask(sciTask);
00155                 }
00156                 return res;
00157         }
00158 }

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