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.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     
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     
00283     
00284     
00285     
00286     
00287     
00288     
00289     
00290     
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             
00335             AbstractBody body = (AbstractBody) ProActive.getBodyOnThis();
00336             body.getProActiveSPMDGroupManager().addToBarrierTags(barrierName);
00337             
00338             body.getProActiveSPMDGroupManager().setAwaitedBarrierCalls(barrierName,
00339                 ProActiveGroup.size(group));
00340             
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 }