From 337b6f469c0f9b7a45d1af8c7a41dba35572edaf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Thu, 6 May 2021 16:25:46 +0200
Subject: [PATCH] New parallel_use_psexec command-line option

Ref. dynare!1843
---
 src/ConfigFile.cc | 13 ++++++++++---
 src/ConfigFile.hh |  7 ++++---
 src/DynareMain.cc | 27 ++++++++++++++++++++++++---
 3 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/src/ConfigFile.cc b/src/ConfigFile.cc
index bf261c16..a6303148 100644
--- a/src/ConfigFile.cc
+++ b/src/ConfigFile.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2010-2020 Dynare Team
+ * Copyright © 2010-2021 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -98,9 +98,12 @@ Cluster::Cluster(member_nodes_t member_nodes_arg) :
 }
 
 ConfigFile::ConfigFile(bool parallel_arg, bool parallel_test_arg,
-                       bool parallel_slave_open_mode_arg, string cluster_name_arg) :
+                       bool parallel_slave_open_mode_arg, bool parallel_use_psexec_arg,
+                       string cluster_name_arg) :
   parallel{parallel_arg}, parallel_test{parallel_test_arg},
-  parallel_slave_open_mode{parallel_slave_open_mode_arg}, cluster_name{move(cluster_name_arg)}
+  parallel_slave_open_mode{parallel_slave_open_mode_arg},
+  parallel_use_psexec{parallel_use_psexec_arg},
+  cluster_name{move(cluster_name_arg)}
 {
 }
 
@@ -748,8 +751,12 @@ ConfigFile::writeCluster(ostream &output) const
         output << "'SingleCompThread', 'false');" << endl;
     }
 
+  // Default values for the following two are both in DynareMain.cc and matlab/default_option_values.m
   if (parallel_slave_open_mode)
     output << "options_.parallel_info.leaveSlaveOpen = 1;" << endl;
+  if (!parallel_use_psexec)
+    output << "options_.parallel_use_psexec = false;" << endl;
+
   output << "options_.parallel_info.console_mode= isoctave;" << endl;
 
   output << "InitializeComputationalEnvironment();" << endl;
diff --git a/src/ConfigFile.hh b/src/ConfigFile.hh
index d20aa7b7..c8d42466 100644
--- a/src/ConfigFile.hh
+++ b/src/ConfigFile.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2010-2020 Dynare Team
+ * Copyright © 2010-2021 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -91,10 +91,11 @@ protected:
 class ConfigFile
 {
 public:
-  ConfigFile(bool parallel_arg, bool parallel_test_arg, bool parallel_slave_open_mode_arg, string cluster_name);
+  ConfigFile(bool parallel_arg, bool parallel_test_arg, bool parallel_slave_open_mode_arg,
+             bool parallel_use_psexec_arg, string cluster_name);
 
 private:
-  const bool parallel, parallel_test, parallel_slave_open_mode;
+  const bool parallel, parallel_test, parallel_slave_open_mode, parallel_use_psexec;
   const string cluster_name;
   string firstClusterName;
   //! Hooks
diff --git a/src/DynareMain.cc b/src/DynareMain.cc
index 6874fb96..5a357359 100644
--- a/src/DynareMain.cc
+++ b/src/DynareMain.cc
@@ -49,7 +49,7 @@ void
 usage()
 {
   cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [linemacro] [notmpterms] [nolog] [warn_uninit]"
-       << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]"
+       << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test] [parallel_use_psexec=true|false]"
        << " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] [compute_xrefs] [output=second|third] [language=matlab|julia]"
        << " [params_derivs_order=0|1|2] [transform_unary_ops] [exclude_eqs=<equation_tag_list_or_file>] [include_eqs=<equation_tag_list_or_file>]"
        << " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple] [nopathchange] [nopreprocessoroutput]"
@@ -137,8 +137,9 @@ main(int argc, char **argv)
   string parallel_config_file;
   bool parallel = false;
   string cluster_name;
-  bool parallel_slave_open_mode = false;
+  bool parallel_slave_open_mode = false; // Must be the same default as in matlab/default_option_values.m
   bool parallel_test = false;
+  bool parallel_use_psexec = true; // Must be the same default as in matlab/default_option_values.m
   bool nostrict = false;
   bool stochastic = false;
   bool check_model_changes = false;
@@ -230,6 +231,26 @@ main(int argc, char **argv)
         parallel_slave_open_mode = true;
       else if (s == "parallel_test")
         parallel_test = true;
+      else if (s.substr(0, 19) == "parallel_use_psexec")
+        {
+          if (s.length() <= 20 || s.at(19) != '=')
+            {
+              cerr << "Incorrect syntax for parallel_use_psexec option" << endl;
+              usage();
+            }
+
+          s.erase(0, 20);
+
+          if (s == "true")
+            parallel_use_psexec = true;
+          else if (s == "false")
+            parallel_use_psexec = false;
+          else
+            {
+              cerr << "Incorrect syntax for parallel_use_psexec option" << endl;
+              usage();
+            }
+        }
       else if (s == "nostrict")
         nostrict = true;
       else if (s == "stochastic")
@@ -429,7 +450,7 @@ main(int argc, char **argv)
   WarningConsolidation warnings(no_warn);
 
   // Process config file
-  ConfigFile config_file(parallel, parallel_test, parallel_slave_open_mode, cluster_name);
+  ConfigFile config_file(parallel, parallel_test, parallel_slave_open_mode, parallel_use_psexec, cluster_name);
   config_file.getConfigFileInfo(parallel_config_file);
   config_file.checkPass(warnings);
   config_file.transformPass();
-- 
GitLab