org/objectweb/proactive/ext/scilab/util/MandelbrotEventListener.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.SciDoubleMatrix;
00034 
00035 import org.objectweb.proactive.ext.scilab.SciResult;
00036 import org.objectweb.proactive.ext.scilab.monitor.SciEvent;
00037 import org.objectweb.proactive.ext.scilab.monitor.SciEventListener;
00038 import org.objectweb.proactive.ext.scilab.monitor.SciTaskInfo;
00039 import org.objectweb.proactive.ext.scilab.monitor.ScilabService;
00040 
00044 public class MandelbrotEventListener implements SciEventListener{
00045         private FutureDoubleMatrix res;
00046         private ScilabService service;
00047         private int nbBloc;
00048         private int sizeBloc;
00049         private int count;
00050         private double matrixResult[];
00051         
00052         public MandelbrotEventListener(ScilabService service, int nbBloc, FutureDoubleMatrix res){
00053                 this.service = service;
00054                 this.res = res;
00055                 this.nbBloc = nbBloc;
00056                 this.sizeBloc = (res.getNbRow()/nbBloc) * res.getNbCol();
00057                 matrixResult = new double[res.getNbRow() * res.getNbCol()];
00058         }
00059         
00060         public void actionPerformed(SciEvent evt){
00061                 SciTaskInfo sciTaskInfo = (SciTaskInfo) evt.getSource();
00062                 
00063                 if(sciTaskInfo.getState() != SciTaskInfo.SUCCEEDED){
00064                         if(sciTaskInfo.getState() == SciTaskInfo.ABORTED){
00065                                 System.out.println("---------------- Task:" + sciTaskInfo.getIdTask() + " ABORT -----------------");
00066                         }
00067                         return;
00068                 }
00069                 
00070                 System.out.println("IDTASK: " + sciTaskInfo.getIdTask() + " IDRES: " + res.getName());
00071                 if(!sciTaskInfo.getIdTask().startsWith(res.getName())){
00072                         return;
00073                 }
00074                 
00075                 service.removeTask(sciTaskInfo.getIdTask());
00076                 
00077                 System.out.println("---------------- Task:" + sciTaskInfo.getIdTask() +" SUCCESS -----------------");
00078                 
00079                 SciResult sciResult = sciTaskInfo.getSciResult();
00080                 //System.out.println(sciTaskInfo.getTimeGlobal() +" " + sciResult.getTimeExecution());
00081                 
00082                 SciDoubleMatrix sciMatrix = (SciDoubleMatrix) sciResult.getList().get(0);
00083                 int iBloc = Integer.parseInt(sciMatrix.getName().substring(res.getName().length()));
00084                 //System.out.println(iBloc + "\n "+ sciMatrix);
00085                 double array[] = sciMatrix.getData();
00086                 int pos = iBloc * sizeBloc;
00087                 
00088                 
00089                 for(int i= 0; i< sizeBloc; i++){
00090                         matrixResult[pos + i] = array[i];
00091                 }
00092                 
00093                 count++;
00094                 //System.out.println("COUNT = " + count + "  NBBLOC = " + nbBloc);
00095                 if(count == nbBloc){
00096                         res.set(matrixResult);
00097                         service.removeEventListenerEngine(this);
00098                 }
00099         }
00100 
00101 }

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