org/objectweb/proactive/core/group/spmd/ProSPMD.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.core.group.spmd;
00032 
00033 import java.lang.reflect.InvocationTargetException;
00034 
00035 import org.objectweb.proactive.ActiveObjectCreationException;
00036 import org.objectweb.proactive.ProActive;
00037 import org.objectweb.proactive.core.body.AbstractBody;
00038 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00039 import org.objectweb.proactive.core.group.Group;
00040 import org.objectweb.proactive.core.group.ProActiveGroup;
00041 import org.objectweb.proactive.core.group.ProxyForGroup;
00042 import org.objectweb.proactive.core.mop.ClassNotReifiableException;
00043 import org.objectweb.proactive.core.node.Node;
00044 import org.objectweb.proactive.core.node.NodeException;
00045 import org.objectweb.proactive.core.node.NodeFactory;
00046 
00047 
00068 public class ProSPMD {
00069 
00081     public static Object newSPMDGroup(String className, Object[][] params,
00082         String nodeName)
00083         throws ClassNotFoundException, ClassNotReifiableException, 
00084             ActiveObjectCreationException, NodeException {
00085         Node[] nodeList = new Node[1];
00086         nodeList[0] = NodeFactory.getNode(nodeName);
00087         return ProSPMD.newSPMDGroup(className, params, nodeList);
00088     }
00089 
00101     public static Object newSPMDGroup(String className, Object[][] params,
00102         String[] nodeListString)
00103         throws ClassNotFoundException, ClassNotReifiableException, 
00104             ActiveObjectCreationException, NodeException {
00105         Node[] nodeList = new Node[nodeListString.length];
00106         for (int i = 0; i < nodeListString.length; i++)
00107             nodeList[i] = NodeFactory.getNode(nodeListString[i]);
00108         return ProSPMD.newSPMDGroup(className, params, nodeList);
00109     }
00110 
00122     public static Object newSPMDGroup(String className, Object[][] params,
00123         Node node)
00124         throws ClassNotFoundException, ClassNotReifiableException, 
00125             ActiveObjectCreationException, NodeException {
00126         Node[] nodeList = new Node[1];
00127         nodeList[0] = node;
00128         return ProSPMD.newSPMDGroup(className, params, nodeList);
00129     }
00130 
00143     public static Object newSPMDGroup(String className, Object[][] params,
00144         Node[] nodeList)
00145         throws ClassNotFoundException, ClassNotReifiableException, 
00146             ActiveObjectCreationException, NodeException {
00147         Object result = ProActiveGroup.newGroup(className);
00148         Group g = ProActiveGroup.getGroup(result);
00149 
00150         if (params != null) {
00151             for (int i = 0; i < params.length; i++) {
00152                 g.add(ProActive.newActive(className, params[i],
00153                         nodeList[i % nodeList.length]));
00154             }
00155         }
00156         ((ProxyForGroup) g).setSPMDGroup(result);
00157         return result;
00158     }
00159 
00172     public static Object newSPMDGroup(String className, Object[][] params,
00173         VirtualNode virtualNode)
00174         throws ClassNotFoundException, ClassNotReifiableException, 
00175             ActiveObjectCreationException, NodeException {
00176         return ProSPMD.newSPMDGroup(className, params, virtualNode.getNodes());
00177     }
00178 
00179     // -------------------------------------------------------------------------
00180     // InParallel OOSPMD constructors
00181     // -------------------------------------------------------------------------
00182 
00193     public static Object newSPMDGroupInParallel(String className,
00194         Object[][] params, String nodeName)
00195         throws ClassNotFoundException, ClassNotReifiableException, 
00196             NodeException {
00197         Node[] nodeList = new Node[1];
00198         nodeList[0] = NodeFactory.getNode(nodeName);
00199         return ProSPMD.newSPMDGroupInParallel(className, params, nodeList);
00200     }
00201 
00212     public static Object newSPMDGroupInParallel(String className,
00213         Object[][] params, String[] nodeListString)
00214         throws ClassNotFoundException, ClassNotReifiableException, 
00215             NodeException {
00216         Node[] nodeList = new Node[nodeListString.length];
00217         for (int i = 0; i < nodeListString.length; i++)
00218             nodeList[i] = NodeFactory.getNode(nodeListString[i]);
00219         return ProSPMD.newSPMDGroupInParallel(className, params, nodeList);
00220     }
00221 
00231     public static Object newSPMDGroupInParallel(String className,
00232         Object[][] params, Node node)
00233         throws ClassNotFoundException, ClassNotReifiableException {
00234         Node[] nodeList = new Node[1];
00235         nodeList[0] = node;
00236         return ProSPMD.newSPMDGroupInParallel(className, params, nodeList);
00237     }
00238 
00250     public static Object newSPMDGroupInParallel(String className,
00251         Object[][] params, VirtualNode virtualNode)
00252         throws ClassNotFoundException, ClassNotReifiableException, 
00253             NodeException {
00254         return ProSPMD.newSPMDGroupInParallel(className, params,
00255             virtualNode.getNodes());
00256     }
00257 
00268     public static Object newSPMDGroupInParallel(String className,
00269         Object[][] params, Node[] nodeList)
00270         throws ClassNotFoundException, ClassNotReifiableException {
00271         Object result = ProActiveGroup.newGroup(className);
00272         ProxyForGroup proxy = (org.objectweb.proactive.core.group.ProxyForGroup) ProActiveGroup.getGroup(result);
00273 
00274         proxy.createMemberWithMultithread(className, null, params, nodeList);
00275 
00276         proxy.setSPMDGroup(result);
00277 
00278         return result;
00279     }
00280 
00281     // -------------------------------------------------------------------------
00282     // End InParallel
00283     // -------------------------------------------------------------------------
00284     //    /**
00285     //     * Set the SPMD group for this
00286     //     * @param o - the new SPMD group
00287     //     */
00288     //    public static void setSPMDGroupOnThis(Object o) {
00289     //        AbstractBody body = (AbstractBody) ProActive.getBodyOnThis();
00290     //        body.setSPMDGroup(o);
00291     //    }
00292 
00297     public static Object getSPMDGroup() {
00298         AbstractBody body = (AbstractBody) ProActive.getBodyOnThis();
00299         return body.getSPMDGroup();
00300     }
00301 
00306     public static int getMySPMDGroupSize() {
00307         return ProActiveGroup.getGroup(ProSPMD.getSPMDGroup()).size();
00308     }
00309 
00314     public static int getMyRank() {
00315         return ProActiveGroup.getGroup(ProSPMD.getSPMDGroup()).indexOf(ProActive.getStubOnThis());
00316     }
00317 
00322     public static void barrier(String barrierName) {
00323         ProSPMD.barrier(barrierName, ProSPMD.getSPMDGroup());
00324     }
00325 
00332     public static void barrier(String barrierName, Object group) {
00333         try {
00334             // add the barrier into the tag list
00335             AbstractBody body = (AbstractBody) ProActive.getBodyOnThis();
00336             body.getProActiveSPMDGroupManager().addToBarrierTags(barrierName);
00337             // set the number of awaited message barriers
00338             body.getProActiveSPMDGroupManager().setAwaitedBarrierCalls(barrierName,
00339                 ProActiveGroup.size(group));
00340             // send the barrier messages
00341             ProxyForGroup proxy = (ProxyForGroup) ProActiveGroup.getGroup(group);
00342             proxy.reify(new MethodCallBarrier(barrierName));
00343         } catch (InvocationTargetException e) {
00344             System.err.println(
00345                 "Unable to invoke a method call to control groups");
00346             e.printStackTrace();
00347         }
00348     }
00349 
00354     public static void barrier(String[] methodNames) {
00355         try {
00356             (ProActive.getStubOnThis()).getProxy().reify(new MethodCallBarrierWithMethodName(
00357                     methodNames));
00358         } catch (InvocationTargetException e) {
00359             System.err.println(
00360                 "Unable to invoke a method call to control groups");
00361             e.printStackTrace();
00362         } catch (Throwable e) {
00363             System.err.println(
00364                 "Unable to invoke a method call to control groups");
00365             e.printStackTrace();
00366         }
00367     }
00368 }

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