79 const std::string&
output,
const unsigned int type,
const bool background,
const size_t timeout)
82 const std::string actual_output = output ==
"" ? Param->getOption<std::string>(OPT_output_temporary_directory) +
85 const std::string script_file_name = Param->getOption<std::string>(OPT_output_temporary_directory) +
88 std::ofstream script_file(script_file_name.c_str());
89 script_file <<
"#!/bin/bash" << std::endl;
92 script_file <<
"if [ ! -z \"$APPDIR\" ]; then\n" 93 <<
" export PATH=$(sed -E 's/\\/tmp\\/.mount[^\\:]+\\://g' <<< $PATH)\n" 94 <<
" export LD_LIBRARY_PATH=$(sed -E 's/\\/tmp\\/.mount[^\\:]+\\://g' <<< $LD_LIBRARY_PATH)\n" 95 <<
" export PERLLIB=$(sed -E 's/\\/tmp\\/.mount[^\\:]+\\://g' <<< $PERLLIB)\n" 98 script_file <<
"ulimit -s 131072" << std::endl;
100 THROW_ASSERT(not background or timeout == 0,
"Background and timeout cannot be specified at the same time");
105 script_file <<
"(" << system_command <<
") ";
112 script_file <<
" > /dev/null 2>&1 ";
117 script_file <<
" 2>/dev/null | tee " << actual_output;
122 script_file <<
" 2>&1 1>/dev/null | tee " << actual_output;
127 script_file <<
" 2>&1 | tee " << actual_output;
142 script_file <<
" > /dev/null 2>&1 ";
147 script_file <<
" 2> /dev/null > " << actual_output;
152 script_file <<
" > /dev/null 2> " << actual_output;
157 script_file <<
" > " << actual_output <<
" 2>&1 ";
168 script_file <<
") &";
170 script_file << std::endl;
173 script_file <<
"exit ${PIPESTATUS[0]}" << std::endl;
178 const std::string timeout_file_name = Param->getOption<std::string>(OPT_output_temporary_directory) +
181 std::ofstream timeout_file(timeout_file_name.c_str());
182 timeout_file <<
"#!/bin/bash" << std::endl;
183 timeout_file <<
"timeout --foreground " <<
STR(timeout) <<
"m bash -f " << script_file_name << std::endl;
184 timeout_file.close();
185 const std::string
command =
"bash -f " + timeout_file_name +
"";
186 return system(command.c_str());
190 const std::string
command =
"bash -f " + script_file_name +
"";
191 return system(command.c_str());
197 const std::regex version_number(
"\\d+(\\.\\d+)*");
198 const auto x = _x.string(), y = _y.string();
200 if(std::regex_search(
x.c_str(), mx, version_number))
202 if(std::regex_search(y.c_str(), my, version_number))
204 const char *px = mx[0].first, *lx;
205 const char *py = my[0].first, *ly;
208 lx = std::find(px, mx[0].second,
'.');
209 ly = std::find(py, my[0].second,
'.');
228 }
while(++px != mx[0].second);
233 else if(std::regex_search(_y.string().c_str(), my, version_number))
240 template <
typename T>
243 static std::random_device rd;
244 static std::mt19937_64 gen(rd());
248 for(i = 0; i < size; ++i, rnd >>=
sizeof(T) * 8)
250 if(i %
sizeof(uint64_t) == 0)
252 arr[i] =
static_cast<T
>(rnd);
294 std::filesystem::path::string_type s(model.native());
296 const char hex[] =
"0123456789abcdef";
297 const char percent =
'%';
299 char ran[] =
"123456789abcdef";
301 const int max_nibbles = 2 *
sizeof(
ran);
303 int nibbles_used = max_nibbles;
304 for(std::filesystem::path::string_type::size_type i = 0; i < s.size(); ++i)
308 if(nibbles_used == max_nibbles)
313 int c = ran[nibbles_used / 2];
314 c >>= 4 * (nibbles_used++ & 1);
File containing functions and utilities to support the printing of debug messagges.
bool NaturalVersionOrder(const std::filesystem::path &_x, const std::filesystem::path &_y)
exceptions managed by PandA
volatile int output[DIM_Y][DIM_X]
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
std::filesystem::path unique_path(const std::filesystem::path &model)
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
#define STR_CST_file_IO_shell_output_file
The file used to store shell output.
constants used in Input/Output
#define STR_CST_file_IO_shell_script
The file used to store the script shell.
utility function used to read files.
fileIO_istreamRef fileIO_istream_open(const std::string &name)
this function returns an istream compressed or not.
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
void array_rand(T *arr, size_t size)
int PandaSystem(const ParameterConstRef Param, const std::string &system_command, bool host_exec, const std::string &output, const unsigned int type, const bool background, const size_t timeout)
System call forcing execution with bash.
#define OUTPUT_LEVEL_PEDANTIC
verbose debugging print is performed.
std::string GetPath(std::filesystem::path path)
TYPE distance(TYPE position_x[nAtoms], TYPE position_y[nAtoms], TYPE position_z[nAtoms], int i, int j)
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
this class is used to manage the command-line or XML options.
std::string GetCurrentPath()
unsigned counter[N_THREADS]
x
Return the smallest n such that 2^n >= _x.
refcount< std::istream > fileIO_istreamRef
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...