AFLOW
 
Loading...
Searching...
No Matches
aflow_xhost.cpp
Go to the documentation of this file.
1// ***************************************************************************
2// * *
3// * Aflow STEFANO CURTAROLO - Duke University 2003-2024 *
4// * *
5// ***************************************************************************
6
7#include "aflow_xhost.h"
8
9#include <cstddef>
10#include <string>
11#include <vector>
12
13#include <pthread.h>
14
15#include "AUROSTD/aurostd.h"
19
20using std::string;
21using std::vector;
22
23// ***************************************************************************
24// ***************************************************************************
25// _XHOST
26// look into aflow.h for the definitions
27// constructors
28
29_XHOST::_XHOST() { // constructor PUBLIC
30 PID = 0;
31 TID = 0; // CO20200502 - threadID
32 ostrPID.clear();
33 ostrPID.str(string(""));
34 ostrTID.clear();
35 ostrTID.str(string("")); // CO20200502 - threadID
36 sPID = "";
37 sTID = "";
38 showPID = false;
39 showTID = false;
40 QUIET = false;
41 QUIET_GLOBAL = false; // CO20220630
42 QUIET_CERR = false; // extra quiet SC20210617
43 QUIET_COUT = false; // extra quiet SC20210617
44 LOGGER_WHITELIST.clear(); // HE+ME20220305
45 LOGGER_BLACKLIST.clear(); // HE+ME20220305
46 TEST = false;
47 DEBUG = false;
48 MPI = false;
49 GENERATE_AFLOWIN_ONLY = false; // CT20180719
50 POSTPROCESS = false; // CO20200624
51 ARUN_POSTPROCESS = false; // CT20181212
52 AVOID_RUNNING_VASP = false; // CO20200624
53 PSEUDOPOTENTIAL_GENERATOR = false; // SC20200327
54 hostname = "";
55 machine_type = "";
56 tmpfs = "";
57 user = "";
58 group = "";
59 home = "";
60 shell = "";
61 progname = "aflow";
62 Find_Parameters = "";
63 sensors_allowed = true;
64 argv.clear();
67 RAM = 0.0;
68 RAM_MB = 0.0;
69 RAM_GB = 0.0;
70 CPU_Cores = 0;
71 CPU_active = 1; // ME20220130 - count main thread
72 CPU_Model = "";
73 CPU_MHz = "";
74 vTemperatureCore.clear();
75 Time_starting = 0.0;
76 Time_now = 0.0;
77 Date = 0;
78 Day = "";
79 Month = "";
80 Year = "";
81 Copyright_Years = "";
82 // PTHREADS_FLAG=false;
83 // PTHREADS_MAX=0;
84 // PTHREADS_RUNNING=0;
85 // thread.clear();
86 // iret.clear();
87 // thread_busy.clear();
88 vcmd.clear();
89 maxmem = 100.00;
90 AFLOW_RUNDIRflag = false;
91 AFLOW_MULTIflag = false;
92 AFLOW_RUNXflag = false;
94 is_PBS = false;
95 PBS_NUM_PPN = 0;
96 PBS_NNODES = 0;
97 is_SLURM = false;
99 SLURM_NNODES = 0;
100 SLURM_NTASKS = 0;
102 vGlobal_uint.clear();
103 for (uint i = 0; i < XHOST_vGlobal_MAX; i++) {
104 vGlobal_uint.push_back(0);
105 }
106 vGlobal_string.clear();
107 for (uint i = 0; i < XHOST_vGlobal_MAX; i++) {
108 vGlobal_string.emplace_back("");
109 }
110 vvGlobal_string.clear();
111 for (uint i = 0; i < XHOST_vGlobal_MAX; i++) {
112 vvGlobal_string.emplace_back();
113 }
114 vvLIBS.clear();
115 for (uint i = 0; i < XHOST_vGlobal_MAX; i++) {
116 vvLIBS.emplace_back();
117 }
118 vflag_aflow.clear();
119 vflag_pflow.clear();
120 vflag_outreach.clear();
121 vflag_control.clear();
122 vschema.clear();
123 vschema_internal.clear(); // ME20220208
135 XHOST_vLibrary_ICSD.clear();
136 for (uint i = 0; i < XHOST_vGlobal_MAX; i++) {
137 XHOST_vLibrary_ICSD.emplace_back(""); // needs some initialization
138 }
139 // extensions
140 vcat.clear();
141 vcat.emplace_back("cat");
142 vcat.emplace_back("bzcat");
143 vcat.emplace_back("xzcat");
144 vcat.emplace_back("gzcat");
145 vext.clear();
146 vext.emplace_back("");
147 vext.emplace_back(".bz2");
148 vext.emplace_back(".xz");
149 vext.emplace_back(".gz");
150 vzip.clear();
151 vzip.emplace_back("");
152 vzip.emplace_back("bzip2");
153 vzip.emplace_back("xz");
154 vzip.emplace_back("gzip");
155 // AFLOWRC
156 aflowrc_filename = ""; // AFLOWRC
157 aflowrc_content = ""; // AFLOWRC
158 vaflowrc.clear(); // AFLOWRC
159 adefault.clear(); // AFLOWRC
160 // AFLOWSYM
161 SKEW_TEST = false; // DX20171019
162 SKEW_TOL = AUROSTD_NAN; // DX20171019
163 // xstructure
164 READ_SPIN_FROM_ATOMLABEL = false; // SD20220316 - spin and pp label can conflict with one another
165 // WEB
166 //[CO20200404 - overload with --www]WEB_MODE=false; //CO20190402
167};
168
169_XHOST::~_XHOST() { // destructor PUBLIC
170 free();
171}
172
173void _XHOST::copy(const _XHOST& b) { // copy PRIVATE
174 PID = b.PID;
175 TID = b.TID; // CO20200502 - threadID
176 ostrPID.clear();
177 ostrPID.str(string(""));
178 ostrPID << b.ostrPID.str();
179 ostrTID.clear();
180 ostrTID.str(string(""));
181 ostrTID << b.ostrTID.str(); // CO20200502 - threadID
182 sPID = b.sPID;
183 sTID = b.sTID;
184 showPID = b.showPID;
185 showTID = b.showTID;
186 QUIET = b.QUIET;
187 QUIET_GLOBAL = b.QUIET_GLOBAL; // CO20220630
188 QUIET_CERR = b.QUIET_CERR; // extra quiet SC20210617
189 QUIET_COUT = b.QUIET_COUT; // extra quiet SC20210617
190 LOGGER_WHITELIST = b.LOGGER_WHITELIST; // HE+ME20220305
191 LOGGER_BLACKLIST = b.LOGGER_BLACKLIST; // HE+ME20220305
192 TEST = b.TEST;
193 DEBUG = b.DEBUG;
194 MPI = b.MPI;
196 POSTPROCESS = b.POSTPROCESS; // CO20200624
197 ARUN_POSTPROCESS = b.ARUN_POSTPROCESS; // CT20181212
198 AVOID_RUNNING_VASP = b.AVOID_RUNNING_VASP; // CO20200624
200 hostname = b.hostname;
202 tmpfs = b.tmpfs;
203 user = b.user;
204 group = b.group;
205 home = b.home;
206 progname = b.progname;
209 argv.clear();
210 for (size_t i = 0; i < b.argv.size(); i++) {
211 argv.push_back(b.argv[i]);
212 }
215 RAM = b.RAM;
216 RAM_MB = b.RAM_MB;
217 RAM_GB = b.RAM_GB;
219 CPU_active = b.CPU_active; // ME20220130
221 CPU_MHz = b.CPU_MHz;
222 vTemperatureCore.clear();
223 for (size_t i = 0; i < b.vTemperatureCore.size(); i++) {
224 vTemperatureCore.push_back(b.vTemperatureCore[i]);
225 }
227 Time_now = b.Time_now;
228 Date = b.Date;
229 Day = b.Day;
230 Month = b.Month;
231 Year = b.Year;
233 // PTHREADS_FLAG=b.PTHREADS_FLAG;
234 // PTHREADS_MAX=b.PTHREADS_MAX;
235 // PTHREADS_RUNNING=b.PTHREADS_RUNNING;
236 // thread.clear();for(size_t i=0;i<b.thread.size();i++) thread.push_back(b.thread.at(i));
237 // iret.clear();for(size_t i=0;i<b.iret.size();i++) iret.push_back(b.iret.at(i));
238 // thread_busy.clear();for(size_t i=0;i<b.thread.size();i++) thread.push_back(b.thread.at(i));
239 vcmd.clear();
240 for (size_t i = 0; i < b.vcmd.size(); i++) {
241 vcmd.push_back(b.vcmd[i]);
242 }
243 maxmem = b.maxmem;
248 is_PBS = b.is_PBS;
251 is_SLURM = b.is_SLURM;
256 vGlobal_uint.clear();
257 for (size_t i = 0; i < b.vGlobal_uint.size(); i++) {
258 vGlobal_uint.push_back(b.vGlobal_uint[i]);
259 }
260 vGlobal_string.clear();
261 for (size_t i = 0; i < b.vGlobal_string.size(); i++) {
262 vGlobal_string.push_back(b.vGlobal_string[i]);
263 }
264 vvGlobal_string.clear();
265 for (size_t i = 0; i < b.vvGlobal_string.size(); i++) {
266 vvGlobal_string.push_back(b.vvGlobal_string[i]);
267 }
268 vvLIBS.clear();
269 for (size_t i = 0; i < b.vvLIBS.size(); i++) {
270 vvLIBS.push_back(b.vvLIBS[i]);
271 }
276 vschema = b.vschema;
277 vschema_internal = b.vschema_internal; // ME20220208
278 // extensions
279 vcat.clear();
280 for (size_t i = 0; i < b.vcat.size(); i++) {
281 vcat.push_back(b.vcat[i]);
282 }
283 vext.clear();
284 for (size_t i = 0; i < b.vext.size(); i++) {
285 vext.push_back(b.vext[i]);
286 }
287 vzip.clear();
288 for (size_t i = 0; i < b.vzip.size(); i++) {
289 vzip.push_back(b.vzip[i]);
290 }
291 // AFLOWRC
292 aflowrc_filename = b.aflowrc_filename; // AFLOWRC
293 aflowrc_content = b.aflowrc_content; // AFLOWRC
294 vaflowrc.clear();
295 for (size_t i = 0; i < b.vaflowrc.size(); i++) {
296 vaflowrc.push_back(b.vaflowrc[i]); // AFLOWRC
297 }
298 adefault.clear();
299 adefault = b.adefault; // AFLOWRC
300 // AFLOWSYM
301 SKEW_TEST = b.SKEW_TEST; // DX20171019
302 SKEW_TOL = b.SKEW_TOL; // DX20171019
303 // xstructure
305 // WEB
306 //[CO20200404 - overload with --www]WEB_MODE=b.WEB_MODE; //CO20190402
307}
308
309const _XHOST& _XHOST::operator=(const _XHOST& b) { // operator= PUBLIC
310 if (this != &b) {
311 free();
312 copy(b);
313 }
314 return *this;
315}
316
317//_XHOST::_XHOST(const _XHOST& b) { // copy PUBLIC
319// copy(b);
320// }
321
322void _XHOST::free() { // free PRIVATE
323 ostrPID.clear();
324 ostrPID.str(string(""));
325 ostrTID.clear();
326 ostrTID.str(string("")); // CO20200502 - threadID
327 vTemperatureCore.clear();
328 // thread.clear();
329 // iret.clear();
330 // thread_busy.clear();
331 vcmd.clear();
332 vGlobal_uint.clear();
333 for (uint i = 0; i < XHOST_vGlobal_MAX; i++) {
334 vGlobal_uint.push_back(0);
335 }
336 vGlobal_string.clear();
337 for (uint i = 0; i < XHOST_vGlobal_MAX; i++) {
338 vGlobal_string.emplace_back("");
339 }
340 vvGlobal_string.clear();
341 for (uint i = 0; i < XHOST_vGlobal_MAX; i++) {
342 vvGlobal_string.emplace_back();
343 }
344 vvLIBS.clear();
345 for (uint i = 0; i < XHOST_vGlobal_MAX; i++) {
346 vvLIBS.emplace_back();
347 }
348 XHOST_vLibrary_ICSD.clear();
349 for (uint i = 0; i < XHOST_vGlobal_MAX; i++) {
350 XHOST_vLibrary_ICSD.emplace_back(""); // needs some initialization
351 }
352 vflag_aflow.clear();
353 vflag_pflow.clear();
354 vflag_outreach.clear();
355 vflag_control.clear();
356 vschema.clear();
357 vschema_internal.clear(); // ME20220208
358 // extensions
359 vcat.clear();
360 vcat.emplace_back("cat");
361 vcat.emplace_back("bzcat");
362 vcat.emplace_back("xzcat");
363 vcat.emplace_back("gzcat");
364 vext.clear();
365 vext.emplace_back("");
366 vext.emplace_back(".bz2");
367 vext.emplace_back(".xz");
368 vext.emplace_back(".gz");
369 vzip.clear();
370 vzip.emplace_back("");
371 vzip.emplace_back("bzip2");
372 vzip.emplace_back("xz");
373 vzip.emplace_back("gzip");
374 // AFLOWRC
375 aflowrc_filename.clear(); // AFLOWRC
376 aflowrc_content.clear(); // AFLOWRC
377 vaflowrc.clear(); // AFLOWRC
378 adefault.clear(); // AFLOWRC
379}
380
381void _XHOST::clear() { // clear PRIVATE
382 _XHOST const XHOST_temp;
383 copy(XHOST_temp);
384}
385
386// other public functions of XHOST
387
388pthread_mutex_t mutex_XAFLOW_XHOST = PTHREAD_MUTEX_INITIALIZER;
389
390std::string _XHOST::command(const string& command) {
391 string _command = command;
392#ifdef _MACOSX_
393 if (command == "beep") return string("echo -ne '\007'");
394#endif
395 // first check for EXACT match in vcmds //CO20180705
396 if (command == "aflow_data" && aurostd::FileExist("./aflow_data")) {
397 return "./aflow_data";
398 } // CO20180705 - hack for developers, prefer ./aflow_data over aflow_data in PATH, as it is probably newer (development)
399 for (size_t i = 0; i < vcmd.size(); i++) {
400 if (vcmd[i] == command) {
401 return vcmd[i];
402 }// found before.. only == otherwise cat gets confused with bzcat
403 }
404 // next check if we can find the command in PATH or somewher else common //CO20180705
405 if (aurostd::IsCommandAvailableModify(_command)) {
406 pthread_mutex_lock(&mutex_XAFLOW_XHOST);
407 // pthread_mutex_unlock(&mutex_XAFLOW_XHOST);
408 vcmd.push_back(_command);
409 pthread_mutex_unlock(&mutex_XAFLOW_XHOST);
410 return _command;
411 } // found and added
412 // CO20180705 START
413 // requested command is "aflow_data", and we have ./aflow_data in our vcmd's
414 // we need to strip vcmd's to basename and check
415 vector<string> path_parts;
416 string basename;
417 for (size_t i = 0; i < vcmd.size(); i++) {
418 aurostd::string2tokens(vcmd[i], path_parts, "/", true); // consecutive
419 if (!path_parts.empty()) {
420 basename = path_parts[path_parts.size() - 1];
421 if (basename == command) {
422 return vcmd[i];
423 }
424 }
425 }
426 // CO20180705 STOP
427 throw aurostd::xerror(__AFLOW_FILE__, __AFLOW_FUNC__, "command=" + command + " not found", _INPUT_MISSING_);
428 return string();
429}
430
431bool _XHOST::is_command(const string& command) {
432 try {
433 const string path = _XHOST::command(command);
434 return !path.empty();
435 } // CO20190629 - using xerror now
436 catch (aurostd::xerror& excpt) {
437 return false;
438 } // CO20190629 - using xerror now
439 //[CO20190629 - using xerror now]return !_XHOST::command(command).empty(); //CO20180705
440}
pthread_mutex_t mutex_XAFLOW_XHOST
#define XHOST_LIBRARY_LIB2
Definition aflow_xhost.h:91
#define XHOST_LIBRARY_LIB3
Definition aflow_xhost.h:92
#define XHOST_LIBRARY_LIB0
Definition aflow_xhost.h:89
#define XHOST_LIBRARY_LIB9
Definition aflow_xhost.h:98
#define XHOST_LIBRARY_LIB1
Definition aflow_xhost.h:90
#define XHOST_LIBRARY_ICSD
Definition aflow_xhost.h:99
#define XHOST_vLibrary_ICSD
Definition aflow_xhost.h:48
#define XHOST_LIBRARY_LIB8
Definition aflow_xhost.h:97
#define XHOST_LIBRARY_LIB7
Definition aflow_xhost.h:96
#define XHOST_LIBRARY_LIB5
Definition aflow_xhost.h:94
#define XHOST_LIBRARY_LIB6
Definition aflow_xhost.h:95
#define XHOST_LIBRARY_LIB4
Definition aflow_xhost.h:93
#define XHOST_vGlobal_MAX
Definition aflow_xhost.h:21
unsigned uint
Definition aurostd.h:39
#define __AFLOW_FILE__
Definition aurostd.h:44
#define __AFLOW_FUNC__
Definition aurostd.h:43
#define AUROSTD_NAN
#define LIBRARY_NOTHING
#define _INPUT_MISSING_
std::vector< uint > vGlobal_uint
bool AVOID_RUNNING_VASP
std::vector< std::string > vaflowrc
std::string group
std::vector< double > vTemperatureCore
std::vector< std::vector< std::string > > vvLIBS
std::string aflowrc_filename
std::string hostname
std::string aflowrc_content
bool QUIET_CERR
int PBS_NNODES
std::string user
double SKEW_TOL
int CPU_Cores
const _XHOST & operator=(const _XHOST &b)
bool READ_SPIN_FROM_ATOMLABEL
std::vector< std::string > LOGGER_WHITELIST
std::vector< std::vector< std::string > > vvGlobal_string
std::vector< std::string > argv
std::ostringstream ostrPID
std::string sPID
uint AFLOW_RUNXnumber
std::string shell
std::string command(const std::string &command)
bool QUIET_GLOBAL
std::string Day
bool AFLOW_RUNXflag
bool is_SLURM
void copy(const _XHOST &b)
int SLURM_NTASKS
bool ARUN_POSTPROCESS
std::vector< std::string > vzip
long int Date
std::string progname
aurostd::xoption adefault
aurostd::xoption vflag_aflow
bool is_command(const std::string &command)
bool sensors_allowed
std::string Month
bool PSEUDOPOTENTIAL_GENERATOR
aurostd::xoption vflag_outreach
bool GENERATE_AFLOWIN_ONLY
std::vector< std::string > LOGGER_BLACKLIST
std::ostringstream ostrTID
int PBS_NUM_PPN
long double RAM_MB
bool POSTPROCESS
std::string AFLOW_MATERIALS_SERVER
int SLURM_CPUS_ON_NODE
aurostd::xoption vschema
std::string Find_Parameters
std::string home
int CPU_active
std::string sTID
aurostd::xoption vschema_internal
long double RAM
bool showTID
aurostd::xoption vflag_control
long double Time_starting
void free()
bool SKEW_TEST
std::string Copyright_Years
std::vector< std::string > vext
bool is_PBS
std::string CPU_MHz
bool DEBUG
bool AFLOW_MULTIflag
std::string machine_type
std::string Year
std::string tmpfs
long double RAM_GB
std::string AFLOW_WEB_SERVER
double maxmem
bool MPI
std::string CPU_Model
aurostd::xoption vflag_pflow
std::vector< std::string > vGlobal_string
long double Time_now
bool QUIET_COUT
int SLURM_NNODES
void clear()
std::vector< std::string > vcat
bool QUIET
bool showPID
bool is_MACHINE_FULTON_MARYLOU
bool TEST
std::vector< std::string > vcmd
bool AFLOW_RUNDIRflag
uint string2tokens(const string &str, vector< string > &tokens, const string &delimiters=" ", bool consecutive=false) __xprototype
bool IsCommandAvailableModify(string &command)
bool FileExist(const string &FileName)
check if file exists