1 package run; 2 import uka.karmi.rmi.RemoteException; 3 4 import jp.lang.*; 5 6 import jp.sync.Barrier; 7 8 import jp.sync.BarrierFactory; 9 10 public class Impact implements uka.patch.Patchable, uka.transport.Transportable { createPatch(Object _copy, uka.patch.PatchOutput po)11 public void createPatch(Object _copy, uka.patch.PatchOutput po) throws java.io.IOException { 12 Impact copy = (Impact)_copy; 13 } applyPatch(Object _copy, uka.patch.PatchInput pi)14 public void applyPatch(Object _copy, uka.patch.PatchInput pi) throws java.io.IOException, ClassNotFoundException { 15 Impact copy = (Impact)_copy; 16 } descendReferences(uka.patch.ReferenceConsumer c)17 public void descendReferences(uka.patch.ReferenceConsumer c) throws java.io.IOException { 18 } filterReferences(uka.patch.ReferenceFilter f)19 public void filterReferences(uka.patch.ReferenceFilter f) { 20 } flatClone()21 public Object flatClone() { 22 try { 23 return super.clone(); 24 } catch (CloneNotSupportedException ex) { 25 throw new AssertionError("Declared Cloneable but clone() is still unsupported"); 26 } 27 } 28 public static final uka.transport.TransportDescriptor TRANSPORT_DESCRIPTOR = new uka.transport.TransportDescriptor(){ 29 public Object unmarshalReference(uka.transport.UnmarshalStream s, int id) throws java.io.IOException, ClassNotFoundException { 30 return new Impact(s, id); 31 } 32 public boolean unmarshal(Object obj, uka.transport.UnmarshalStream s) throws ClassNotFoundException, java.io.IOException { 33 ((Impact)obj).unmarshal(s); 34 return false; 35 } 36 public void marshalReference(Object obj, uka.transport.MarshalStream s) throws java.io.IOException { 37 ((Impact)obj).marshalReference(s); 38 } 39 public void marshal(Object obj, uka.transport.MarshalStream s) throws java.io.IOException { 40 ((Impact)obj).marshal(s); 41 } 42 public Object deepClone(Object orig, int id, uka.transport.DeepClone _helper) throws CloneNotSupportedException { 43 try { 44 return new Impact((Impact)orig, id, _helper); 45 } catch (java.io.IOException ex) { 46 throw (CloneNotSupportedException)new CloneNotSupportedException().initCause(ex); 47 } 48 } 49 public boolean deepCloneReferences(Object orig, Object copy, uka.transport.DeepClone _helper) throws CloneNotSupportedException { 50 ((Impact)copy).deepCloneReferences((Impact)orig, _helper); 51 return false; 52 } 53 public Class getType() { 54 return Impact.class; 55 } 56 }; getTransportDescriptor()57 public uka.transport.TransportDescriptor getTransportDescriptor() { 58 return TRANSPORT_DESCRIPTOR; 59 } Impact(uka.transport.UnmarshalStream _stream, int _id)60 public Impact(uka.transport.UnmarshalStream _stream, int _id) throws java.io.IOException, ClassNotFoundException { 61 _stream.register(this, _id); 62 } unmarshal(uka.transport.UnmarshalStream _stream)63 public void unmarshal(uka.transport.UnmarshalStream _stream) throws java.io.IOException, ClassNotFoundException { 64 } marshalReference(uka.transport.MarshalStream _stream)65 public void marshalReference(uka.transport.MarshalStream _stream) throws java.io.IOException { 66 } marshal(uka.transport.MarshalStream _stream)67 public void marshal(uka.transport.MarshalStream _stream) throws java.io.IOException { 68 } Impact(Impact _orig, int _id, uka.transport.DeepClone _helper)69 public Impact(Impact _orig, int _id, uka.transport.DeepClone _helper) throws CloneNotSupportedException, java.io.IOException { 70 _helper.add(_id, this); 71 } deepCloneReferences(Impact _orig, uka.transport.DeepClone _helper)72 public void deepCloneReferences(Impact _orig, uka.transport.DeepClone _helper) throws CloneNotSupportedException { 73 } Impact()74 public Impact() { 75 super(); 76 } main(java.lang.String[] args)77 public static void main(java.lang.String[] args) { 78 System.out.println("\n=========== Welcome to Impact =========="); 79 System.out.println("= Impact is free software and licensed ="); 80 System.out.println("= under GPL. Please note that it comes ="); 81 System.out.println("= with no warranties whatsoever. ="); 82 System.out.println("= ="); 83 System.out.println("= Report any bugs at our webpage: ="); 84 System.out.println("= http://impact.sourceforge.net ="); 85 System.out.println("=============== ENJOY!!!! ==============\n\n"); 86 int nr_CPU = DistributedRuntime.getMachineCnt(); 87 if (args.length == 1) { 88 if (nr_CPU > 0) try { 89 run_cluster(args[0], nr_CPU); 90 } catch (Error e) { 91 e.printStackTrace(); 92 return; 93 } catch (Exception e) { 94 e.printStackTrace(); 95 return; 96 } else { 97 nr_CPU = Runtime.getRuntime().availableProcessors(); 98 try { 99 run_smp(args[0], nr_CPU); 100 } catch (Exception e) { 101 e.printStackTrace(); 102 return; 103 } 104 } 105 } else { 106 System.out.println("Impact - A simple explicit dynamic program\n"); 107 System.out.println("Syntax: java run.Impact sourcefile.in to start solver"); 108 } 109 System.exit(0); 110 } run_smp(String fname, int nr_CPU)111 public static void run_smp(String fname, int nr_CPU) throws RemoteException, Exception { 112 System.out.println("*******************************"); 113 System.out.println("*** Solver has been invoked ***"); 114 System.out.println("*******************************\n\n"); 115 System.out.println("Running on " + nr_CPU + " clients\n\n"); 116 ModelSmp node = new ModelSmp(nr_CPU, fname); 117 node.run(); 118 System.out.println("*** Solution completed ***"); 119 } run_cluster(final String fname, int nr_CPU)120 public static void run_cluster(final String fname, int nr_CPU) throws Exception { 121 final ModelCluster[] nodes; 122 final Barrier barrier; 123 System.out.println("********************************"); 124 System.out.println("*** Cluster has been invoked ***"); 125 System.out.println("********************************\n\n"); 126 System.out.println("Running on " + nr_CPU + " clients\n\n"); 127 nodes = new ModelCluster[nr_CPU]; 128 barrier = BarrierFactory.createBarrier(nr_CPU); 129 System.out.println("*** Creating cluster processes ***"); 130 for (int n = 0; n < nr_CPU; n++) { 131 nodes[n] = /** @at n */ new ModelCluster(jp.lang.Node.getNode(n), nr_CPU, n, fname, barrier); 132 } 133 for (int n = 0; n < nr_CPU; n++) nodes[n].setCluster_nodes(nodes); 134 Thread[] tsolve = new Thread[nr_CPU]; 135 for (int n = 0; n < tsolve.length; n++) { 136 tsolve[n] = new Thread(nodes[n]); 137 tsolve[n].setPriority(Thread.MIN_PRIORITY); 138 } 139 System.out.println("*** Starting the solution ***"); 140 for (int n = 0; n < tsolve.length; n++) { 141 tsolve[n].start(); 142 } 143 long stime = System.currentTimeMillis(); 144 for (int n = 0; n < tsolve.length; n++) { 145 try { 146 tsolve[n].join(); 147 } catch (InterruptedException e) { 148 e.printStackTrace(); 149 return; 150 } 151 } 152 System.out.println("Solving took " + (System.currentTimeMillis() - stime) + " ms"); 153 } 154 } 155