[SYSTEMML-1325] Cleanup static variables in DMLScript

We use ThreadLocal DMLOptions and DMLConfig instead of static variables in 
DMLScript class. It allows different JMLC instances (or MLCContext instances) 
to run with different options (such as with GPU, with CPU, etc).

Closes #832.


Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/ae268a9e
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/ae268a9e
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/ae268a9e

Branch: refs/heads/master
Commit: ae268a9ee7ecca6abdc3846bab5e2a5a45996d6c
Parents: a169053
Author: Niketan Pansare <[email protected]>
Authored: Mon Aug 27 13:06:51 2018 -0700
Committer: Niketan Pansare <[email protected]>
Committed: Mon Aug 27 13:08:47 2018 -0700

----------------------------------------------------------------------
 .../java/org/apache/sysml/api/DMLOptions.java   | 263 --------------
 .../java/org/apache/sysml/api/DMLScript.java    |  88 +----
 .../apache/sysml/api/ScriptExecutorUtils.java   |   9 +-
 .../org/apache/sysml/api/jmlc/Connection.java   |  28 +-
 .../apache/sysml/api/jmlc/PreparedScript.java   |  22 ++
 .../apache/sysml/api/mlcontext/MLContext.java   |   6 +-
 .../sysml/api/mlcontext/ScriptExecutor.java     |  42 ++-
 .../apache/sysml/conf/ConfigurationManager.java | 126 ++++++-
 .../java/org/apache/sysml/conf/DMLOptions.java  | 355 +++++++++++++++++++
 .../java/org/apache/sysml/hops/AggBinaryOp.java |   8 +-
 .../java/org/apache/sysml/hops/AggUnaryOp.java  |   6 +-
 .../java/org/apache/sysml/hops/BinaryOp.java    |   3 +-
 src/main/java/org/apache/sysml/hops/DnnOp.java  |   8 +-
 .../java/org/apache/sysml/hops/FunctionOp.java  |   6 +-
 src/main/java/org/apache/sysml/hops/Hop.java    |  22 +-
 .../java/org/apache/sysml/hops/IndexingOp.java  |   4 +-
 .../org/apache/sysml/hops/OptimizerUtils.java   |  12 +-
 .../java/org/apache/sysml/hops/ReorgOp.java     |   4 +-
 .../java/org/apache/sysml/hops/TernaryOp.java   |   3 +-
 .../java/org/apache/sysml/hops/UnaryOp.java     |   4 +-
 .../sysml/hops/codegen/SpoofCompiler.java       |  12 +-
 .../codegen/opt/PlanSelectionFuseCostBased.java |   6 +-
 .../opt/PlanSelectionFuseCostBasedV2.java       |  10 +-
 .../hops/recompile/LiteralReplacement.java      |   4 +-
 .../sysml/hops/rewrite/HopRewriteUtils.java     |   3 +-
 .../sysml/hops/rewrite/ProgramRewriter.java     |   3 +-
 .../rewrite/RewriteBlockSizeAndReblock.java     |   5 +-
 .../hops/rewrite/RewriteGPUSpecificOps.java     |   6 +-
 .../RewriteMarkLoopVariablesUpdateInPlace.java  |   6 +-
 .../RewriteSplitDagDataDependentOperators.java  |   3 +-
 .../rewrite/RewriteSplitDagUnknownCSVRead.java  |   4 +-
 .../java/org/apache/sysml/lops/compile/Dag.java |   2 +-
 .../apache/sysml/lops/runtime/RunMRJobs.java    |   5 +-
 .../sysml/runtime/codegen/CodegenUtils.java     |   6 +-
 .../controlprogram/FunctionProgramBlock.java    |   5 +-
 .../controlprogram/LocalVariableMap.java        |   3 +-
 .../controlprogram/ParForProgramBlock.java      |  10 +-
 .../runtime/controlprogram/ProgramBlock.java    |  14 +-
 .../controlprogram/caching/CacheableData.java   |  30 +-
 .../controlprogram/caching/LazyWriteBuffer.java |  10 +-
 .../controlprogram/caching/MatrixObject.java    |   9 +-
 .../context/ExecutionContext.java               |   9 +-
 .../context/ExecutionContextFactory.java        |   4 +-
 .../context/SparkExecutionContext.java          |  42 +--
 .../controlprogram/paramserv/LocalPSWorker.java |  16 +-
 .../controlprogram/paramserv/ParamServer.java   |  10 +-
 .../paramserv/ParamservUtils.java               |   5 +-
 .../controlprogram/paramserv/SparkPSProxy.java  |   8 +-
 .../parfor/DataPartitionerRemoteMR.java         |   5 +-
 .../parfor/DataPartitionerRemoteSpark.java      |   6 +-
 .../controlprogram/parfor/LocalParWorker.java   |   3 +-
 .../controlprogram/parfor/RemoteDPParForMR.java |   7 +-
 .../parfor/RemoteDPParForSpark.java             |   6 +-
 .../parfor/RemoteDPParWorkerReducer.java        |   7 +-
 .../controlprogram/parfor/RemoteParForMR.java   |   7 +-
 .../parfor/RemoteParForSpark.java               |   6 +-
 .../parfor/RemoteParForUtils.java               |   3 +-
 .../parfor/RemoteParWorkerMapper.java           |   7 +-
 .../parfor/ResultMergeRemoteMR.java             |   5 +-
 .../parfor/ResultMergeRemoteSpark.java          |   6 +-
 .../parfor/opt/CostEstimatorHops.java           |   3 +-
 .../parfor/opt/OptimizationWrapper.java         |   5 +-
 .../parfor/opt/OptimizerRuleBased.java          |   3 +-
 .../sysml/runtime/instructions/Instruction.java |   4 +-
 .../runtime/instructions/MRJobInstruction.java  |   3 +-
 .../cp/AggregateUnaryCPInstruction.java         |   4 +-
 .../cp/ComputationCPInstruction.java            |   4 +-
 .../instructions/cp/DnnCPInstruction.java       |   4 +-
 .../cp/FunctionCallCPInstruction.java           |   3 +-
 .../cp/MatrixIndexingCPInstruction.java         |   4 +-
 .../cp/ParamservBuiltinCPInstruction.java       |  12 +-
 .../instructions/cp/VariableCPInstruction.java  |   3 +-
 .../instructions/gpu/DnnGPUInstruction.java     |   9 +-
 .../instructions/gpu/GPUInstruction.java        |  12 +-
 .../instructions/gpu/context/CSRPointer.java    |  14 +-
 .../gpu/context/CudaMemoryAllocator.java        |   7 +-
 .../instructions/gpu/context/GPUContext.java    |  28 +-
 .../context/GPULazyCudaFreeMemoryManager.java   |  12 +-
 .../gpu/context/GPUMemoryManager.java           |  46 +--
 .../instructions/gpu/context/GPUObject.java     |  69 ++--
 .../instructions/gpu/context/JCudaKernels.java  |   3 +-
 .../instructions/gpu/context/ShadowBuffer.java  |  34 +-
 .../gpu/context/UnifiedMemoryAllocator.java     |  11 +-
 .../instructions/spark/RandSPInstruction.java   |   5 +-
 .../DoublePrecisionCudaSupportFunctions.java    |  10 +-
 .../runtime/matrix/data/LibMatrixCUDA.java      | 175 ++++-----
 .../runtime/matrix/data/LibMatrixCuDNN.java     |  82 ++---
 .../LibMatrixCuDNNConvolutionAlgorithm.java     |  20 +-
 .../data/LibMatrixCuDNNInputRowFetcher.java     |   6 +-
 .../matrix/data/LibMatrixCuDNNRnnAlgorithm.java |   7 +-
 .../runtime/matrix/data/LibMatrixCuMatMult.java |  26 +-
 .../sysml/runtime/matrix/data/LibMatrixDNN.java |  12 +-
 .../runtime/matrix/data/LibMatrixDNNConv2d.java |  42 +--
 .../runtime/matrix/data/LibMatrixNative.java    |  17 +-
 .../SinglePrecisionCudaSupportFunctions.java    |  18 +-
 .../sysml/runtime/util/ProgramConverter.java    |   6 +-
 .../org/apache/sysml/utils/GPUStatistics.java   |   4 +-
 .../java/org/apache/sysml/utils/Statistics.java |  34 +-
 .../parfor/ParForCorrelationTest.java           |   6 +-
 .../functions/codegen/APICodegenTest.java       |  25 +-
 .../functions/frame/FrameConverterTest.java     |   5 +-
 .../jmlc/JMLCClonedPreparedScriptTest.java      |   8 +-
 .../jmlc/JMLCParfor2ForCompileTest.java         |  13 +-
 .../DataFrameMatrixConversionTest.java          |  12 +-
 .../DataFrameRowFrameConversionTest.java        |   6 +-
 .../DataFrameVectorFrameConversionTest.java     |   6 +-
 .../functions/mlcontext/FrameTest.java          |   7 +-
 .../functions/mlcontext/GNMFTest.java           |   6 +-
 .../paramserv/SparkDataPartitionerTest.java     |   3 +-
 .../mlcontext/MLContextMultipleScriptsTest.java |   8 +-
 .../mlcontext/MLContextScratchCleanupTest.java  |   8 +-
 .../sysml/test/unit/CLIOptionsParserTest.java   |   2 +-
 112 files changed, 1221 insertions(+), 992 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/api/DMLOptions.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/DMLOptions.java 
