ConfigFile.hh 3.97 KB
Newer Older
1
/*
2
 * Copyright (C) 2010-2016 Dynare Team
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * This file is part of Dynare.
 *
 * Dynare is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Dynare is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _CONFIG_FILE_HH
#define _CONFIG_FILE_HH

#include <map>
#include <vector>
25

26 27
#include "WarningConsolidation.hh"

28 29
using namespace std;

30
typedef map<string, double> member_nodes_t;
31

32 33 34 35 36 37 38 39
class Hook
{
public:
  Hook(string &global_init_file_arg);
  ~Hook();
private:
  map<string, string> hooks;
public:
40 41 42 43 44
  inline map<string, string>
  get_hooks()
  {
    return hooks;
  };
45
};
46

47 48 49
class Path
{
public:
50
  Path(vector<string> &includepath_arg);
51 52 53 54
  ~Path();
private:
  map<string, vector<string> > paths;
public:
55 56 57 58 59
  inline map<string, vector<string> >
  get_paths()
  {
    return paths;
  };
60 61
};

62 63 64 65
class SlaveNode
{
  friend class ConfigFile;
public:
66
  SlaveNode(string &computerName_arg, string port_arg, int minCpuNbr_arg, int maxCpuNbr_arg, string &userName_arg,
67
            string &password_arg, string &remoteDrive_arg, string &remoteDirectory_arg,
68
            string &dynarePath_arg, string &matlabOctavePath_arg, bool singleCompThread_arg, int numberOfThreadsPerJob_arg,
69
            string &operatingSystem_arg);
70 71 72 73
  ~SlaveNode();

protected:
  const string computerName;
74
  const string port;
75 76 77 78 79 80 81 82 83
  int minCpuNbr;
  int maxCpuNbr;
  const string userName;
  const string password;
  const string remoteDrive;
  const string remoteDirectory;
  const string dynarePath;
  const string matlabOctavePath;
  const bool singleCompThread;
84
  const int numberOfThreadsPerJob;
85
  const string operatingSystem;
86 87 88 89 90 91
};

class Cluster
{
  friend class ConfigFile;
public:
92
  Cluster(member_nodes_t member_nodes_arg);
93 94 95
  ~Cluster();

protected:
96
  member_nodes_t member_nodes;
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
};

//! The abstract representation of a "config" file
class ConfigFile
{
public:
  ConfigFile(bool parallel_arg, bool parallel_test_arg, bool parallel_slave_open_mode_arg, const string &cluster_name);
  ~ConfigFile();

private:
  const bool parallel;
  const bool parallel_test;
  const bool parallel_slave_open_mode;
  const string cluster_name;
  string firstClusterName;
112 113
  //! Hooks
  vector<Hook *> hooks;
114 115
  //! Paths
  vector<Path *> paths;
116 117 118 119
  //! Cluster Table
  map<string, Cluster *> clusters;
  //! Node Map
  map<string, SlaveNode *> slave_nodes;
120 121
  //! Add Hooks
  void addHooksConfFileElement(string &global_init_file);
122 123
  //! Add Paths
  void addPathsConfFileElement(vector<string> &includepath);
124
  //! Add a SlaveNode or a Cluster object
125 126 127
  void addParallelConfFileElement(bool inNode, bool inCluster, member_nodes_t member_nodes, string &name,
                                  string &computerName, string port, int minCpuNbr, int maxCpuNbr, string &userName,
                                  string &password, string &remoteDrive, string &remoteDirectory,
128
                                  string &dynarePath, string &matlabOctavePath, bool singleCompThread, int numberOfThreadsPerJob,
129
                                  string &operatingSystem);
130 131 132 133
public:
  //! Parse config file
  void getConfigFileInfo(const string &parallel_config_file);
  //! Check Pass
134
  void checkPass(WarningConsolidation &warnings) const;
135 136
  //! Check Pass
  void transformPass();
137 138
  //! Get Path Info
  vector<string> getIncludePaths() const;
139 140
  //! Write any hooks
  void writeHooks(ostream &output) const;
141 142 143 144 145 146 147
  //! Create options_.parallel structure, write options
  void writeCluster(ostream &output) const;
  //! Close slave nodes if needed
  void writeEndParallel(ostream &output) const;
};

#endif // ! CONFIG_FILE_HH