Changeset 13629


Ignore:
Timestamp:
Oct 1, 2019 12:59:58 PM (3 months ago)
Author:
Jonathan Kämpe
Message:

#5837 Fixed accesses to external constant evaluation options.

Location:
branches/dev-cw-evaluator/Compiler
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-cw-evaluator/Compiler/ModelicaCompiler/src/jastadd/ModelicaCompiler.jrag

    r13396 r13629  
    12661266        /* Temporary fix to problems with long compilation times due to later evaluations */
    12671267        getExternalFunctionCache().tearDown();
    1268         options.setIntegerOption("external_constant_evaluation", 0);
     1268        options.external_constant_evaluation.setValue(0);
    12691269       
    12701270        hookModelTransformed(fc);
  • branches/dev-cw-evaluator/Compiler/ModelicaFlatTree/src/jastadd/ConstantEvaluation/ConstantEvaluation.jrag

    r13431 r13629  
    49794979        }
    49804980       
    4981         public AlgorithmEvaluator createAlgorithmEvaluator(AbstractOptionRegistry options, Map<CommonVariableDecl, CValue> values) {
     4981        public AlgorithmEvaluator createAlgorithmEvaluator(OptionRegistry options, Map<CommonVariableDecl, CValue> values) {
    49824982            return new AlgorithmEvaluator(externalEvaluationEnabled, options, values);
    49834983        }
    49844984       
    4985         public AlgorithmEvaluator createEmptyAlgorithmEvaluator(AbstractOptionRegistry options) {
     4985        public AlgorithmEvaluator createEmptyAlgorithmEvaluator(OptionRegistry options) {
    49864986            return new AlgorithmEvaluator(true, options, Collections.<CommonVariableDecl, CValue>emptyMap());
    49874987        }
     
    50495049       
    50505050        @Override
    5051         public AlgorithmEvaluator createAlgorithmEvaluator(AbstractOptionRegistry options, Map<CommonVariableDecl, CValue> values) {
     5051        public AlgorithmEvaluator createAlgorithmEvaluator(OptionRegistry options, Map<CommonVariableDecl, CValue> values) {
    50525052            return new PartialAlgorithmEvaluator(externalEvaluationEnabled(), options, values, this);
    50535053        }
     
    50835083       
    50845084        @Override
    5085         public AlgorithmEvaluator createAlgorithmEvaluator(AbstractOptionRegistry options, Map<CommonVariableDecl, CValue> values) {
     5085        public AlgorithmEvaluator createAlgorithmEvaluator(OptionRegistry options, Map<CommonVariableDecl, CValue> values) {
    50865086            if (this.values == null) {
    50875087                this.values = values;
     
    51775177    public class AlgorithmEvaluator extends VariableEvaluator {
    51785178       
    5179         protected Map<CommonVariableDecl, CValue> values;
    5180         private AbstractOptionRegistry options;
    5181        
    5182         public AlgorithmEvaluator(boolean evaluateExternalEnabled, AbstractOptionRegistry options, Map<CommonVariableDecl, CValue> values) {
     5179        protected final Map<CommonVariableDecl, CValue> values;
     5180        private final OptionRegistry options;
     5181       
     5182        public AlgorithmEvaluator(boolean evaluateExternalEnabled, OptionRegistry options, Map<CommonVariableDecl, CValue> values) {
    51835183            super(evaluateExternalEnabled);
    51845184            this.values  = values;
     
    51875187       
    51885188        public int externalEvaluation() {
    5189             return externalEvaluationEnabled() ? options.getIntegerOption("external_constant_evaluation") : 0;
     5189            return externalEvaluationEnabled() ? options.external_constant_evaluation.getValue() : 0;
    51905190        }
    51915191       
     
    52515251        protected ArrayList<IfEvaluation> ifStack;
    52525252       
    5253         public PartialAlgorithmEvaluator(boolean evaluateExternalEnabled, AbstractOptionRegistry options,
     5253        public PartialAlgorithmEvaluator(boolean evaluateExternalEnabled, OptionRegistry options,
    52545254                Map<CommonVariableDecl, CValue> values, PartialVariableEvaluator variableEvaluator) {
    52555255            super(evaluateExternalEnabled, options, values);
     
    52685268       
    52695269        @Override
    5270         public AlgorithmEvaluator createAlgorithmEvaluator(AbstractOptionRegistry options, Map<CommonVariableDecl, CValue> values) {
     5270        public AlgorithmEvaluator createAlgorithmEvaluator(OptionRegistry options, Map<CommonVariableDecl, CValue> values) {
    52715271            return variableEvaluator.createAlgorithmEvaluator(options, values);
    52725272        }
  • branches/dev-cw-evaluator/Compiler/ModelicaFlatTree/src/jastadd/ConstantEvaluation/ExternalConstantEvaluation.jrag

    r11541 r13629  
    8989     * Check if this external function should be cached as a live process.
    9090     */
    91     syn boolean FExternalStmt.shouldCacheProcess() {
    92         return myOptions().getIntegerOption("external_constant_evaluation_max_proc") > 0;
    93     }
     91    syn int FExternalStmt.processLimit() =
     92            myOptions().external_constant_evaluation_max_proc.getValue();
     93   
     94    syn boolean FExternalStmt.dynamicEvaluatorEnabled() =
     95            myOptions().external_constant_evaluation_dynamic.getValue()
     96            && !externalObjectsToSerialize().iterator().hasNext();
    9497   
    9598    /**
  • branches/dev-cw-evaluator/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ExternalProcessCacheImpl.java

    r13610 r13629  
    33import java.io.File;
    44import java.io.FileNotFoundException;
    5 import java.io.FilenameFilter;
    65import java.io.IOException;
    76import java.io.PrintStream;
     
    3029     * Maps external functions names to compiled executables.
    3130     */
    32     private Map<String, ExternalFunction<K, V>> cachedExternals = new HashMap<String, ExternalFunction<K, V>>();
     31    private final Map<String, ExternalFunction<K, V>> cachedExternals = new HashMap<String, ExternalFunction<K, V>>();
    3332
    3433    /**
    3534     * Keeps track of all living processes, least recently used first.
    3635     */
    37     private LinkedHashSet<ExternalFunction<K, V>> livingCachedExternals = new LinkedHashSet<ExternalFunction<K, V>>();
    38 
    39     private Compiler<K, E> mc;
     36    private final LinkedHashSet<ExternalFunction<K, V>> livingCachedExternals = new LinkedHashSet<ExternalFunction<K, V>>();
     37
     38    private final Compiler<K, E> mc;
    4039
    4140    public ExternalProcessCacheImpl(Compiler<K, E> mc) {
     
    8281       
    8382        return sharedLib;
    84     }
    85    
    86     private String getOutputArguments(E ext) {
    87         return ext.functionReturnArgSerialized();
    88     }
    89    
    90     private String getInputArguments(E ext) {
    91         return ext.functionArgsSerialized();
    9283    }
    9384   
     
    113104   
    114105    public boolean canUseEvaluator(E ext, ArrayList<String> arguments) {
    115         if (!(ext.myOptions().getBooleanOption("external_constant_evaluation_dynamic"))) {
    116             return false;
    117         }
    118        
    119         /* External objects not supported at the moment */
    120         for (K eo : ext.externalObjectsToSerialize()) {
     106        if (!ext.dynamicEvaluatorEnabled()) {
    121107            return false;
    122108        }
     
    124110        String sharedLibrary = getSharedLibrary(ext);
    125111        String functionName  = ext.getName();
    126         String outputArguments = getOutputArguments(ext);
    127         String inputArguments  = getInputArguments(ext);
     112        String outputArguments = ext.functionReturnArgSerialized();
     113        String inputArguments  = ext.functionArgsSerialized();
    128114       
    129115        if (sharedLibrary.equals("")) {
     
    172158                   
    173159                    debugMsg = "Succesfully connected external function '" + ext.getName() + "' to the evaluator '"
    174                             + executable + "' with outputs: '" + getOutputArguments(ext) + "' and inputs: '" + getInputArguments(ext) + "'";
     160                            + executable + "' with outputs: '" + ext.functionReturnArgSerialized() + "' and inputs: '" + ext.functionArgsSerialized() + "'";
    175161                } else {
    176162                    executable = mc.compileExternal(ext);
     
    182168                }
    183169               
    184                 if (ext.shouldCacheProcess()) {
     170                if (ext.processLimit() > 0) {
    185171                    ef = new MappedExternalFunction(ext, extFunctionExecutable);
    186172                } else {
     
    368354            com.accept("CALC");
    369355            com.accept("DONE");
    370             for (K cvd : ext.varsToDeserialize())
     356            for (K cvd : ext.varsToDeserialize()) {
    371357                values.put(cvd, com.get(cvd.type()));
     358            }
    372359            com.accept("READY");
    373360            com.cancelTimer();
     
    421408            String var = platform.startsWith("win") ? "PATH" : "LD_LIBRARY_PATH";
    422409            String res = env.get(var);
    423             if (res == null)
     410            if (res == null) {
    424411                res = libLoc;
    425             else
     412            } else {
    426413                res = res + sep + libLoc;
     414            }
    427415            env.put(var, res);
    428416        }
     
    441429        public MappedExternalFunction(External<K> ext, ExternalFunctionExecutable extFunctionExecutable) {
    442430            super(ext, extFunctionExecutable);
    443             externalConstantEvaluationMaxProc = ext.myOptions()
    444                     .getIntegerOption("external_constant_evaluation_max_proc");
     431            externalConstantEvaluationMaxProc = ext.processLimit();
    445432        }
    446433
  • branches/dev-cw-evaluator/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ExternalProcessMultiCache.java

    r13610 r13629  
    2323        public String getName();
    2424
    25         public boolean shouldCacheProcess();
     25        public int processLimit();
     26
     27        public boolean dynamicEvaluatorEnabled();
    2628
    2729        public AbstractOptionRegistry myOptions();
  • branches/dev-cw-evaluator/Compiler/ModelicaFrontEnd/test/junit/org/jmodelica/test/common/ExternalProcessCacheTest.java

    r13610 r13629  
    99import java.io.IOException;
    1010
     11import org.jmodelica.common.evaluation.ExternalFunction;
    1112import org.jmodelica.common.evaluation.ExternalProcessCache;
    12 import org.jmodelica.common.evaluation.ExternalFunction;
    1313import org.jmodelica.common.evaluation.ExternalProcessMultiCache;
     14import org.jmodelica.common.evaluation.ExternalProcessMultiCache.External;
     15import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Type;
     16import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Value;
    1417import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Variable;
     18import org.jmodelica.common.evaluation.ProcessCommunicator;
    1519import org.jmodelica.common.options.AbstractOptionRegistry;
    16 import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Value;
    17 import org.jmodelica.common.evaluation.ExternalProcessMultiCache.Type;
    18 import org.jmodelica.common.evaluation.ExternalProcessMultiCache.External;
    19 import org.jmodelica.common.evaluation.ProcessCommunicator;
    2020import org.jmodelica.util.ccompiler.CCompilerDelegator;
    2121import org.jmodelica.util.exceptions.CcodeCompilationException;
     
    189189
    190190        @Override
    191         public boolean shouldCacheProcess() {
    192             // TODO Auto-generated method stub
     191        public int processLimit() {
     192            // TODO Auto-generated method stub
     193            return 0;
     194        }
     195
     196        @Override
     197        public boolean dynamicEvaluatorEnabled() {
    193198            return false;
    194199        }
Note: See TracChangeset for help on using the changeset viewer.