b/src/main/java/org/apache/sysml/api/DMLOptions.java
deleted file mode 100644
index 2cb147a..0000000
--- a/src/main/java/org/apache/sysml/api/DMLOptions.java
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * 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.api;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.cli.OptionGroup;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.PosixParser;
-import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
-import org.apache.sysml.api.mlcontext.ScriptType;
-import org.apache.sysml.hops.OptimizerUtils;
-import org.apache.sysml.utils.Explain;
-import org.apache.sysml.utils.Explain.ExplainType;
-
-/**
- * Set of DMLOptions that can be set through the command line
- * and {@link org.apache.sysml.api.mlcontext.MLContext}
- * The values have been initialized with the default values
- * Despite there being a DML and PyDML, this class is named DMLOptions
- * to keep it consistent with {@link DMLOptions} and {@link DMLOptions}
- */
-public class DMLOptions {
-       public final Options        options;
-       public Map<String, String>  argVals       = new HashMap<>();  // 
Arguments map containing either named arguments or arguments by position for a 
DML program
-       public String               configFile    = null;             // Path 
to config file if default config and default config is to be overriden
-       public boolean              clean         = false;            // 
Whether to clean up all SystemML working directories (FS, DFS)
-       public boolean              stats         = false;            // 
Whether to record and print the statistics
-       public int                  statsCount    = 10;               // 
Default statistics count
-       public boolean              memStats      = false;            // max 
memory statistics
-       public Explain.ExplainType  explainType   = Explain.ExplainType.NONE;  
// Whether to print the "Explain" and if so, what type
-       public RUNTIME_PLATFORM     execMode = 
OptimizerUtils.getDefaultExecutionMode();  // Execution mode standalone, MR, 
Spark or a hybrid
-       public boolean              gpu           = false;            // 
Whether to use the GPU
-       public boolean              forceGPU      = false;            // 
Whether to ignore memory & estimates and always use the GPU
-       public boolean              debug         = false;            // to go 
into debug mode to be able to step through a program
-       public ScriptType           scriptType    = ScriptType.DML;   // 
whether the script is a DML or PyDML script
-       public String               filePath      = null;             // path 
to script
-       public String               script        = null;             // the 
script itself
-       public boolean              help          = false;            // 
whether to print the usage option
-
-       public final static DMLOptions defaultOptions = new DMLOptions(null);
-
-       public DMLOptions(Options opts) {
-               options = opts;
-       }
-       
-       @Override
-       public String toString() {
-               return "DMLOptions{" +
-                       "argVals=" + argVals +
-                       ", configFile='" + configFile + '\'' +
-                       ", clean=" + clean +
-                       ", stats=" + stats +
-                       ", statsCount=" + statsCount +
-                       ", memStats=" + memStats +
-                       ", explainType=" + explainType +
-                       ", execMode=" + execMode +
-                       ", gpu=" + gpu +
-                       ", forceGPU=" + forceGPU +
-                       ", debug=" + debug +
-                       ", scriptType=" + scriptType +
-                       ", filePath='" + filePath + '\'' +
-                       ", script='" + script + '\'' +
-                       ", help=" + help +
-                       '}';
-       }
-       
-       /**
-        * Parses command line arguments to create a {@link DMLOptions} 
instance with the correct options
-        * @param args arguments from the command line
-        * @return an instance of {@link DMLOptions} that contain the correct 
{@link Option}s.
-        * @throws org.apache.commons.cli.ParseException if there is an 
incorrect option specified in the CLI
-        */
-       public static DMLOptions parseCLArguments(String[] args)
-               throws org.apache.commons.cli.ParseException
-       {
-               Options options = createCLIOptions();
-               CommandLineParser clParser = new PosixParser();
-               CommandLine line = clParser.parse(options, args);
-
-               DMLOptions dmlOptions = new DMLOptions(options);
-               dmlOptions.help = line.hasOption("help");
-               dmlOptions.scriptType = line.hasOption("python") ? 
ScriptType.PYDML : ScriptType.DML;
-               dmlOptions.debug = line.hasOption("debug");
-               dmlOptions.gpu = line.hasOption("gpu");
-               if (dmlOptions.gpu) {
-                       String force = line.getOptionValue("gpu");
-                       if (force != null) {
-                               if (force.equalsIgnoreCase("force")) {
-                                       dmlOptions.forceGPU = true;
-                               } else {
-                                       throw new 
org.apache.commons.cli.ParseException("Invalid argument specified for -gpu 
option");
-                               }
-                       }
-               }
-               if (line.hasOption("exec")){
-                       String execMode = line.getOptionValue("exec");
-                       if (execMode != null){
-                               if (execMode.equalsIgnoreCase("hadoop")) 
dmlOptions.execMode = RUNTIME_PLATFORM.HADOOP;
-                               else if 
(execMode.equalsIgnoreCase("singlenode")) dmlOptions.execMode = 
RUNTIME_PLATFORM.SINGLE_NODE;
-                               else if (execMode.equalsIgnoreCase("hybrid")) 
dmlOptions.execMode = RUNTIME_PLATFORM.HYBRID;
-                               else if 
(execMode.equalsIgnoreCase("hybrid_spark")) dmlOptions.execMode = 
RUNTIME_PLATFORM.HYBRID_SPARK;
-                               else if (execMode.equalsIgnoreCase("spark")) 
dmlOptions.execMode = RUNTIME_PLATFORM.SPARK;
-                               else throw new 
org.apache.commons.cli.ParseException("Invalid argument specified for -exec 
option, must be one of [hadoop, singlenode, hybrid, hybrid_spark, spark]");
-                       }
-               }
-               if (line.hasOption("explain")) {
-                       dmlOptions.explainType = ExplainType.RUNTIME;
-                       String explainType = line.getOptionValue("explain");
-                       if (explainType != null){
-                               if (explainType.equalsIgnoreCase("hops")) 
dmlOptions.explainType = ExplainType.HOPS;
-                               else if 
(explainType.equalsIgnoreCase("runtime")) dmlOptions.explainType = 
ExplainType.RUNTIME;
-                               else if 
(explainType.equalsIgnoreCase("recompile_hops")) dmlOptions.explainType = 
ExplainType.RECOMPILE_HOPS;
-                               else if 
(explainType.equalsIgnoreCase("recompile_runtime")) dmlOptions.explainType = 
ExplainType.RECOMPILE_RUNTIME;
-                               else throw new 
org.apache.commons.cli.ParseException("Invalid argument specified for -hops 
option, must be one of [hops, runtime, recompile_hops, recompile_runtime]");
-                       }
-               }
-               dmlOptions.stats = line.hasOption("stats");
-               if (dmlOptions.stats){
-                       String statsCount = line.getOptionValue("stats");
-                       if (statsCount != null) {
-                               try {
-                                       dmlOptions.statsCount = 
Integer.parseInt(statsCount);
-                               } catch (NumberFormatException e) {
-                                       throw new 
org.apache.commons.cli.ParseException("Invalid argument specified for -stats 
option, must be a valid integer");
-                               }
-                       }
-               }
-               dmlOptions.memStats = line.hasOption("mem");
-
-               dmlOptions.clean = line.hasOption("clean");
-
-               if (line.hasOption("config")){
-                       dmlOptions.configFile = line.getOptionValue("config");
-               }
-
-               if (line.hasOption("f")){
-                       dmlOptions.filePath = line.getOptionValue("f");
-               }
-
-               if (line.hasOption("s")){
-                       dmlOptions.script = line.getOptionValue("s");
-               }
-
-               // Positional arguments map is created as ("$1", "a"), ("$2", 
123), etc
-               if (line.hasOption("args")){
-                       String[] argValues = line.getOptionValues("args");
-                       for (int k=0; k<argValues.length; k++){
-                               String str = argValues[k];
-                               if (!str.isEmpty()) {
-                                       dmlOptions.argVals.put("$" + (k+1), 
str);
-                               }
-                       }
-               }
-
-               // Named arguments map is created as ("$K, 123), ("$X", 
"X.csv"), etc
-               if (line.hasOption("nvargs")){
-                       String varNameRegex = "^[a-zA-Z]([a-zA-Z0-9_])*$";
-                       String[] nvargValues = line.getOptionValues("nvargs");
-                       for (String str : nvargValues){
-                               if (!str.isEmpty()){
-                                       String[] kv = str.split("=");
-                                       if (kv.length != 2){
-                                               throw new 
org.apache.commons.cli.ParseException("Invalid argument specified for -nvargs 
option, must be a list of space separated K=V pairs, where K is a valid name of 
a variable in the DML/PyDML program");
-                                       }
-                                       if (!kv[0].matches(varNameRegex)) {
-                                               throw new 
org.apache.commons.cli.ParseException("Invalid argument specified for -nvargs 
option, " + kv[0] + " does not seem like a valid variable name in DML. Valid 
variable names in DML start with upper-case or lower-case letter, and contain 
only letters, digits, or underscores");
-                                       }
-                                       dmlOptions.argVals.put("$" + kv[0], 
kv[1]);
-                               }
-                       }
-               }
-
-               return dmlOptions;
-       }
-       
-       @SuppressWarnings("static-access")
-       private static Options createCLIOptions() {
-               Options options = new Options();
-               Option nvargsOpt = OptionBuilder.withArgName("key=value")
-                       .withDescription("parameterizes DML script with named 
parameters of the form <key=value>; <key> should be a valid identifier in 
DML/PyDML")
-                       .hasArgs().create("nvargs");
-               Option argsOpt = OptionBuilder.withArgName("argN")
-                       .withDescription("specifies positional parameters; 
first value will replace $1 in DML program; $2 will replace 2nd and so on")
-                       .hasArgs().create("args");
-               Option configOpt = OptionBuilder.withArgName("filename")
-                       .withDescription("uses a given configuration file (can 
be on local/hdfs/gpfs; default values in SystemML-config.xml")
-                       .hasArg().create("config");
-               Option cleanOpt = OptionBuilder.withDescription("cleans up all 
SystemML working directories (FS, DFS); all other flags are ignored in this 
mode. \n")
-                       .create("clean");
-               Option statsOpt = OptionBuilder.withArgName("count")
-                       .withDescription("monitors and reports summary 
execution statistics; heavy hitter <count> is 10 unless overridden; default 
off")
-                       .hasOptionalArg().create("stats");
-               Option memOpt = OptionBuilder.withDescription("monitors and 
reports max memory consumption in CP; default off")
-                       .create("mem");
-               Option explainOpt = OptionBuilder.withArgName("level")
-                       .withDescription("explains plan levels; can be 'hops' / 
'runtime'[default] / 'recompile_hops' / 'recompile_runtime'")
-                       .hasOptionalArg().create("explain");
-               Option execOpt = OptionBuilder.withArgName("mode")
-                       .withDescription("sets execution mode; can be 'hadoop' 
/ 'singlenode' / 'hybrid'[default] / 'hybrid_spark' / 'spark'")
-                       .hasArg().create("exec");
-               Option gpuOpt = OptionBuilder.withArgName("force")
-                       .withDescription("uses CUDA instructions when 
reasonable; set <force> option to skip conservative memory estimates and use 
GPU wherever possible; default off")
-                       .hasOptionalArg().create("gpu");
-               Option debugOpt = OptionBuilder.withDescription("runs in debug 
mode; default off")
-                       .create("debug");
-               Option pythonOpt = OptionBuilder.withDescription("parses 
Python-like DML")
-                       .create("python");
-               Option fileOpt = OptionBuilder.withArgName("filename")
-                       .withDescription("specifies dml/pydml file to execute; 
path can be local/hdfs/gpfs (prefixed with appropriate URI)")
-                       .isRequired().hasArg().create("f");
-               Option scriptOpt = OptionBuilder.withArgName("script_contents")
-                       .withDescription("specified script string to execute 
directly")
-                       .isRequired().hasArg().create("s");
-               Option helpOpt = OptionBuilder.withDescription("shows usage 
message")
-                       .create("help");
-               
-               options.addOption(configOpt);
-               options.addOption(cleanOpt);
-               options.addOption(statsOpt);
-               options.addOption(memOpt);
-               options.addOption(explainOpt);
-               options.addOption(execOpt);
-               options.addOption(gpuOpt);
-               options.addOption(debugOpt);
-               options.addOption(pythonOpt);
-               
-               // Either a clean(-clean), a file(-f), a script(-s) or 
help(-help) needs to be specified
-               OptionGroup fileOrScriptOpt = new OptionGroup()
-                       
.addOption(scriptOpt).addOption(fileOpt).addOption(cleanOpt).addOption(helpOpt);
-               fileOrScriptOpt.setRequired(true);
-               options.addOptionGroup(fileOrScriptOpt);
-               
-               // Either -args or -nvargs
-               options.addOptionGroup(new OptionGroup()
-                       .addOption(nvargsOpt).addOption(argsOpt));
-               options.addOption(helpOpt);
-               
-               return options;
-       }
-}

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/api/DMLScript.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/DMLScript.java 
b/src/main/java/org/apache/sysml/api/DMLScript.java
index 9a6bb9b..9976adc 100644
--- a/src/main/java/org/apache/sysml/api/DMLScript.java
+++ b/src/main/java/org/apache/sysml/api/DMLScript.java
@@ -52,6 +52,7 @@ import org.apache.sysml.api.mlcontext.ScriptType;
 import org.apache.sysml.conf.CompilerConfig;
 import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.conf.DMLConfig;
+import org.apache.sysml.conf.DMLOptions;
 import org.apache.sysml.debug.DMLDebugger;
 import org.apache.sysml.debug.DMLDebuggerProgramInfo;
 import org.apache.sysml.hops.OptimizerUtils;
@@ -111,22 +112,18 @@ public class DMLScript
                // LOOP_AWARE           // different policies for operations in 
for/while/parfor loop vs out-side the loop
        }
        
-       public static RUNTIME_PLATFORM  rtplatform          = 
DMLOptions.defaultOptions.execMode;    // the execution mode
-       public static boolean           STATISTICS          = 
DMLOptions.defaultOptions.stats;       // whether to print statistics
-       public static boolean           FINEGRAINED_STATISTICS  = false;        
                     // whether to print fine-grained statistics
+       // TODO: Anthony
        public static boolean           JMLC_MEM_STATISTICS = false;            
                     // whether to gather memory use stats in JMLC
-       public static int               STATISTICS_COUNT    = 
DMLOptions.defaultOptions.statsCount;  // statistics maximum heavy hitter count
-       public static int               STATISTICS_MAX_WRAP_LEN = 30;           
                     // statistics maximum wrap length
+       
+       // debug mode is deprecated and will be removed soon.
        public static boolean           ENABLE_DEBUG_MODE   = 
DMLOptions.defaultOptions.debug;       // debug mode
+       
+       // These flags are not used by JMLC and hence are not cleaned up. We 
can revisit this later.
        public static ExplainType       EXPLAIN             = 
DMLOptions.defaultOptions.explainType; // explain type
        public static String            DML_FILE_PATH_ANTLR_PARSER = 
DMLOptions.defaultOptions.filePath; // filename of dml/pydml script
-       public static String            FLOATING_POINT_PRECISION = "double";    
                     // data type to use internally
-       public static EvictionPolicy    GPU_EVICTION_POLICY = 
EvictionPolicy.MIN_EVICT;                 // currently employed GPU eviction 
policy
-       public static boolean           PRINT_GPU_MEMORY_INFO = false;          
                     // whether to print GPU memory-related information
-       public static long              EVICTION_SHADOW_BUFFER_MAX_BYTES = 0;   
                      // maximum number of bytes to use for shadow buffer
-       public static long              EVICTION_SHADOW_BUFFER_CURR_BYTES = 0;  
                      // number of bytes to use for shadow buffer
-       public static double                    GPU_MEMORY_UTILIZATION_FACTOR = 
0.9;                                              // fraction of available GPU 
memory to use
-       public static String                    GPU_MEMORY_ALLOCATOR = "cuda";  
                                                          // GPU memory 
allocator to use
+       
+       // TODO: For now, assume that multiple threads won't attempt to use 
different floating point precision.
+       public static String            FLOATING_POINT_PRECISION = "double";    
                     // data type to use internally. 
        
        /**
         * Global variable indicating the script type (DML or PYDML). Can be 
used
@@ -135,14 +132,6 @@ public class DMLScript
         */
        public static ScriptType        SCRIPT_TYPE         = 
DMLOptions.defaultOptions.scriptType;
        
-       public static boolean           USE_ACCELERATOR     = 
DMLOptions.defaultOptions.gpu;
-       public static boolean           FORCE_ACCELERATOR   = 
DMLOptions.defaultOptions.forceGPU;
-       // whether to synchronize GPU after every instruction
-       public static boolean           SYNCHRONIZE_GPU         = true;
-       // whether to perform eager CUDA free on rmvar
-       public static boolean           EAGER_CUDA_FREE         = false;
-
-
        public static boolean _suppressPrint2Stdout = false;  // flag that 
indicates whether or not to suppress any prints to stdout
        public static boolean USE_LOCAL_SPARK_CONFIG = false; //set default 
local spark configuration - used for local testing
        public static boolean _activeAM = false;
@@ -217,7 +206,7 @@ public class DMLScript
        @SuppressWarnings("null")
        public static boolean executeScript( Configuration conf, String[] args 
) {
                //parse arguments and set execution properties
-               RUNTIME_PLATFORM oldrtplatform  = rtplatform;  //keep old 
rtplatform
+               RUNTIME_PLATFORM oldExecMode  = 
ConfigurationManager.getExecutionMode();  //keep old 
ConfigurationManager.getExecutionMode()
                ExplainType oldexplain          = EXPLAIN;     //keep old 
explain
 
                DMLOptions dmlOptions = null;
@@ -225,16 +214,12 @@ public class DMLScript
                try
                {
                        dmlOptions = DMLOptions.parseCLArguments(args);
+                       ConfigurationManager.setGlobalOptions(dmlOptions);
                        
-                       STATISTICS          = dmlOptions.stats;
-                       STATISTICS_COUNT    = dmlOptions.statsCount;
                        JMLC_MEM_STATISTICS = dmlOptions.memStats;
-                       USE_ACCELERATOR     = dmlOptions.gpu;
-                       FORCE_ACCELERATOR   = dmlOptions.forceGPU;
                        EXPLAIN             = dmlOptions.explainType;
                        ENABLE_DEBUG_MODE   = dmlOptions.debug;
                        SCRIPT_TYPE         = dmlOptions.scriptType;
-                       rtplatform          = dmlOptions.execMode;
 
                        String fnameOptConfig = dmlOptions.configFile;
                        boolean isFile = dmlOptions.filePath != null;
@@ -297,7 +282,7 @@ public class DMLScript
                }
                finally {
                        //reset runtime platform and visualize flag
-                       rtplatform = oldrtplatform;
+                       
ConfigurationManager.getDMLOptions().setExecutionMode(oldExecMode);
                        EXPLAIN = oldexplain;
                }
                
@@ -414,7 +399,7 @@ public class DMLScript
                
                //Step 1: parse configuration files & write any configuration 
specific global variables
                DMLConfig dmlconf = 
DMLConfig.readConfigurationFile(fnameOptConfig);
-               ConfigurationManager.setGlobalConfig(dmlconf);          
+               ConfigurationManager.setGlobalConfig(dmlconf);
                CompilerConfig cconf = 
OptimizerUtils.constructCompilerConfig(dmlconf);
                ConfigurationManager.setGlobalConfig(cconf);
                LOG.debug("\nDML config: \n" + dmlconf.getConfigInfo());
@@ -481,7 +466,7 @@ public class DMLScript
                ExecutionContext ec = null;
                try {
                        ec = ExecutionContextFactory.createContext(rtprog);
-                       ScriptExecutorUtils.executeRuntimeProgram(rtprog, ec, 
dmlconf, STATISTICS ? STATISTICS_COUNT : 0, null);
+                       ScriptExecutorUtils.executeRuntimeProgram(rtprog, ec, 
dmlconf, ConfigurationManager.isStatistics() ? 
ConfigurationManager.getDMLOptions().getStatisticsMaxHeavyHitters() : 0, null);
                }
                finally {
                        if(ec != null && ec instanceof SparkExecutionContext)
@@ -501,51 +486,14 @@ public class DMLScript
                // Sets the GPUs to use for this process (a range, all GPUs, 
comma separated list or a specific GPU)
                GPUContextPool.AVAILABLE_GPUS = 
dmlconf.getTextValue(DMLConfig.AVAILABLE_GPUS);
                
-               String evictionPolicy = 
dmlconf.getTextValue(DMLConfig.GPU_EVICTION_POLICY).toUpperCase();
-               try {
-                       DMLScript.GPU_EVICTION_POLICY = 
EvictionPolicy.valueOf(evictionPolicy);
-               } catch(IllegalArgumentException e) {
-                       throw new RuntimeException("Unsupported eviction 
policy:" + evictionPolicy);
-               }
-               
-               // Whether extra statistics useful for developers and others 
interested
-               // in digging into performance problems are recorded and 
displayed
-               DMLScript.FINEGRAINED_STATISTICS = DMLScript.STATISTICS && 
dmlconf.getBooleanValue(DMLConfig.EXTRA_FINEGRAINED_STATS);
                CacheableData.CACHING_BUFFER_SIZE = 
dmlconf.getDoubleValue(DMLConfig.CACHING_BUFFER_SIZE);
                if(CacheableData.CACHING_BUFFER_SIZE < 0 || 
CacheableData.CACHING_BUFFER_SIZE > 1) 
                        throw new RuntimeException("Incorrect value (" + 
CacheableData.CACHING_BUFFER_SIZE + ") for the configuration " + 
DMLConfig.CACHING_BUFFER_SIZE);
-               
-               DMLScript.STATISTICS_MAX_WRAP_LEN = 
dmlconf.getIntValue(DMLConfig.STATS_MAX_WRAP_LEN);          
+                               
                
NativeHelper.initialize(dmlconf.getTextValue(DMLConfig.NATIVE_BLAS_DIR), 
dmlconf.getTextValue(DMLConfig.NATIVE_BLAS).trim());
                
-               DMLScript.SYNCHRONIZE_GPU = 
dmlconf.getBooleanValue(DMLConfig.SYNCHRONIZE_GPU);
-               DMLScript.EAGER_CUDA_FREE = 
dmlconf.getBooleanValue(DMLConfig.EAGER_CUDA_FREE);
-               DMLScript.PRINT_GPU_MEMORY_INFO = 
dmlconf.getBooleanValue(DMLConfig.PRINT_GPU_MEMORY_INFO);
-               DMLScript.GPU_MEMORY_UTILIZATION_FACTOR = 
dmlconf.getDoubleValue(DMLConfig.GPU_MEMORY_UTILIZATION_FACTOR);
-               DMLScript.GPU_MEMORY_ALLOCATOR = 
dmlconf.getTextValue(DMLConfig.GPU_MEMORY_ALLOCATOR);
-               if(DMLScript.GPU_MEMORY_UTILIZATION_FACTOR < 0) {
-                       throw new RuntimeException("Incorrect value (" + 
DMLScript.GPU_MEMORY_UTILIZATION_FACTOR + ") for the configuration:" + 
DMLConfig.GPU_MEMORY_UTILIZATION_FACTOR);
-               }
-               
                DMLScript.FLOATING_POINT_PRECISION = 
dmlconf.getTextValue(DMLConfig.FLOATING_POINT_PRECISION);
                
org.apache.sysml.runtime.matrix.data.LibMatrixCUDA.resetFloatingPointPrecision();
-               if(DMLScript.FLOATING_POINT_PRECISION.equals("double")) {
-                       DMLScript.EVICTION_SHADOW_BUFFER_MAX_BYTES = 0;
-               }
-               else {
-                       double shadowBufferSize = 
dmlconf.getDoubleValue(DMLConfig.EVICTION_SHADOW_BUFFERSIZE);
-                       if(shadowBufferSize < 0 || shadowBufferSize > 1) 
-                               throw new RuntimeException("Incorrect value (" 
+ shadowBufferSize + ") for the configuration:" + 
DMLConfig.EVICTION_SHADOW_BUFFERSIZE);
-                       DMLScript.EVICTION_SHADOW_BUFFER_MAX_BYTES = (long) 
(((double)InfrastructureAnalyzer.getLocalMaxMemory())*shadowBufferSize);
-                       if(DMLScript.EVICTION_SHADOW_BUFFER_MAX_BYTES > 0 && 
-                                       
DMLScript.EVICTION_SHADOW_BUFFER_CURR_BYTES > 
DMLScript.EVICTION_SHADOW_BUFFER_MAX_BYTES) {
-                               // This will be printed in a very rare 
situation when:
-                               // 1. There is a memory leak which leads to 
non-cleared shadow buffer OR
-                               // 2. MLContext is registering to bunch of 
outputs that are all part of shadow buffer
-                               System.out.println("WARN: Cannot use the shadow 
buffer due to potentially cached GPU objects. Current shadow buffer size (in 
bytes):" 
-                                       + 
DMLScript.EVICTION_SHADOW_BUFFER_CURR_BYTES + " > Max shadow buffer size (in 
bytes):" + DMLScript.EVICTION_SHADOW_BUFFER_MAX_BYTES);
-                       }
-               }
        }
        
        /**
@@ -621,7 +569,7 @@ public class DMLScript
                
                //reset statistics (required if multiple scripts executed in 
one JVM)
                Statistics.resetNoOfExecutedJobs();
-               if( STATISTICS )
+               if( ConfigurationManager.isStatistics() )
                        Statistics.reset();
        }
        
@@ -712,7 +660,7 @@ public class DMLScript
 
        private static void printInvocationInfo(String fnameScript, String 
fnameOptConfig, Map<String,String> argVals) {
                LOG.debug("****** args to DML Script ******\n" + "UUID: " + 
getUUID() + "\n" + "SCRIPT PATH: " + fnameScript + "\n" 
-                       + "RUNTIME: " + rtplatform + "\n" + "BUILTIN CONFIG: " 
+ DMLConfig.DEFAULT_SYSTEMML_CONFIG_FILEPATH + "\n"
+                       + "RUNTIME: " + ConfigurationManager.getExecutionMode() 
+ "\n" + "BUILTIN CONFIG: " + DMLConfig.DEFAULT_SYSTEMML_CONFIG_FILEPATH + "\n"
                        + "OPTIONAL CONFIG: " + fnameOptConfig + "\n");
                if( !argVals.isEmpty() ) {
                        LOG.debug("Script arguments are: \n");
@@ -724,7 +672,7 @@ public class DMLScript
        private static void printStartExecInfo(String dmlScriptString) {
                LOG.info("BEGIN DML run " + getDateTime());
                LOG.debug("DML script: \n" + dmlScriptString);
-               if (rtplatform == RUNTIME_PLATFORM.HADOOP || rtplatform == 
RUNTIME_PLATFORM.HYBRID) {
+               if (ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.HADOOP || ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.HYBRID) {
                        String hadoop_home = System.getenv("HADOOP_HOME");
                        LOG.info("HADOOP_HOME: " + hadoop_home);
                }

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/api/ScriptExecutorUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/ScriptExecutorUtils.java 
b/src/main/java/org/apache/sysml/api/ScriptExecutorUtils.java
index 4af6949..e32fa29 100644
--- a/src/main/java/org/apache/sysml/api/ScriptExecutorUtils.java
+++ b/src/main/java/org/apache/sysml/api/ScriptExecutorUtils.java
@@ -73,11 +73,11 @@ public class ScriptExecutorUtils {
         */
        public static void executeRuntimeProgram(Program rtprog, 
ExecutionContext ec, DMLConfig dmlconf, int statisticsMaxHeavyHitters, 
Set<String> outputVariables) {
                boolean exceptionThrown = false;
-
+               
                Statistics.startRunTimer();
                try {
                        // run execute (w/ exception handling to ensure proper 
shutdown)
-                       if (DMLScript.USE_ACCELERATOR && ec != null) {
+                       if (ConfigurationManager.isGPU() && ec != null) {
                                List<GPUContext> gCtxs = 
GPUContextPool.reserveAllGPUContexts();
                                if (gCtxs == null) {
                                        throw new DMLRuntimeException(
@@ -91,7 +91,7 @@ public class ScriptExecutorUtils {
                        exceptionThrown = true;
                        throw e;
                } finally { // ensure cleanup/shutdown
-                       if (DMLScript.USE_ACCELERATOR && 
!ec.getGPUContexts().isEmpty()) {
+                       if (ConfigurationManager.isGPU() && 
!ec.getGPUContexts().isEmpty()) {
                                // 
-----------------------------------------------------------------
                                // The below code pulls the output variables on 
the GPU to the host. This is required especially when:
                                // The output variable was generated as part of 
a MLContext session with GPU enabled
@@ -123,7 +123,8 @@ public class ScriptExecutorUtils {
                        Statistics.stopRunTimer();
                        (exceptionThrown ? System.err : System.out)
                                
.println(Statistics.display(statisticsMaxHeavyHitters > 0 ?
-                                       statisticsMaxHeavyHitters : 
DMLScript.STATISTICS_COUNT));
+                                       statisticsMaxHeavyHitters : 
ConfigurationManager.getDMLOptions().getStatisticsMaxHeavyHitters()));
+                       ConfigurationManager.resetStatistics();
                }
        }
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/api/jmlc/Connection.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/jmlc/Connection.java 
b/src/main/java/org/apache/sysml/api/jmlc/Connection.java
index ea521e5..ea0d503 100644
--- a/src/main/java/org/apache/sysml/api/jmlc/Connection.java
+++ b/src/main/java/org/apache/sysml/api/jmlc/Connection.java
@@ -39,6 +39,7 @@ import org.apache.sysml.conf.CompilerConfig;
 import org.apache.sysml.conf.CompilerConfig.ConfigType;
 import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.conf.DMLConfig;
+import org.apache.sysml.conf.DMLOptions;
 import org.apache.sysml.hops.codegen.SpoofCompiler;
 import org.apache.sysml.hops.rewrite.ProgramRewriter;
 import org.apache.sysml.hops.rewrite.RewriteRemovePersistentReadWrite;
@@ -64,6 +65,7 @@ import org.apache.sysml.runtime.transform.TfUtils;
 import org.apache.sysml.runtime.transform.meta.TfMetaUtils;
 import org.apache.sysml.runtime.util.DataConverter;
 import org.apache.sysml.runtime.util.UtilFunctions;
+import org.apache.sysml.utils.Explain;
 import org.apache.wink.json4j.JSONObject;
 
 /**
@@ -149,8 +151,6 @@ public class Connection implements Closeable
         * @param dmlconfig a dml configuration.
         */
        public Connection(DMLConfig dmlconfig) {
-               DMLScript.rtplatform = RUNTIME_PLATFORM.SINGLE_NODE;
-               
                //setup basic parameters for embedded execution
                //(parser, compiler, and runtime parameters)
                CompilerConfig cconf = new CompilerConfig();
@@ -178,24 +178,6 @@ public class Connection implements Closeable
                
                setLocalConfigs();
        }
-
-       /**
-        * Sets a boolean flag indicating if runtime statistics should be 
gathered
-        * Same behavior as in "MLContext.setStatistics()"
-        *
-        * @param stats boolean value with true indicating statistics should be 
gathered
-        */
-       public void setStatistics(boolean stats) { DMLScript.STATISTICS = 
stats; }
-
-       /**
-        * Sets a boolean flag indicating if memory profiling statistics should 
be
-        * gathered. The option is false by default.
-        * @param stats boolean value with true indicating memory statistics 
should be gathered
-        */
-       public void gatherMemStats(boolean stats) {
-               DMLScript.STATISTICS = stats || DMLScript.STATISTICS;
-               DMLScript.JMLC_MEM_STATISTICS = stats;
-       }
        
        /**
         * Prepares (precompiles) a script and registers input and output 
variables.
@@ -249,6 +231,12 @@ public class Connection implements Closeable
         */
        public PreparedScript prepareScript(String script, Map<String,String> 
nsscripts, Map<String, String> args, String[] inputs, String[] outputs, boolean 
parsePyDML) {
                DMLScript.SCRIPT_TYPE = parsePyDML ? ScriptType.PYDML : 
ScriptType.DML;
+
+               // Set DML Options here:
+               boolean gpu = false; boolean forceGPU = false;
+               ConfigurationManager.setLocalOptions(new DMLOptions(args, 
+                               false, 10, false, Explain.ExplainType.NONE, 
RUNTIME_PLATFORM.SINGLE_NODE, gpu, forceGPU, 
+                               parsePyDML ? ScriptType.PYDML : ScriptType.DML, 
null, script));
                
                //check for valid names of passed arguments
                String[] invalidArgs = args.keySet().stream()

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/api/jmlc/PreparedScript.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/jmlc/PreparedScript.java 
b/src/main/java/org/apache/sysml/api/jmlc/PreparedScript.java
index 3fd3c67..d5955f4 100644
--- a/src/main/java/org/apache/sysml/api/jmlc/PreparedScript.java
+++ b/src/main/java/org/apache/sysml/api/jmlc/PreparedScript.java
@@ -30,6 +30,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.sysml.api.ConfigurableAPI;
 import org.apache.sysml.api.DMLException;
+import org.apache.sysml.api.DMLScript;
 import org.apache.sysml.conf.CompilerConfig;
 import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.conf.DMLConfig;
@@ -79,6 +80,7 @@ public class PreparedScript implements ConfigurableAPI
        private final LocalVariableMap _vars;
        private final DMLConfig _dmlconf;
        private final CompilerConfig _cconf;
+       private boolean _isStatisticsEnabled = false;
        
        private PreparedScript(PreparedScript that) {
                //shallow copy, except for a separate symbol table
@@ -124,6 +126,24 @@ public class PreparedScript implements ConfigurableAPI
                _cconf = cconf;
        }
        
+       /**
+        * Sets a boolean flag indicating if runtime statistics should be 
gathered
+        * Same behavior as in "MLContext.setStatistics()"
+        *
+        * @param stats boolean value with true indicating statistics should be 
gathered
+        */
+       public void setStatistics(boolean stats) { this._isStatisticsEnabled = 
stats; }
+
+       /**
+        * Sets a boolean flag indicating if memory profiling statistics should 
be
+        * gathered. The option is false by default.
+        * @param stats boolean value with true indicating memory statistics 
should be gathered
+        */
+       public void gatherMemStats(boolean stats) {
+               this._isStatisticsEnabled = this._isStatisticsEnabled || 
ConfigurationManager.isStatistics();
+               DMLScript.JMLC_MEM_STATISTICS = stats;
+       }
+       
        @Override
        public void resetConfig() {
                _dmlconf.set(new DMLConfig());
@@ -447,6 +467,8 @@ public class PreparedScript implements ConfigurableAPI
                
                //clear thread-local configurations
                ConfigurationManager.clearLocalConfigs();
+               
+               ConfigurationManager.resetStatistics();
 
                return rvars;
        }

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java 
b/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java
index 3690354..dee4060 100644
--- a/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java
+++ b/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java
@@ -270,7 +270,7 @@ public class MLContext implements ConfigurableAPI
                }
 
                this.spark = spark;
-               DMLScript.rtplatform = executionType.getRuntimePlatform();
+               
ConfigurationManager.getDMLOptions().setExecutionMode(executionType.getRuntimePlatform());
 
                activeMLContext = this;
                MLContextProxy.setActive(true);
@@ -608,7 +608,6 @@ public class MLContext implements ConfigurableAPI
         *            otherwise
         */
        public void setStatistics(boolean statistics) {
-               DMLScript.STATISTICS = statistics;
                this.statistics = statistics;
        }
 
@@ -620,7 +619,6 @@ public class MLContext implements ConfigurableAPI
         *            maximum number of heavy hitters to print
         */
        public void setStatisticsMaxHeavyHitters(int maxHeavyHitters) {
-               DMLScript.STATISTICS_COUNT = maxHeavyHitters;
                this.statisticsMaxHeavyHitters = maxHeavyHitters;
        }
 
@@ -740,7 +738,7 @@ public class MLContext implements ConfigurableAPI
         *            the execution environment
         */
        public void setExecutionType(ExecutionType executionType) {
-               DMLScript.rtplatform = executionType.getRuntimePlatform();
+               
ConfigurationManager.getDMLOptions().setExecutionMode(executionType.getRuntimePlatform());
                this.executionType = executionType;
        }
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java 
b/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java
index cce7c49..135e1cd 100644
--- a/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java
+++ b/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java
@@ -26,7 +26,7 @@ import java.util.Set;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.sysml.api.DMLScript;
-import org.apache.sysml.api.DMLOptions;
+import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
 import org.apache.sysml.api.ScriptExecutorUtils;
 import org.apache.sysml.api.jmlc.JMLCUtils;
 import org.apache.sysml.api.mlcontext.MLContext.ExecutionType;
@@ -34,6 +34,7 @@ import org.apache.sysml.api.mlcontext.MLContext.ExplainLevel;
 import org.apache.sysml.conf.CompilerConfig;
 import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.conf.DMLConfig;
+import org.apache.sysml.conf.DMLOptions;
 import org.apache.sysml.hops.HopsException;
 import org.apache.sysml.hops.OptimizerUtils;
 import org.apache.sysml.hops.rewrite.ProgramRewriter;
@@ -108,7 +109,6 @@ public class ScriptExecutor {
        protected boolean forceGPU = false;
        protected boolean oldForceGPU = false;
        protected boolean statistics = false;
-       protected boolean oldStatistics = false;
        protected ExplainLevel explainLevel;
        protected ExecutionType executionType;
        protected int statisticsMaxHeavyHitters = 10;
@@ -225,13 +225,12 @@ public class ScriptExecutor {
         * Set the global flags (for example: statistics, gpu, etc).
         */
        protected void setGlobalFlags() {
-               oldStatistics = DMLScript.STATISTICS;
-               DMLScript.STATISTICS = statistics;
-               oldForceGPU = DMLScript.FORCE_ACCELERATOR;
-               DMLScript.FORCE_ACCELERATOR = forceGPU;
-               oldGPU = DMLScript.USE_ACCELERATOR;
-               DMLScript.USE_ACCELERATOR = gpu;
-               DMLScript.STATISTICS_COUNT = statisticsMaxHeavyHitters;
+               ConfigurationManager.setStatistics(statistics);
+               oldForceGPU = ConfigurationManager.isForcedGPU();
+               ConfigurationManager.getDMLOptions().setForceGPU(forceGPU);
+               oldGPU = ConfigurationManager.isGPU();
+               ConfigurationManager.getDMLOptions().setGPU(gpu);
+               
ConfigurationManager.getDMLOptions().setStatisticsMaxHeavyHitters(statisticsMaxHeavyHitters);
 
                // set the global compiler configuration
                try {
@@ -253,10 +252,9 @@ public class ScriptExecutor {
         * post-execution.
         */
        protected void resetGlobalFlags() {
-               DMLScript.STATISTICS = oldStatistics;
-               DMLScript.FORCE_ACCELERATOR = oldForceGPU;
-               DMLScript.USE_ACCELERATOR = oldGPU;
-               DMLScript.STATISTICS_COUNT = 
DMLOptions.defaultOptions.statsCount;
+               ConfigurationManager.getDMLOptions().setForceGPU(oldForceGPU);
+               ConfigurationManager.getDMLOptions().setGPU(oldGPU);
+               
ConfigurationManager.getDMLOptions().setStatisticsMaxHeavyHitters(DMLOptions.defaultOptions.statsCount);
        }
        
        public void compile(Script script) {
@@ -334,6 +332,22 @@ public class ScriptExecutor {
         */
        public MLResults execute(Script script) {
 
+               Map<String, String> args = MLContextUtil
+                               
.convertInputParametersForParser(script.getInputParameters(), 
script.getScriptType());
+               
+               Explain.ExplainType explainType = Explain.ExplainType.NONE;
+               if(explain && explainLevel != null) {
+                       explainType = explainLevel.getExplainType();
+               }
+               RUNTIME_PLATFORM rtplatform = 
DMLOptions.defaultOptions.execMode;
+               if(executionType != null) {
+                       rtplatform = getExecutionType().getRuntimePlatform();
+               }
+               ConfigurationManager.setGlobalOptions(new DMLOptions(args, 
+                               statistics, statisticsMaxHeavyHitters, false, 
explainType, 
+                               rtplatform, gpu, forceGPU, 
script.getScriptType(), DMLScript.DML_FILE_PATH_ANTLR_PARSER, 
+                               script.getScriptExecutionString()));
+               
                // main steps in script execution
                compile(script);
 
@@ -718,7 +732,7 @@ public class ScriptExecutor {
         *            the execution environment
         */
        public void setExecutionType(ExecutionType executionType) {
-               DMLScript.rtplatform = executionType.getRuntimePlatform();
+               
ConfigurationManager.getDMLOptions().setExecutionMode(executionType.getRuntimePlatform());
                this.executionType = executionType;
        }
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/conf/ConfigurationManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/conf/ConfigurationManager.java 
b/src/main/java/org/apache/sysml/conf/ConfigurationManager.java
index bbba53f..d9f1906 100644
--- a/src/main/java/org/apache/sysml/conf/ConfigurationManager.java
+++ b/src/main/java/org/apache/sysml/conf/ConfigurationManager.java
@@ -20,7 +20,7 @@
 package org.apache.sysml.conf;
 
 import org.apache.hadoop.mapred.JobConf;
-import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
 import org.apache.sysml.conf.CompilerConfig.ConfigType;
 import org.apache.sysml.runtime.matrix.mapred.MRConfigurationNames;
 import org.apache.sysml.runtime.matrix.mapred.MRJobConfiguration;
@@ -45,6 +45,12 @@ public class ConfigurationManager
        /** Local DML configuration for thread-local config updates */
        private static ThreadLocalDMLConfig _ldmlconf = new 
ThreadLocalDMLConfig();
        
+       /** Global DML options (read or defaults) */
+       private static DMLOptions _dmlOptions = DMLOptions.defaultOptions; 
+       
+       /** Local DML configuration for thread-local options */
+       private static ThreadLocalDMLOptions _ldmlOptions = new 
ThreadLocalDMLOptions();
+       
     /** Global compiler configuration (defaults) */
     private static CompilerConfig _cconf = null;
        
@@ -97,6 +103,24 @@ public class ConfigurationManager
                
                //reinitialize thread-local dml configs w/ _dmlconf
                _ldmlconf = new ThreadLocalDMLConfig();
+               
+               FINEGRAINED_STATISTICS = 
conf.getBooleanValue(DMLConfig.EXTRA_FINEGRAINED_STATS);
+       }
+       
+       /**
+        * Sets a global options as a basis for any thread-local configurations.
+        * NOTE: This global options should never be accessed directly but only
+        * through its thread-local derivatives. 
+        * 
+        * @param opts the dml options
+        */
+       public synchronized static void setGlobalOptions( DMLOptions opts ) {
+               _dmlOptions = opts;
+               
+               //reinitialize thread-local dml options w/ _dmlOptions
+               _ldmlOptions = new ThreadLocalDMLOptions();
+               
+               STATISTICS = opts.stats;
        }
        
        /**
@@ -106,6 +130,8 @@ public class ConfigurationManager
         */
        public static void setLocalConfig( DMLConfig conf ) {
                _ldmlconf.set(conf);
+               
+               FINEGRAINED_STATISTICS = 
conf.getBooleanValue(DMLConfig.EXTRA_FINEGRAINED_STATS);
        }
        
        /**
@@ -117,6 +143,27 @@ public class ConfigurationManager
                return _ldmlconf.get();
        }
        
+       /**
+        * Gets the current thread-local dml options.
+        * 
+        * @return the dml options
+        */
+       public static DMLOptions getDMLOptions() {
+               return _ldmlOptions.get();
+       }
+       
+       /**
+        * Sets the current thread-local dml configuration to the given options.
+        * 
+        * @param conf the configuration
+        */
+       public static void setLocalOptions( DMLOptions opts ) {
+               _dmlOptions = opts;
+               _ldmlOptions.set(opts);
+               STATISTICS = opts.stats;
+       }
+       
+       
        public synchronized static void setGlobalConfig( CompilerConfig conf ) {
                _cconf = conf;
                
@@ -140,6 +187,7 @@ public class ConfigurationManager
        public static void clearLocalConfigs() {
                _ldmlconf.remove();
                _lcconf.remove();
+               _ldmlOptions.remove();
        }
        
        /**
@@ -193,15 +241,89 @@ public class ConfigurationManager
        public static boolean isCodegenEnabled() {
                return (getDMLConfig().getBooleanValue(DMLConfig.CODEGEN)
                        || getCompilerConfigFlag(ConfigType.CODEGEN_ENABLED))
-                       && !DMLScript.USE_ACCELERATOR;
+                       && !ConfigurationManager.isGPU();
                //note: until codegen is supported for the GPU backend, we 
globally
                //disable codegen if operations are forced to the GPU to avoid
                //a counter-productive impact on performance.
        }
        
+       /**
+        * @return true if gpu is enabled
+        */
+       public static boolean isGPU() {
+               return _ldmlOptions.get().isGPU();
+       }
+       
+       /**
+        * @return true if GPU is enabled in forced mode
+        */
+       public static boolean isForcedGPU() {
+               return _ldmlOptions.get().isGPU();
+       }
+       
+       /**
+        * @return the execution Mode
+        */
+       public static RUNTIME_PLATFORM getExecutionMode() {
+               return _ldmlOptions.get().getExecutionMode();
+       }
+       
+       // 
-------------------------------------------------------------------------------
+       // This needs to be revisited in context of multi-threaded execution: 
JMLC.
+       // Since STATISTICS and FINEGRAINED_STATISTICS are frequently used 
flags,
+       // we use static variables here instead of _dmlOptions.stats and 
+       // _dmlconf.getBooleanValue(DMLConfig.EXTRA_FINEGRAINED_STATS);
+       private static boolean STATISTICS = false;
+       private static boolean FINEGRAINED_STATISTICS = false;
+       
+       /**
+        * @return true if statistics is enabled
+        */
+       public static boolean isStatistics() {
+               return STATISTICS;
+       }
+       
+       /**
+        * @return true if finegrained statistics is enabled
+        */
+       public static boolean isFinegrainedStatistics() {
+               return FINEGRAINED_STATISTICS;
+       }
+       
+       /**
+        * Whether or not statistics about the DML/PYDML program should be 
output to
+        * standard output.
+        *
+        * @param enabled
+        *            {@code true} if statistics should be output, {@code false}
+        *            otherwise
+        */
+       public static void setStatistics(boolean enabled) {
+               STATISTICS = enabled;
+       }
+       
+       /**
+        * Reset the statistics flag.
+        */
+       public static void resetStatistics() {
+               STATISTICS = false;
+       }
+       
+       
+       // 
-------------------------------------------------------------------------------
+       
        ///////////////////////////////////////
        // Thread-local classes
        
+       private static class ThreadLocalDMLOptions extends 
ThreadLocal<DMLOptions> {
+               @Override 
+               protected DMLOptions initialValue() {  
+                       if(_dmlOptions != null)
+                               return _dmlOptions;
+                       return DMLOptions.defaultOptions;
+               }
+       }
+       
        private static class ThreadLocalDMLConfig extends 
ThreadLocal<DMLConfig> {
                @Override 
                protected DMLConfig initialValue() { 

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/conf/DMLOptions.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/conf/DMLOptions.java 
b/src/main/java/org/apache/sysml/conf/DMLOptions.java
new file mode 100644
index 0000000..3263e48
--- /dev/null
+++ b/src/main/java/org/apache/sysml/conf/DMLOptions.java
@@ -0,0 +1,355 @@
+/*
+ * 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.conf;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.PosixParser;
+import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
+import org.apache.sysml.api.mlcontext.ScriptType;
+import org.apache.sysml.hops.OptimizerUtils;
+import org.apache.sysml.utils.Explain;
+import org.apache.sysml.utils.Explain.ExplainType;
+
+/**
+ * Set of DMLOptions that can be set through the command line
+ * and {@link org.apache.sysml.api.mlcontext.MLContext}
+ * The values have been initialized with the default values
+ * Despite there being a DML and PyDML, this class is named DMLOptions
+ * to keep it consistent with {@link DMLOptions} and {@link DMLOptions}
+ */
+public class DMLOptions {
+       public final Options        options;
+       public Map<String, String>  argVals       = new HashMap<>();  // 
Arguments map containing either named arguments or arguments by position for a 
DML program
+       public String               configFile    = null;             // Path 
to config file if default config and default config is to be overriden
+       public boolean              clean         = false;            // 
Whether to clean up all SystemML working directories (FS, DFS)
+       public boolean              stats         = false;            // 
Whether to record and print the statistics
+       public int                  statsCount    = 10;               // 
Default statistics count
+       public boolean              memStats      = false;            // max 
memory statistics
+       public Explain.ExplainType  explainType   = Explain.ExplainType.NONE;  
// Whether to print the "Explain" and if so, what type
+       public RUNTIME_PLATFORM     execMode = 
OptimizerUtils.getDefaultExecutionMode();  // Execution mode standalone, MR, 
Spark or a hybrid
+       public boolean              gpu           = false;            // 
Whether to use the GPU
+       public boolean              forceGPU      = false;            // 
Whether to ignore memory & estimates and always use the GPU
+       public boolean              debug         = false;            // to go 
into debug mode to be able to step through a program
+       public ScriptType           scriptType    = ScriptType.DML;   // 
whether the script is a DML or PyDML script
+       public String               filePath      = null;             // path 
to script
+       public String               script        = null;             // the 
script itself
+       public boolean              help          = false;            // 
whether to print the usage option
+
+       public final static DMLOptions defaultOptions = new DMLOptions(null);
+
+       // Set when invoked via DMLScript
+       public DMLOptions(Options opts) {
+               options = opts;
+       }
+       
+       // Set when invoked via MLContext and JMLC via 
Configuration.setGlobalOptions and Configuration.setLocalOptions respectively
+       public DMLOptions(Map<String, String>  argVals, boolean stats, int 
statsCount, boolean memStats, 
+                       Explain.ExplainType  explainType, RUNTIME_PLATFORM 
execMode, boolean gpu, boolean forceGPU, 
+                       ScriptType scriptType, String filePath, String script) {
+               options = null;
+               this.argVals = argVals;
+               this.stats = stats;
+               this.statsCount = statsCount;
+               this.memStats = memStats;
+               this.explainType = explainType;
+               this.execMode = execMode;
+               this.gpu = gpu;
+               this.forceGPU = forceGPU;
+               this.scriptType = scriptType;
+               this.filePath = filePath;
+               this.script = script;
+       }
+       
+       /**
+        * @return the filePath
+        */
+       public String getFilePath() {
+               return filePath;
+       }
+
+       /**
+        * @return the execution Mode
+        */
+       public RUNTIME_PLATFORM getExecutionMode() {
+               return execMode;
+       }
+
+       /**
+        * @param execMode the execution Mode to set
+        */
+       public void setExecutionMode(RUNTIME_PLATFORM execMode) {
+               this.execMode = execMode;
+       }
+
+       /**
+        * Sets the maximum number of heavy hitters that are printed out as 
part of
+        * the statistics.
+        *
+        * @param maxHeavyHitters
+        *            maximum number of heavy hitters to print
+        */
+       public void setStatisticsMaxHeavyHitters(int maxHeavyHitters) {
+               this.statsCount = maxHeavyHitters;
+       }
+       
+       /**
+        * @return the number of statistics instructions to print
+        */
+       public int getStatisticsMaxHeavyHitters() {
+               return statsCount;
+       }
+
+       /**
+        * Whether or not to enable GPU usage.
+        *
+        * @param enabled
+        *            {@code true} if enabled, {@code false} otherwise
+        */
+       public void setGPU(boolean enabled) {
+               this.gpu = enabled;
+       }
+
+       /**
+        * @return true if gpu is enabled
+        */
+       public boolean isGPU() {
+               return gpu;
+       }
+       
+       /**
+        * Whether or not to force GPU usage.
+        *
+        * @param enabled
+        *            {@code true} if enabled, {@code false} otherwise
+        */
+       public void setForceGPU(boolean enabled) {
+               this.forceGPU = enabled;
+       }
+       
+       /**
+        * @return true if GPU is enabled in forced mode
+        */
+       public boolean isForceGPU() {
+               return forceGPU;
+       }
+       
+       @Override
+       public String toString() {
+               return "DMLOptions{" +
+                       "argVals=" + argVals +
+                       ", configFile='" + configFile + '\'' +
+                       ", clean=" + clean +
+                       ", stats=" + stats +
+                       ", statsCount=" + statsCount +
+                       ", memStats=" + memStats +
+                       ", explainType=" + explainType +
+                       ", execMode=" + execMode +
+                       ", gpu=" + gpu +
+                       ", forceGPU=" + forceGPU +
+                       ", debug=" + debug +
+                       ", scriptType=" + scriptType +
+                       ", filePath='" + filePath + '\'' +
+                       ", script='" + script + '\'' +
+                       ", help=" + help +
+                       '}';
+       }
+       
+       /**
+        * Parses command line arguments to create a {@link DMLOptions} 
instance with the correct options
+        * @param args arguments from the command line
+        * @return an instance of {@link DMLOptions} that contain the correct 
{@link Option}s.
+        * @throws org.apache.commons.cli.ParseException if there is an 
incorrect option specified in the CLI
+        */
+       public static DMLOptions parseCLArguments(String[] args)
+               throws org.apache.commons.cli.ParseException
+       {
+               Options options = createCLIOptions();
+               CommandLineParser clParser = new PosixParser();
+               CommandLine line = clParser.parse(options, args);
+
+               DMLOptions dmlOptions = new DMLOptions(options);
+               dmlOptions.help = line.hasOption("help");
+               dmlOptions.scriptType = line.hasOption("python") ? 
ScriptType.PYDML : ScriptType.DML;
+               dmlOptions.debug = line.hasOption("debug");
+               dmlOptions.gpu = line.hasOption("gpu");
+               if (dmlOptions.gpu) {
+                       String force = line.getOptionValue("gpu");
+                       if (force != null) {
+                               if (force.equalsIgnoreCase("force")) {
+                                       dmlOptions.forceGPU = true;
+                               } else {
+                                       throw new 
org.apache.commons.cli.ParseException("Invalid argument specified for -gpu 
option");
+                               }
+                       }
+               }
+               if (line.hasOption("exec")){
+                       String execMode = line.getOptionValue("exec");
+                       if (execMode != null){
+                               if (execMode.equalsIgnoreCase("hadoop")) 
dmlOptions.execMode = RUNTIME_PLATFORM.HADOOP;
+                               else if 
(execMode.equalsIgnoreCase("singlenode")) dmlOptions.execMode = 
RUNTIME_PLATFORM.SINGLE_NODE;
+                               else if (execMode.equalsIgnoreCase("hybrid")) 
dmlOptions.execMode = RUNTIME_PLATFORM.HYBRID;
+                               else if 
(execMode.equalsIgnoreCase("hybrid_spark")) dmlOptions.execMode = 
RUNTIME_PLATFORM.HYBRID_SPARK;
+                               else if (execMode.equalsIgnoreCase("spark")) 
dmlOptions.execMode = RUNTIME_PLATFORM.SPARK;
+                               else throw new 
org.apache.commons.cli.ParseException("Invalid argument specified for -exec 
option, must be one of [hadoop, singlenode, hybrid, hybrid_spark, spark]");
+                       }
+               }
+               if (line.hasOption("explain")) {
+                       dmlOptions.explainType = ExplainType.RUNTIME;
+                       String explainType = line.getOptionValue("explain");
+                       if (explainType != null){
+                               if (explainType.equalsIgnoreCase("hops")) 
dmlOptions.explainType = ExplainType.HOPS;
+                               else if 
(explainType.equalsIgnoreCase("runtime")) dmlOptions.explainType = 
ExplainType.RUNTIME;
+                               else if 
(explainType.equalsIgnoreCase("recompile_hops")) dmlOptions.explainType = 
ExplainType.RECOMPILE_HOPS;
+                               else if 
(explainType.equalsIgnoreCase("recompile_runtime")) dmlOptions.explainType = 
ExplainType.RECOMPILE_RUNTIME;
+                               else throw new 
org.apache.commons.cli.ParseException("Invalid argument specified for -hops 
option, must be one of [hops, runtime, recompile_hops, recompile_runtime]");
+                       }
+               }
+               dmlOptions.stats = line.hasOption("stats");
+               if (dmlOptions.stats){
+                       String statsCount = line.getOptionValue("stats");
+                       if (statsCount != null) {
+                               try {
+                                       dmlOptions.statsCount = 
Integer.parseInt(statsCount);
+                               } catch (NumberFormatException e) {
+                                       throw new 
org.apache.commons.cli.ParseException("Invalid argument specified for -stats 
option, must be a valid integer");
+                               }
+                       }
+               }
+               dmlOptions.memStats = line.hasOption("mem");
+
+               dmlOptions.clean = line.hasOption("clean");
+
+               if (line.hasOption("config")){
+                       dmlOptions.configFile = line.getOptionValue("config");
+               }
+
+               if (line.hasOption("f")){
+                       dmlOptions.filePath = line.getOptionValue("f");
+               }
+
+               if (line.hasOption("s")){
+                       dmlOptions.script = line.getOptionValue("s");
+               }
+
+               // Positional arguments map is created as ("$1", "a"), ("$2", 
123), etc
+               if (line.hasOption("args")){
+                       String[] argValues = line.getOptionValues("args");
+                       for (int k=0; k<argValues.length; k++){
+                               String str = argValues[k];
+                               if (!str.isEmpty()) {
+                                       dmlOptions.argVals.put("$" + (k+1), 
str);
+                               }
+                       }
+               }
+
+               // Named arguments map is created as ("$K, 123), ("$X", 
"X.csv"), etc
+               if (line.hasOption("nvargs")){
+                       String varNameRegex = "^[a-zA-Z]([a-zA-Z0-9_])*$";
+                       String[] nvargValues = line.getOptionValues("nvargs");
+                       for (String str : nvargValues){
+                               if (!str.isEmpty()){
+                                       String[] kv = str.split("=");
+                                       if (kv.length != 2){
+                                               throw new 
org.apache.commons.cli.ParseException("Invalid argument specified for -nvargs 
option, must be a list of space separated K=V pairs, where K is a valid name of 
a variable in the DML/PyDML program");
+                                       }
+                                       if (!kv[0].matches(varNameRegex)) {
+                                               throw new 
org.apache.commons.cli.ParseException("Invalid argument specified for -nvargs 
option, " + kv[0] + " does not seem like a valid variable name in DML. Valid 
variable names in DML start with upper-case or lower-case letter, and contain 
only letters, digits, or underscores");
+                                       }
+                                       dmlOptions.argVals.put("$" + kv[0], 
kv[1]);
+                               }
+                       }
+               }
+
+               return dmlOptions;
+       }
+       
+       @SuppressWarnings("static-access")
+       private static Options createCLIOptions() {
+               Options options = new Options();
+               Option nvargsOpt = OptionBuilder.withArgName("key=value")
+                       .withDescription("parameterizes DML script with named 
parameters of the form <key=value>; <key> should be a valid identifier in 
DML/PyDML")
+                       .hasArgs().create("nvargs");
+               Option argsOpt = OptionBuilder.withArgName("argN")
+                       .withDescription("specifies positional parameters; 
first value will replace $1 in DML program; $2 will replace 2nd and so on")
+                       .hasArgs().create("args");
+               Option configOpt = OptionBuilder.withArgName("filename")
+                       .withDescription("uses a given configuration file (can 
be on local/hdfs/gpfs; default values in SystemML-config.xml")
+                       .hasArg().create("config");
+               Option cleanOpt = OptionBuilder.withDescription("cleans up all 
SystemML working directories (FS, DFS); all other flags are ignored in this 
mode. \n")
+                       .create("clean");
+               Option statsOpt = OptionBuilder.withArgName("count")
+                       .withDescription("monitors and reports summary 
execution statistics; heavy hitter <count> is 10 unless overridden; default 
off")
+                       .hasOptionalArg().create("stats");
+               Option memOpt = OptionBuilder.withDescription("monitors and 
reports max memory consumption in CP; default off")
+                       .create("mem");
+               Option explainOpt = OptionBuilder.withArgName("level")
+                       .withDescription("explains plan levels; can be 'hops' / 
'runtime'[default] / 'recompile_hops' / 'recompile_runtime'")
+                       .hasOptionalArg().create("explain");
+               Option execOpt = OptionBuilder.withArgName("mode")
+                       .withDescription("sets execution mode; can be 'hadoop' 
/ 'singlenode' / 'hybrid'[default] / 'hybrid_spark' / 'spark'")
+                       .hasArg().create("exec");
+               Option gpuOpt = OptionBuilder.withArgName("force")
+                       .withDescription("uses CUDA instructions when 
reasonable; set <force> option to skip conservative memory estimates and use 
GPU wherever possible; default off")
+                       .hasOptionalArg().create("gpu");
+               Option debugOpt = OptionBuilder.withDescription("runs in debug 
mode; default off")
+                       .create("debug");
+               Option pythonOpt = OptionBuilder.withDescription("parses 
Python-like DML")
+                       .create("python");
+               Option fileOpt = OptionBuilder.withArgName("filename")
+                       .withDescription("specifies dml/pydml file to execute; 
path can be local/hdfs/gpfs (prefixed with appropriate URI)")
+                       .isRequired().hasArg().create("f");
+               Option scriptOpt = OptionBuilder.withArgName("script_contents")
+                       .withDescription("specified script string to execute 
directly")
+                       .isRequired().hasArg().create("s");
+               Option helpOpt = OptionBuilder.withDescription("shows usage 
message")
+                       .create("help");
+               
+               options.addOption(configOpt);
+               options.addOption(cleanOpt);
+               options.addOption(statsOpt);
+               options.addOption(memOpt);
+               options.addOption(explainOpt);
+               options.addOption(execOpt);
+               options.addOption(gpuOpt);
+               options.addOption(debugOpt);
+               options.addOption(pythonOpt);
+               
+               // Either a clean(-clean), a file(-f), a script(-s) or 
help(-help) needs to be specified
+               OptionGroup fileOrScriptOpt = new OptionGroup()
+                       
.addOption(scriptOpt).addOption(fileOpt).addOption(cleanOpt).addOption(helpOpt);
+               fileOrScriptOpt.setRequired(true);
+               options.addOptionGroup(fileOrScriptOpt);
+               
+               // Either -args or -nvargs
+               options.addOptionGroup(new OptionGroup()
+                       .addOption(nvargsOpt).addOption(argsOpt));
+               options.addOption(helpOpt);
+               
+               return options;
+       }
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/AggBinaryOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/AggBinaryOp.java 
b/src/main/java/org/apache/sysml/hops/AggBinaryOp.java
index 9b2b650..b267b0c 100644
--- a/src/main/java/org/apache/sysml/hops/AggBinaryOp.java
+++ b/src/main/java/org/apache/sysml/hops/AggBinaryOp.java
@@ -19,8 +19,8 @@
 
 package org.apache.sysml.hops;
 
-import org.apache.sysml.api.DMLScript;
 import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
+import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.hops.rewrite.HopRewriteUtils;
 import org.apache.sysml.lops.Aggregate;
 import org.apache.sysml.lops.Binary;
@@ -132,7 +132,7 @@ public class AggBinaryOp extends MultiThreadedHop
        
        @Override
        public boolean isGPUEnabled() {
-               if(!DMLScript.USE_ACCELERATOR)
+               if(!ConfigurationManager.isGPU())
                        return false;
                
                Hop input1 = getInput().get(0);
@@ -1265,8 +1265,8 @@ public class AggBinaryOp extends MultiThreadedHop
        {
                //check for forced MR or Spark execution modes, which prevent 
the introduction of
                //additional CP operations and hence the rewrite application
-               if(    DMLScript.rtplatform == RUNTIME_PLATFORM.HADOOP  //not 
hybrid_mr
-                       || DMLScript.rtplatform == RUNTIME_PLATFORM.SPARK ) 
//not hybrid_spark
+               if(    ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.HADOOP  //not hybrid_mr
+                       || ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.SPARK ) //not hybrid_spark
                {
                        return false;
                }

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/AggUnaryOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/AggUnaryOp.java 
b/src/main/java/org/apache/sysml/hops/AggUnaryOp.java
index af9d936..48d18b7 100644
--- a/src/main/java/org/apache/sysml/hops/AggUnaryOp.java
+++ b/src/main/java/org/apache/sysml/hops/AggUnaryOp.java
@@ -19,7 +19,7 @@
 
 package org.apache.sysml.hops;
 
-import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.hops.AggBinaryOp.SparkAggType;
 import org.apache.sysml.hops.rewrite.HopRewriteUtils;
 import org.apache.sysml.lops.Aggregate;
@@ -89,7 +89,7 @@ public class AggUnaryOp extends MultiThreadedHop
        
        @Override
        public boolean isGPUEnabled() {
-               if(!DMLScript.USE_ACCELERATOR)
+               if(!ConfigurationManager.isGPU())
                        return false;
                
                try {
@@ -499,7 +499,7 @@ public class AggUnaryOp extends MultiThreadedHop
                boolean ret = false;
                
                // TODO: Disable ternary aggregate rewrite on GPU backend.
-               if(DMLScript.USE_ACCELERATOR)
+               if(!ConfigurationManager.isGPU())
                        return false;
                
                //currently we support only sum over binary multiply but 
potentially 

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/BinaryOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/BinaryOp.java 
b/src/main/java/org/apache/sysml/hops/BinaryOp.java
index 80cfbcb..45fe11e 100644
--- a/src/main/java/org/apache/sysml/hops/BinaryOp.java
+++ b/src/main/java/org/apache/sysml/hops/BinaryOp.java
@@ -19,7 +19,6 @@
 
 package org.apache.sysml.hops;
 
-import org.apache.sysml.api.DMLScript;
 import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.hops.rewrite.HopRewriteUtils;
 import org.apache.sysml.lops.Aggregate;
@@ -131,7 +130,7 @@ public class BinaryOp extends MultiThreadedHop
        
        @Override
        public boolean isGPUEnabled() {
-               if(!DMLScript.USE_ACCELERATOR)
+               if(!ConfigurationManager.isGPU())
                        return false;
                
                switch(op) 

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/DnnOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/DnnOp.java 
b/src/main/java/org/apache/sysml/hops/DnnOp.java
index 4ca90f8..a7d37dc 100644
--- a/src/main/java/org/apache/sysml/hops/DnnOp.java
+++ b/src/main/java/org/apache/sysml/hops/DnnOp.java
@@ -19,7 +19,7 @@
 
 package org.apache.sysml.hops;
 
-import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.hops.rewrite.HopRewriteUtils;
 import org.apache.sysml.lops.DnnTransform;
 import org.apache.sysml.lops.DnnTransform.OperationTypes;
@@ -98,7 +98,7 @@ public class DnnOp extends MultiThreadedHop
        
        @Override
        public boolean isGPUEnabled() {
-               if(!DMLScript.USE_ACCELERATOR)
+               if(!ConfigurationManager.isGPU())
                        return false;
                return true;
        }
@@ -349,7 +349,7 @@ public class DnnOp extends MultiThreadedHop
        {               
                if(getOp() == OpOpDnn.BIASMULT) {
                        // in non-gpu mode, the worst case size of bias 
multiply operation is same as that of input.
-                       if(DMLScript.USE_ACCELERATOR) 
+                       if(ConfigurationManager.isGPU()) 
                                return 
OptimizerUtils.estimateSizeExactSparsity(dim1, dim2, 1.0);
                        else
                                return 
OptimizerUtils.estimateSizeExactSparsity(dim1, dim2, 
getInput().get(0).getSparsity());
@@ -436,7 +436,7 @@ public class DnnOp extends MultiThreadedHop
                        ArrayList<IntermediateDimensions> cpIntermediates) {
                // Since CP operators use row-level parallelism by default
                int numWorkers = (int) 
Math.min(OptimizerUtils.getConstrainedNumThreads(_maxNumThreads), 
Math.max(getDim("N"), 1));
-               if(DMLScript.USE_ACCELERATOR) {
+               if(ConfigurationManager.isGPU()) {
                        // Account for potential sparse-to-dense conversion
                        double gpuMemBudget = 
IntermediateDimensions.addEstimateSizes(gpuIntermediates, 1);
                        double cpMemoryBudget = 
IntermediateDimensions.addEstimateSizes(cpIntermediates, numWorkers);

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/FunctionOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/FunctionOp.java 
b/src/main/java/org/apache/sysml/hops/FunctionOp.java
index 148b39d..ea397db 100644
--- a/src/main/java/org/apache/sysml/hops/FunctionOp.java
+++ b/src/main/java/org/apache/sysml/hops/FunctionOp.java
@@ -22,7 +22,7 @@ package org.apache.sysml.hops;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.lops.FunctionCallCP;
 import org.apache.sysml.lops.FunctionCallCPSingle;
 import org.apache.sysml.lops.Lop;
@@ -304,12 +304,12 @@ public class FunctionOp extends Hop
                                                && 
OptimizerUtils.isSparkExecutionMode())) ? ExecType.SPARK : ExecType.CP);
                        }
                        else if(isBuiltinFunction && 
(getFunctionName().equalsIgnoreCase("lstm") || 
getFunctionName().equalsIgnoreCase("lstm_backward"))) {
-                               if(!DMLScript.USE_ACCELERATOR)
+                               if(!ConfigurationManager.isGPU())
                                        throw new RuntimeException("The 
function " + getFunctionName() + " is only supported on GPU.");
                                _etype = ExecType.GPU;
                        }
                        else if(isBuiltinFunction && 
(getFunctionName().equalsIgnoreCase("batch_norm2d") || 
getFunctionName().equalsIgnoreCase("batch_norm2d_backward"))) {
-                               _etype = DMLScript.USE_ACCELERATOR ? 
ExecType.GPU : ExecType.CP;
+                               _etype = ConfigurationManager.isGPU() ? 
ExecType.GPU : ExecType.CP;
                        }
                        else if(isBuiltinFunction && 
getFunctionName().equalsIgnoreCase("batch_norm2d_train")) {
                                // Only GPU implementation is supported

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/Hop.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/Hop.java 
b/src/main/java/org/apache/sysml/hops/Hop.java
index 73a58e3..3b461a1 100644
--- a/src/main/java/org/apache/sysml/hops/Hop.java
+++ b/src/main/java/org/apache/sysml/hops/Hop.java
@@ -189,10 +189,10 @@ public abstract class Hop implements ParseInfo
        
        public void checkAndSetForcedPlatform()
        {
-               if(DMLScript.USE_ACCELERATOR && DMLScript.FORCE_ACCELERATOR && 
isGPUEnabled())
+               if(ConfigurationManager.isGPU() && 
ConfigurationManager.isForcedGPU() && isGPUEnabled())
                        _etypeForced = ExecType.GPU; // enabled with -gpu force 
option
-               else if ( DMLScript.rtplatform == RUNTIME_PLATFORM.SINGLE_NODE 
) {
-                       if(OptimizerUtils.isMemoryBasedOptLevel() && 
DMLScript.USE_ACCELERATOR && isGPUEnabled()) {
+               else if ( ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.SINGLE_NODE ) {
+                       if(OptimizerUtils.isMemoryBasedOptLevel() && 
ConfigurationManager.isGPU() && isGPUEnabled()) {
                                // enabled with -exec singlenode -gpu option
                                _etypeForced = findExecTypeByMemEstimate();
                                if(_etypeForced != ExecType.CP && _etypeForced 
!= ExecType.GPU)
@@ -203,9 +203,9 @@ public abstract class Hop implements ParseInfo
                                _etypeForced = ExecType.CP;  
                        }
                }
-               else if ( DMLScript.rtplatform == RUNTIME_PLATFORM.HADOOP )
+               else if ( ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.HADOOP )
                        _etypeForced = ExecType.MR; // enabled with -exec 
hadoop option
-               else if ( DMLScript.rtplatform == RUNTIME_PLATFORM.SPARK )
+               else if ( ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.SPARK )
                        _etypeForced = ExecType.SPARK; // enabled with -exec 
spark option
        }
        
@@ -217,9 +217,9 @@ public abstract class Hop implements ParseInfo
                        
                        //force exec type mr if necessary
                        if( invalid ) { 
-                               if( DMLScript.rtplatform == 
RUNTIME_PLATFORM.HYBRID )
+                               if( ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.HYBRID )
                                        _etype = ExecType.MR;
-                               else if( DMLScript.rtplatform == 
RUNTIME_PLATFORM.HYBRID_SPARK )
+                               else if( 
ConfigurationManager.getExecutionMode() == RUNTIME_PLATFORM.HYBRID_SPARK )
                                        _etype = ExecType.SPARK;
                        }
                }
@@ -290,7 +290,7 @@ public abstract class Hop implements ParseInfo
        {
                //determine execution type
                ExecType et = ExecType.CP;
-               if( DMLScript.rtplatform != RUNTIME_PLATFORM.SINGLE_NODE 
+               if( ConfigurationManager.getExecutionMode() != 
RUNTIME_PLATFORM.SINGLE_NODE 
                        && !(getDataType()==DataType.SCALAR) )
                {
                        et = OptimizerUtils.isSparkExecutionMode() ? 
ExecType.SPARK : ExecType.MR;
@@ -735,15 +735,15 @@ public abstract class Hop implements ParseInfo
                char c = ' ';
                double memEst = getMemEstimate();
                if ( memEst < OptimizerUtils.getLocalMemBudget() ) {
-                       if (DMLScript.USE_ACCELERATOR && isGPUEnabled() && 
memEst < GPUContextPool.initialGPUMemBudget())
+                       if (ConfigurationManager.isGPU() && isGPUEnabled() && 
memEst < GPUContextPool.initialGPUMemBudget())
                                et = ExecType.GPU;
                        else
                                et = ExecType.CP;
                }
                else {
-                       if( DMLScript.rtplatform == 
DMLScript.RUNTIME_PLATFORM.HYBRID )
+                       if( ConfigurationManager.getExecutionMode() == 
DMLScript.RUNTIME_PLATFORM.HYBRID )
                                et = ExecType.MR;
-                       else if( DMLScript.rtplatform == 
DMLScript.RUNTIME_PLATFORM.HYBRID_SPARK )
+                       else if( ConfigurationManager.getExecutionMode() == 
DMLScript.RUNTIME_PLATFORM.HYBRID_SPARK )
                                et = ExecType.SPARK;
                        
                        c = '*';

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/IndexingOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/IndexingOp.java 
b/src/main/java/org/apache/sysml/hops/IndexingOp.java
index 4bb03b4..1091027 100644
--- a/src/main/java/org/apache/sysml/hops/IndexingOp.java
+++ b/src/main/java/org/apache/sysml/hops/IndexingOp.java
@@ -19,7 +19,7 @@
 
 package org.apache.sysml.hops;
 
-import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.hops.AggBinaryOp.SparkAggType;
 import org.apache.sysml.hops.rewrite.HopRewriteUtils;
 import org.apache.sysml.lops.Aggregate;
@@ -97,7 +97,7 @@ public class IndexingOp extends Hop
        
        @Override
        public boolean isGPUEnabled() {
-               if(!DMLScript.USE_ACCELERATOR) {
+               if(!ConfigurationManager.isGPU()) {
                        return false;
                }
                else {

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/OptimizerUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/OptimizerUtils.java 
b/src/main/java/org/apache/sysml/hops/OptimizerUtils.java
index e78d809..a43abb3 100644
--- a/src/main/java/org/apache/sysml/hops/OptimizerUtils.java
+++ b/src/main/java/org/apache/sysml/hops/OptimizerUtils.java
@@ -552,18 +552,18 @@ public class OptimizerUtils
        }
 
        public static boolean isSparkExecutionMode() {
-               return (   DMLScript.rtplatform == RUNTIME_PLATFORM.SPARK
-                               || DMLScript.rtplatform == 
RUNTIME_PLATFORM.HYBRID_SPARK);
+               return (   ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.SPARK
+                               || ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.HYBRID_SPARK);
        }
 
        public static boolean isHadoopExecutionMode() {
-               return (   DMLScript.rtplatform == RUNTIME_PLATFORM.HADOOP
-                               || DMLScript.rtplatform == 
RUNTIME_PLATFORM.HYBRID);
+               return (   ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.HADOOP
+                               || ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.HYBRID);
        }
 
        public static boolean isHybridExecutionMode() {
-               return (  DMLScript.rtplatform == RUNTIME_PLATFORM.HYBRID 
-                          || DMLScript.rtplatform == 
RUNTIME_PLATFORM.HYBRID_SPARK );
+               return (  ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.HYBRID 
+                          || ConfigurationManager.getExecutionMode() == 
RUNTIME_PLATFORM.HYBRID_SPARK );
        }
        
        /**

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/ReorgOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/ReorgOp.java 
b/src/main/java/org/apache/sysml/hops/ReorgOp.java
index 4fa782d..ab6a641 100644
--- a/src/main/java/org/apache/sysml/hops/ReorgOp.java
+++ b/src/main/java/org/apache/sysml/hops/ReorgOp.java
@@ -21,7 +21,7 @@ package org.apache.sysml.hops;
 
 import java.util.ArrayList;
 
-import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.hops.rewrite.HopRewriteUtils;
 import org.apache.sysml.lops.Aggregate;
 import org.apache.sysml.lops.Group;
@@ -115,7 +115,7 @@ public class ReorgOp extends MultiThreadedHop
        
        @Override
        public boolean isGPUEnabled() {
-               if(!DMLScript.USE_ACCELERATOR)
+               if(!ConfigurationManager.isGPU())
                        return false;
                switch( op ) {
                        case TRANS: {

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/TernaryOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/TernaryOp.java 
b/src/main/java/org/apache/sysml/hops/TernaryOp.java
index b6e62ff..ad1b4b2 100644
--- a/src/main/java/org/apache/sysml/hops/TernaryOp.java
+++ b/src/main/java/org/apache/sysml/hops/TernaryOp.java
@@ -19,7 +19,6 @@
 
 package org.apache.sysml.hops;
 
-import org.apache.sysml.api.DMLScript;
 import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.hops.rewrite.HopRewriteUtils;
 import org.apache.sysml.lops.Aggregate;
@@ -127,7 +126,7 @@ public class TernaryOp extends Hop
        
        @Override
        public boolean isGPUEnabled() {
-               if(!DMLScript.USE_ACCELERATOR)
+               if(!ConfigurationManager.isGPU())
                        return false;
                switch( _op ) {
                        case MOMENT:

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/UnaryOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/UnaryOp.java 
b/src/main/java/org/apache/sysml/hops/UnaryOp.java
index f93d40d..86f935f 100644
--- a/src/main/java/org/apache/sysml/hops/UnaryOp.java
+++ b/src/main/java/org/apache/sysml/hops/UnaryOp.java
@@ -21,7 +21,7 @@ package org.apache.sysml.hops;
 
 import java.util.ArrayList;
 
-import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.lops.Aggregate;
 import org.apache.sysml.lops.Aggregate.OperationTypes;
 import org.apache.sysml.lops.CombineUnary;
@@ -85,7 +85,7 @@ public class UnaryOp extends MultiThreadedHop
 
        @Override
        public boolean isGPUEnabled() {
-               if(!DMLScript.USE_ACCELERATOR)
+               if(!ConfigurationManager.isGPU())
                        return false;
                boolean isScalar = (    getDataType() == DataType.SCALAR 
//value type casts or matrix to scalar
                                || (_op == OpOp1.CAST_AS_MATRIX && 
getInput().get(0).getDataType()==DataType.SCALAR)

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java 
b/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
index 9fc9ac4..665e71d 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
@@ -340,7 +340,7 @@ public class SpoofCompiler
                if( roots == null || roots.isEmpty() )
                        return roots;
        
-               long t0 = DMLScript.STATISTICS ? System.nanoTime() : 0;
+               long t0 = ConfigurationManager.isStatistics() ? 
System.nanoTime() : 0;
                ArrayList<Hop> ret = roots;
                
                try
@@ -406,14 +406,14 @@ public class SpoofCompiler
                                        if( 
PLAN_CACHE_POLICY!=PlanCachePolicy.NONE )
                                                
planCache.putPlan(tmp.getValue(), cla);
                                }
-                               else if( DMLScript.STATISTICS ) {
+                               else if( ConfigurationManager.isStatistics() ) {
                                        
Statistics.incrementCodegenOpCacheHits();
                                }
                                
                                //make class available and maintain hits
                                if(cla != null)
                                        clas.put(cplan.getKey(), new 
Pair<Hop[],Class<?>>(tmp.getKey(),cla));
-                               if( DMLScript.STATISTICS )
+                               if( ConfigurationManager.isStatistics() )
                                        
Statistics.incrementCodegenOpCacheTotal();
                        }
                        
@@ -438,7 +438,7 @@ public class SpoofCompiler
                        throw new DMLRuntimeException(ex);
                }
                
-               if( DMLScript.STATISTICS ) {
+               if( ConfigurationManager.isStatistics() ) {
                        Statistics.incrementCodegenDAGCompile();
                        
Statistics.incrementCodegenCompileTime(System.nanoTime()-t0);
                }
@@ -559,7 +559,7 @@ public class SpoofCompiler
                        cplans.put(hop.getHopID(), TemplateUtils
                                        
.createTemplate(memo.getBest(hop.getHopID()).type)
                                        .constructCplan(hop, memo, 
compileLiterals));
-                       if (DMLScript.STATISTICS)
+                       if (ConfigurationManager.isStatistics())
                                Statistics.incrementCodegenCPlanCompile(1);
                }
                
@@ -726,7 +726,7 @@ public class SpoofCompiler
                                }
                                else if( OptimizerUtils.isSparkExecutionMode() 
) {
                                        Hop hop = 
memo.getHopRefs().get(e.getKey());
-                                       boolean isSpark = DMLScript.rtplatform 
== RUNTIME_PLATFORM.SPARK
+                                       boolean isSpark = 
ConfigurationManager.getExecutionMode() == RUNTIME_PLATFORM.SPARK
                                                || 
OptimizerUtils.getTotalMemEstimate(inHops, hop, true)
                                                        > 
OptimizerUtils.getLocalMemBudget();
                                        boolean invalidNcol = 
hop.getDataType().isMatrix() && (HopRewriteUtils.isTransposeOperation(hop) ?

http://git-wip-us.apache.org/repos/asf/systemml/blob/ae268a9e/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBased.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBased.java
 
b/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBased.java
index ed37084..028b84a 100644
--- 
a/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBased.java
+++ 
b/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBased.java
@@ -35,7 +35,7 @@ import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.conf.ConfigurationManager;
 import org.apache.sysml.hops.AggBinaryOp;
 import org.apache.sysml.hops.AggUnaryOp;
 import org.apache.sysml.hops.BinaryOp;
@@ -106,7 +106,7 @@ public class PlanSelectionFuseCostBased extends 
PlanSelection
                        memo.setDistinct(e.getKey(), e.getValue());
                
                //maintain statistics
-               if( DMLScript.STATISTICS )
+               if( ConfigurationManager.isStatistics() )
                        Statistics.incrementCodegenEnumAll(UtilFunctions.pow(2, 
sumMatPoints));
        }
        
@@ -395,7 +395,7 @@ public class PlanSelectionFuseCostBased extends 
PlanSelection
                                }
                        }
                        
-                       if( DMLScript.STATISTICS ) {
+                       if( ConfigurationManager.isStatistics() ) {
                                Statistics.incrementCodegenEnumAllP(len);
                                Statistics.incrementCodegenEnumEval(len);
                        }

Reply via email to