private static AbstractIterationStrategyNode nodeForElement(Element e) { AbstractIterationStrategyNode node = null; String eName = e.getName(); if (eName.equals("dot")) { node = new DotProduct(); } else if (eName.equals("cross")) { node = new CrossProduct(); } else if (eName.equals("prefix")) { node = new PrefixDotProduct(); } else if (eName.equals("port")) { String portName = e.getAttributeValue("name"); int portDepth = Integer.parseInt(e.getAttributeValue("depth")); node = new NamedInputPortNode(portName, portDepth); } for (Object child : e.getChildren()) { Element childElement = (Element) child; nodeForElement(childElement).setParent(node); } return node; }
public int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { // Check that all input depths are the same if (isLeaf()) { // No children! throw new IterationTypeMismatchException("Dot product with no children"); } int depth = getChildAt(0).getIterationDepth(inputDepths); for (IterationStrategyNode childNode : getChildren()) { if (childNode.getIterationDepth(inputDepths) != depth) { throw new IterationTypeMismatchException( "Mismatched input types for dot product node"); } } return depth; }
@Override public synchronized void innerReceiveJob(int inputIndex, Job newJob) { if (getChildCount() == 1) { pushJob(newJob); return; TreeCache[] caches = new TreeCache[getChildCount()]; for (int i = 0; i < getChildCount(); i++) { caches[i] = new TreeCache(); cache.cut(indexArray); pushJob(j);
public int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { // Check that all input depths are the same int depth = getChildAt(0).getIterationDepth(inputDepths); for (IterationStrategyNode childNode : getChildren()) { if (childNode.getIterationDepth(inputDepths) != depth) { throw new IterationTypeMismatchException( "Mismatched input types for dot product node"); } } return depth; }
private IterationStrategyImpl getISDot(int depthA, int depthB) { IterationStrategyImpl is1 = new IterationStrategyImpl(); NamedInputPortNode nipn1 = new NamedInputPortNode("a", depthA); NamedInputPortNode nipn2 = new NamedInputPortNode("b", depthB); is1.addInput(nipn1); is1.addInput(nipn2); DotProduct dp = new DotProduct(); nipn1.setParent(dp); nipn2.setParent(dp); dp.setParent(is1.getTerminal()); return is1; }
@Test public void cantAddSelf() throws Exception { dotProduct1.setParent(crossProduct1); try { dotProduct1.insert(dotProduct1); fail("Didn't throw IllegalArgumentException"); } catch (IllegalArgumentException ex) { // Make sure we didn't loose our old parent and // ended up in a funny state assertEquals(crossProduct1, dotProduct1.getParent()); assertEquals(dotProduct1, crossProduct1.getChildAt(0)); } }
@Test public void moveNodeToDifferentParent() { crossProduct1.setParent(root); crossProduct1.insert(input1); crossProduct1.insert(dotProduct1); dotProduct1.insert(input2); dotProduct1.insert(crossProduct2); // Check tree assertEquals(crossProduct2, root.getChildAt(0).getChildAt(1) .getChildAt(1)); assertEquals(Arrays.asList(input2, crossProduct2), dotProduct1 .getChildren()); crossProduct1.insert(crossProduct2, 1); assertEquals(Arrays.asList(input1, crossProduct2, dotProduct1), crossProduct1.getChildren()); assertEquals(crossProduct1, crossProduct2.getParent()); // Should no longer be in dotProduct1 assertEquals(Arrays.asList(input2), dotProduct1.getChildren()); }
@Test public void cantSetSelfParent() throws Exception { crossProduct1.insert(dotProduct1); try { dotProduct1.setParent(dotProduct1); fail("Didn't throw IllegalArgumentException"); } catch (IllegalArgumentException ex) { // Make sure we didn't loose our old parent and // ended up in a funny state assertEquals(crossProduct1, dotProduct1.getParent()); assertEquals(dotProduct1, crossProduct1.getChildAt(0)); } }
public int getIterationDepth(Map<String, Integer> inputDepths) throws IterationTypeMismatchException { // Check that all input depths are the same int depth = getChildren().get(0).getIterationDepth(inputDepths); for (IterationStrategyNode childNode : getChildren()) { if (childNode.getIterationDepth(inputDepths) != depth) { throw new IterationTypeMismatchException( "Mismatched input types for dot product node"); } } return depth; }
public void testMutipleData() throws MalformedIdentifierException { NamedInputPortNode nipn1 = new NamedInputPortNode("a", 0); NamedInputPortNode nipn2 = new NamedInputPortNode("b", 0); DotProduct dp = new DotProduct(); nipn1.setParent(dp); nipn2.setParent(dp); DiagnosticIterationStrategyNode disn = new DiagnosticIterationStrategyNode(); dp.setParent(disn); IterationStrategyImpl is = new IterationStrategyImpl(); is.addInput(nipn1); is.addInput(nipn2); String owningProcess = "Process1"; for (int i = 0; i < 4; i++) { EntityListIdentifier dataReference = new EntityListIdentifier("urn:t2data:list://foo.bar/alist"+i+"/1"); is.receiveData("a", owningProcess, new int[]{i}, dataReference, context); } is.receiveCompletion("a", owningProcess, new int[]{}, context); for (int i = 0; i < 4; i++) { EntityListIdentifier dataReference = new EntityListIdentifier("urn:t2data:list://foo.bar/blist"+i+"/1"); is.receiveData("b", owningProcess, new int[]{i}, dataReference, context); } is.receiveCompletion("b", owningProcess, new int[]{}, context); assertTrue(disn.jobsReceived("Process1")==4); System.out.println(disn); }
@Test public void cantAddSelf() throws Exception { dotProduct1.setParent(crossProduct1); try { dotProduct1.insert(dotProduct1); fail("Didn't throw IllegalArgumentException"); } catch (IllegalArgumentException ex) { // Make sure we didn't loose our old parent and // ended up in a funny state assertEquals(crossProduct1, dotProduct1.getParent()); assertEquals(dotProduct1, crossProduct1.getChildAt(0)); } }
@Test public void moveNodeToDifferentParent() { crossProduct1.setParent(root); crossProduct1.insert(input1); crossProduct1.insert(dotProduct1); dotProduct1.insert(input2); dotProduct1.insert(crossProduct2); // Check tree assertEquals(crossProduct2, root.getChildAt(0).getChildAt(1) .getChildAt(1)); assertEquals(Arrays.asList(input2, crossProduct2), dotProduct1 .getChildren()); crossProduct1.insert(crossProduct2, 1); assertEquals(Arrays.asList(input1, crossProduct2, dotProduct1), crossProduct1.getChildren()); assertEquals(crossProduct1, crossProduct2.getParent()); // Should no longer be in dotProduct1 assertEquals(Arrays.asList(input2), dotProduct1.getChildren()); }
@Test public void cantSetSelfParent() throws Exception { crossProduct1.insert(dotProduct1); try { dotProduct1.setParent(dotProduct1); fail("Didn't throw IllegalArgumentException"); } catch (IllegalArgumentException ex) { // Make sure we didn't loose our old parent and // ended up in a funny state assertEquals(crossProduct1, dotProduct1.getParent()); assertEquals(dotProduct1, crossProduct1.getChildAt(0)); } }
public void testBasic() { NamedInputPortNode nipn1 = new NamedInputPortNode("Input1", 0); NamedInputPortNode nipn2 = new NamedInputPortNode("Input2", 0); DotProduct dp = new DotProduct(); nipn1.setParent(dp); nipn2.setParent(dp); DiagnosticIterationStrategyNode disn = new DiagnosticIterationStrategyNode(); dp.setParent(disn); IterationStrategyImpl is = new IterationStrategyImpl(); is.addInput(nipn1); is.addInput(nipn2); try { is.receiveData("Input1", "Process1", new int[] {0}, nextID(), context); is.receiveCompletion("Input1", "Process1", new int[]{}, context); assertTrue(disn.jobsReceived("Process1") == 0); is.receiveData("Input2", "Process1", new int[] {0}, nextID(), context); is.receiveCompletion("Input2", "Process1", new int[]{}, context); assertTrue(disn.jobsReceived("Process1") == 1); System.out.println(disn); } catch (WorkflowStructureException e) { fail("Unknown structure exception"); } }
private AbstractIterationStrategyNode nodeForElement(Element e) { AbstractIterationStrategyNode node = null; String eName = e.getName(); if (eName.equals("dot")) { node = new DotProduct(); } else if (eName.equals("cross")) { node = new CrossProduct(); } else if (eName.equals("prefix")) { node = new PrefixDotProduct(); } else if (eName.equals("port")) { String portName = e.getAttributeValue("name"); int portDepth = Integer.parseInt(e.getAttributeValue("depth")); node = new NamedInputPortNode(portName, portDepth); addInput((NamedInputPortNode) node); } for (Object child : e.getChildren()) { Element childElement = (Element) child; nodeForElement(childElement).setParent(node); } return node; }
String owningProcess = newJob.getOwningProcess(); if (!ownerToCache.containsKey(owningProcess)) { TreeCache[] caches = new TreeCache[getChildCount()]; for (int i = 0; i < getChildCount(); i++) { caches[i] = new TreeCache(); cache.cut(indexArray); pushJob(j);
is1.addInput(nipn1); is1.addInput(nipn2); DotProduct dp = new DotProduct(); nipn1.setParent(dp); nipn2.setParent(dp); dp.setParent(is1.getTerminal());
private AbstractIterationStrategyNode nodeForElement(Element e) { AbstractIterationStrategyNode node = null; String eName = e.getName(); if (eName.equals("dot")) { node = new DotProduct(); } else if (eName.equals("cross")) { node = new CrossProduct(); } else if (eName.equals("prefix")) { node = new PrefixDotProduct(); } else if (eName.equals("port")) { String portName = e.getAttributeValue("name"); int portDepth = Integer.parseInt(e.getAttributeValue("depth")); node = new NamedInputPortNode(portName, portDepth); addInput((NamedInputPortNode) node); } for (Object child : e.getChildren()) { Element childElement = (Element) child; nodeForElement(childElement).setParent(node); } return node; }
String owningProcess = newJob.getOwningProcess(); if (!ownerToCache.containsKey(owningProcess)) { TreeCache[] caches = new TreeCache[getChildCount()]; for (int i = 0; i < getChildCount(); i++) { caches[i] = new TreeCache(); cache.cut(indexArray); pushJob(j);
public void testMultipleProcess() { NamedInputPortNode nipn1 = new NamedInputPortNode("Input1", 0); NamedInputPortNode nipn2 = new NamedInputPortNode("Input2", 0); DotProduct dp = new DotProduct(); nipn1.setParent(dp); nipn2.setParent(dp); DiagnosticIterationStrategyNode disn = new DiagnosticIterationStrategyNode(); dp.setParent(disn); IterationStrategyImpl is = new IterationStrategyImpl(); is.addInput(nipn1); is.addInput(nipn2); try { is.receiveData("Input1", "Process1", new int[] {}, nextID(), context); assertTrue(disn.jobsReceived("Process1") == 0); is.receiveCompletion("Input1", "Process1", new int[]{}, context); is.receiveData("Input2", "Process2", new int[] {}, nextID(), context); assertTrue(disn.jobsReceived("Process1") == 0); is.receiveData("Input2", "Process1", new int[] {}, nextID(), context); assertTrue(disn.jobsReceived("Process1") == 1); is.receiveCompletion("Input2", "Process1", new int[]{}, context); System.out.println(disn); } catch (WorkflowStructureException e) { fail("Unknown structure exception"); } }