[SYSTEMML-1987] Fix JMLC handling of disabled parfor (convert to for) This patch makes a minor improvement to the compilation of parfor loops. JMLC allows to disable parfor (for environments w/ concurrent execution of prepared scripts) - so far we simply forced a parallel degree of 1. This led to unnecessary problems, because the optimizer still tries to access the cluster status and configuration, which can cause unnecessary problems in non-hadoop environments. We now simply convert parfor to for during runtime program construction.
Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/e888cce8 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/e888cce8 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/e888cce8 Branch: refs/heads/master Commit: e888cce89c6fce0f3a2e055dfa5a13efbd103c17 Parents: 55c4c0b Author: Matthias Boehm <[email protected]> Authored: Sat Nov 4 22:38:20 2017 -0700 Committer: Matthias Boehm <[email protected]> Committed: Sun Nov 5 14:27:20 2017 -0800 ---------------------------------------------------------------------- .../org/apache/sysml/parser/DMLTranslator.java | 2 +- .../jmlc/JMLCParfor2ForCompileTest.java | 77 ++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/e888cce8/src/main/java/org/apache/sysml/parser/DMLTranslator.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/parser/DMLTranslator.java b/src/main/java/org/apache/sysml/parser/DMLTranslator.java index 0d466e2..5a7f60e 100644 --- a/src/main/java/org/apache/sysml/parser/DMLTranslator.java +++ b/src/main/java/org/apache/sysml/parser/DMLTranslator.java @@ -613,7 +613,7 @@ public class DMLTranslator ForProgramBlock rtpb = null; IterablePredicate iterPred = fsb.getIterPredicate(); - if( sb instanceof ParForStatementBlock ) { + if( sb instanceof ParForStatementBlock && ConfigurationManager.isParallelParFor() ) { sbName = "ParForStatementBlock"; rtpb = new ParForProgramBlock(prog, iterPred.getIterVar().getName(), iterPred.getParForParams(), ((ParForStatementBlock)sb).getResultVariables()); http://git-wip-us.apache.org/repos/asf/systemml/blob/e888cce8/src/test/java/org/apache/sysml/test/integration/functions/jmlc/JMLCParfor2ForCompileTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/jmlc/JMLCParfor2ForCompileTest.java b/src/test/java/org/apache/sysml/test/integration/functions/jmlc/JMLCParfor2ForCompileTest.java new file mode 100644 index 0000000..e806f0c --- /dev/null +++ b/src/test/java/org/apache/sysml/test/integration/functions/jmlc/JMLCParfor2ForCompileTest.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.sysml.test.integration.functions.jmlc; + +import java.io.IOException; + +import org.junit.Assert; +import org.junit.Test; +import org.apache.sysml.api.DMLScript; +import org.apache.sysml.api.jmlc.Connection; +import org.apache.sysml.api.jmlc.PreparedScript; +import org.apache.sysml.conf.CompilerConfig.ConfigType; +import org.apache.sysml.test.integration.AutomatedTestBase; +import org.apache.sysml.utils.Statistics; + +public class JMLCParfor2ForCompileTest extends AutomatedTestBase +{ + @Override + public void setUp() { + //do nothing + } + + @Test + public void testParfor2ParforCompile() throws IOException { + runJMLCParFor2ForTest(true); + } + + @Test + public void testParfor2ForCompile() throws IOException { + runJMLCParFor2ForTest(false); + } + + private void runJMLCParFor2ForTest(boolean par) + throws IOException + { + try { + Connection conn = !par ? new Connection() : + new Connection(ConfigType.PARALLEL_LOCAL_OR_REMOTE_PARFOR); + String script = + " X = rand(rows=10, cols=10);" + + "R = matrix(0, rows=10, cols=1)" + + "parfor(i in 1:nrow(X))" + + " R[i,] = sum(X[i,])" + + "print(sum(R))"; + DMLScript.STATISTICS = true; + Statistics.reset(); + + PreparedScript pscript = conn.prepareScript( + script, new String[]{}, new String[]{}, false); + pscript.executeScript(); + conn.close(); + } + catch(Exception ex) { + Assert.fail("JMLC parfor test failed: "+ex.getMessage()); + } + + //check for existing or non-existing parfor + Assert.assertTrue(Statistics.getParforOptCount()==(par?1:0)); + } +}
