1 | def write_config(np_min, np_max, nx_min, nx_max, ny_min, ny_max, nz_min, nz_max, tpn, dnpexnpey, dnpexnpey_tolerance, dnxny, poisfft, switch, |
---|
2 | temperton, mlt_grid, spectr, rslt_thrs, ld_thrs): |
---|
3 | #from configparser import ConfigParser # windows |
---|
4 | from ConfigParser import ConfigParser # Linux |
---|
5 | |
---|
6 | # if __name__ == "__main__": |
---|
7 | cfg = ConfigParser() |
---|
8 | |
---|
9 | import os.path |
---|
10 | if os.path.exists('.palm_gf_conf') is False: |
---|
11 | cfg.add_section("processor_topology") |
---|
12 | cfg.add_section("numerical_grid") |
---|
13 | cfg.add_section("method") |
---|
14 | |
---|
15 | #cfg.add_section("processor_topology") |
---|
16 | cfg.set("processor_topology", "np_min", np_min) |
---|
17 | cfg.set("processor_topology", "np_max", np_max) |
---|
18 | cfg.set("processor_topology", "tasks_per_node", tpn) |
---|
19 | cfg.set("processor_topology", "dnpexnpey", dnpexnpey) |
---|
20 | cfg.set("processor_topology", "dnpexnpey_tolerance", dnpexnpey_tolerance) |
---|
21 | cfg.set("processor_topology", "dnxny", dnxny) |
---|
22 | |
---|
23 | #cfgadd_section("numerical_grid"). |
---|
24 | cfg.set("numerical_grid", "nx_min", nx_min) |
---|
25 | cfg.set("numerical_grid", "nx_max", nx_max) |
---|
26 | cfg.set("numerical_grid", "ny_min", ny_min) |
---|
27 | cfg.set("numerical_grid", "ny_max", ny_max) |
---|
28 | cfg.set("numerical_grid", "nz_min", nz_min) |
---|
29 | cfg.set("numerical_grid", "nz_max", nz_max) |
---|
30 | |
---|
31 | #cfg.add_section("method") |
---|
32 | cfg.set("method", "poisfft", poisfft) |
---|
33 | cfg.set("method", "switch", switch) |
---|
34 | cfg.set("method", "temperton", temperton) |
---|
35 | cfg.set("method", "mlt_grid", mlt_grid) |
---|
36 | cfg.set("method", "spectr", spectr) |
---|
37 | |
---|
38 | #cfg.add_section("settings") |
---|
39 | #cfg.set("settings", "path", path) |
---|
40 | #cfg.set("settings", "result_threshold", rslt_thrs) |
---|
41 | #cfg.set("settings", "load_threshold", ld_thrs) |
---|
42 | |
---|
43 | |
---|
44 | with open(".palm_gf_config", "a") as configfile: |
---|
45 | cfg.write(configfile) |
---|
46 | |
---|
47 | |
---|
48 | def read_config(): |
---|
49 | #from configparser import ConfigParser # windows |
---|
50 | from ConfigParser import ConfigParser # Linux |
---|
51 | |
---|
52 | |
---|
53 | cfg = ConfigParser() |
---|
54 | |
---|
55 | cfg.read(".palm_gf_config") |
---|
56 | np_min = cfg.get("processor_topology", "np_min") |
---|
57 | np_max = cfg.get("processor_topology", "np_max") |
---|
58 | tpn = cfg.get("processor_topology", "tasks_per_node") |
---|
59 | dnpexnpey = cfg.get("processor_topology", "dnpexnpey") |
---|
60 | dnpexnpey_tolerance = cfg.get("processor_topology", "dnpexnpey_tolerance") |
---|
61 | dnxny = cfg.get("processor_topology", "dnxny") |
---|
62 | |
---|
63 | nx_min = cfg.get("numerical_grid", "nx_min") |
---|
64 | nx_max = cfg.get("numerical_grid", "nx_max") |
---|
65 | ny_min = cfg.get("numerical_grid", "ny_min") |
---|
66 | ny_max = cfg.get("numerical_grid", "ny_max") |
---|
67 | nz_min = cfg.get("numerical_grid", "nz_min") |
---|
68 | nz_max = cfg.get("numerical_grid", "nz_max") |
---|
69 | |
---|
70 | poisfft = cfg.get("method", "poisfft") |
---|
71 | switch = cfg.get("method", "switch") |
---|
72 | temperton = cfg.get("method", "temperton") |
---|
73 | mlt_grid = cfg.get("method", "mlt_grid") |
---|
74 | spectr = cfg.get("method", "spectr") |
---|
75 | |
---|
76 | import ConfigParser as conf |
---|
77 | try: |
---|
78 | result_threshold = cfg.get("settings", "result_threshold") |
---|
79 | load_threshold = cfg.get("settings", "load_threshold") |
---|
80 | path = cfg.get("settings", 'path') |
---|
81 | |
---|
82 | except conf.NoSectionError: |
---|
83 | |
---|
84 | path = '/localdata/' |
---|
85 | result_threshold = 250000 |
---|
86 | load_threshold = 100000 |
---|
87 | |
---|
88 | return np_min, np_max, tpn, dnpexnpey, dnpexnpey_tolerance, dnxny, nx_min, nx_max, ny_min, ny_max, nz_min, nz_max, poisfft, switch, temperton, mlt_grid, spectr, result_threshold, load_threshold, path |
---|
89 | |
---|
90 | |
---|
91 | def write_config_settings(path, rslt_thrs, ld_thrs): |
---|
92 | |
---|
93 | from ConfigParser import ConfigParser |
---|
94 | |
---|
95 | cfg = ConfigParser() |
---|
96 | |
---|
97 | cfg.add_section('settings') |
---|
98 | |
---|
99 | cfg.set('settings', 'path', path) |
---|
100 | cfg.set('settings', "result_threshold", rslt_thrs) |
---|
101 | cfg.set('settings', "load_threshold", ld_thrs) |
---|
102 | |
---|
103 | with open(".palm_gf_config", "a") as configfile: |
---|
104 | cfg.write(configfile) |
---|
105 | |
---|
106 | |
---|
107 | def read_config_settings(): |
---|
108 | |
---|
109 | from ConfigParser import ConfigParser |
---|
110 | import ConfigParser as con |
---|
111 | |
---|
112 | cfg = ConfigParser() |
---|
113 | cfg.read(".palm_gf_config") |
---|
114 | |
---|
115 | try: |
---|
116 | path = cfg.get("settings", "path") |
---|
117 | result_thrs = cfg.get("settings", "result_threshold") |
---|
118 | load_thrs = cfg.get("settings", "load_threshold") |
---|
119 | |
---|
120 | except con.NoSectionError: |
---|
121 | |
---|
122 | path = '/localdata/' |
---|
123 | result_thrs = 250000 |
---|
124 | load_thrs = 100000 |
---|
125 | |
---|
126 | except con.NoOptionError: |
---|
127 | |
---|
128 | path = '/localdata/' |
---|
129 | result_thrs = 250000 |
---|
130 | load_thrs = 100000 |
---|
131 | |
---|
132 | #print path, result_thrs, load_thrs |
---|
133 | |
---|
134 | return path, result_thrs, load_thrs |
---|
135 | |
---|
136 | |
---|
137 | # *********************************************** |
---|
138 | |
---|
139 | |
---|
140 | def closing_cleanup(): |
---|
141 | from ConfigParser import ConfigParser # Linux |
---|
142 | import ConfigParser as conf |
---|
143 | import os, shutil, time |
---|
144 | |
---|
145 | cfg = ConfigParser() |
---|
146 | |
---|
147 | try: |
---|
148 | |
---|
149 | cfg.read(".palm_gf_config") |
---|
150 | np_min = cfg.get("processor_topology", "np_min") |
---|
151 | np_max = cfg.get("processor_topology", "np_max") |
---|
152 | tpn = cfg.get("processor_topology", "tasks_per_node") |
---|
153 | dnpexnpey = cfg.get("processor_topology", "dnpexnpey") |
---|
154 | dnpexnpey_tolerance = cfg.get("processor_topology", "dnpexnpey_tolerance") |
---|
155 | dnxny = cfg.get("processor_topology", "dnxny") |
---|
156 | |
---|
157 | nx_min = cfg.get("numerical_grid", "nx_min") |
---|
158 | nx_max = cfg.get("numerical_grid", "nx_max") |
---|
159 | ny_min = cfg.get("numerical_grid", "ny_min") |
---|
160 | ny_max = cfg.get("numerical_grid", "ny_max") |
---|
161 | nz_min = cfg.get("numerical_grid", "nz_min") |
---|
162 | nz_max = cfg.get("numerical_grid", "nz_max") |
---|
163 | |
---|
164 | poisfft = cfg.get("method", "poisfft") |
---|
165 | switch = cfg.get("method", "switch") |
---|
166 | temperton = cfg.get("method", "temperton") |
---|
167 | mlt_grid = cfg.get("method", "mlt_grid") |
---|
168 | spectr = cfg.get("method", "spectr") |
---|
169 | |
---|
170 | var1_bool = True |
---|
171 | |
---|
172 | except conf.NoSectionError: |
---|
173 | np_min = 0 |
---|
174 | np_max = 0 |
---|
175 | tpn = 0 |
---|
176 | dnpexnpey = 0 |
---|
177 | dnpexnpey_tolerance = 0 |
---|
178 | dnxny = 0 |
---|
179 | |
---|
180 | nx_min = 0 |
---|
181 | nx_max = 0 |
---|
182 | ny_min = 0 |
---|
183 | ny_max = 0 |
---|
184 | nz_min = 0 |
---|
185 | nz_max = 0 |
---|
186 | |
---|
187 | poisfft = False |
---|
188 | switch = False |
---|
189 | temperton = False |
---|
190 | mlt_grid = False |
---|
191 | spectr = False |
---|
192 | var1_bool = False |
---|
193 | |
---|
194 | with open(".palm_gf_config", "w") as configfile: |
---|
195 | cfg.write(configfile) |
---|
196 | |
---|
197 | try: |
---|
198 | cfg.read(".palm_gf_config") |
---|
199 | rslt_thrs = cfg.get("settings", "result_threshold") |
---|
200 | ld_thrs = cfg.get("settings", "load_threshold") |
---|
201 | path = cfg.get("settings", 'path') |
---|
202 | |
---|
203 | var2_bool = True |
---|
204 | |
---|
205 | except conf.NoSectionError: |
---|
206 | |
---|
207 | path = '/localdata/' |
---|
208 | rslt_thrs = 250000 |
---|
209 | ld_thrs = 100000 |
---|
210 | |
---|
211 | var2_bool = False |
---|
212 | |
---|
213 | |
---|
214 | |
---|
215 | with open(".palm_gf_config", "w") as configfile: |
---|
216 | cfg.write(configfile) |
---|
217 | |
---|
218 | |
---|
219 | |
---|
220 | #os.remove('.palm_gf_config') |
---|
221 | |
---|
222 | |
---|
223 | |
---|
224 | try: |
---|
225 | cfg.set("processor_topology", "np_min", np_min) |
---|
226 | cfg.set("processor_topology", "np_max", np_max) |
---|
227 | cfg.set("processor_topology", "tasks_per_node", tpn) |
---|
228 | cfg.set("processor_topology", "dnpexnpey", dnpexnpey) |
---|
229 | cfg.set("processor_topology", "dnpexnpey_tolerance", dnpexnpey_tolerance) |
---|
230 | cfg.set("processor_topology", "dnxny", dnxny) |
---|
231 | |
---|
232 | |
---|
233 | cfg.set("numerical_grid", "nx_min", nx_min) |
---|
234 | cfg.set("numerical_grid", "nx_max", nx_max) |
---|
235 | cfg.set("numerical_grid", "ny_min", ny_min) |
---|
236 | cfg.set("numerical_grid", "ny_max", ny_max) |
---|
237 | cfg.set("numerical_grid", "nz_min", nz_min) |
---|
238 | cfg.set("numerical_grid", "nz_max", nz_max) |
---|
239 | |
---|
240 | |
---|
241 | cfg.set("method", "poisfft", poisfft) |
---|
242 | cfg.set("method", "switch", switch) |
---|
243 | cfg.set("method", "temperton", temperton) |
---|
244 | cfg.set("method", "mlt_grid", mlt_grid) |
---|
245 | cfg.set("method", "spectr", spectr) |
---|
246 | |
---|
247 | except conf.NoSectionError: |
---|
248 | cfg.add_section("processor_topology") |
---|
249 | cfg.set("processor_topology", "np_min", np_min) |
---|
250 | cfg.set("processor_topology", "np_max", np_max) |
---|
251 | cfg.set("processor_topology", "tasks_per_node", tpn) |
---|
252 | cfg.set("processor_topology", "dnpexnpey", dnpexnpey) |
---|
253 | cfg.set("processor_topology", "dnpexnpey_tolerance", dnpexnpey_tolerance) |
---|
254 | cfg.set("processor_topology", "dnxny", dnxny) |
---|
255 | |
---|
256 | cfg.add_section("numerical_grid") |
---|
257 | cfg.set("numerical_grid", "nx_min", nx_min) |
---|
258 | cfg.set("numerical_grid", "nx_max", nx_max) |
---|
259 | cfg.set("numerical_grid", "ny_min", ny_min) |
---|
260 | cfg.set("numerical_grid", "ny_max", ny_max) |
---|
261 | cfg.set("numerical_grid", "nz_min", nz_min) |
---|
262 | cfg.set("numerical_grid", "nz_max", nz_max) |
---|
263 | |
---|
264 | cfg.add_section("method") |
---|
265 | cfg.set("method", "poisfft", poisfft) |
---|
266 | cfg.set("method", "switch", switch) |
---|
267 | cfg.set("method", "temperton", temperton) |
---|
268 | cfg.set("method", "mlt_grid", mlt_grid) |
---|
269 | cfg.set("method", "spectr", spectr) |
---|
270 | |
---|
271 | |
---|
272 | try: |
---|
273 | cfg.set("settings", "path", path) |
---|
274 | cfg.set("settings", "result_threshold", rslt_thrs) |
---|
275 | cfg.set("settings", "load_threshold", ld_thrs) |
---|
276 | |
---|
277 | except conf.NoSectionError: |
---|
278 | cfg.add_section("settings") |
---|
279 | cfg.set("settings", "path", path) |
---|
280 | cfg.set("settings", "result_threshold", rslt_thrs) |
---|
281 | cfg.set("settings", "load_threshold", ld_thrs) |
---|
282 | |
---|
283 | |
---|
284 | |
---|
285 | |
---|
286 | |
---|
287 | |
---|
288 | with open(".palm_gf_config", "w") as configfile: |
---|
289 | cfg.write(configfile) |
---|
290 | |
---|