00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
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 }