From 8698e7feeb82a8681b10acade7840b9ff8043505 Mon Sep 17 00:00:00 2001 From: Thomas Witkowski <thomas.witkowski@gmx.de> Date: Tue, 7 Jun 2011 07:01:27 +0000 Subject: [PATCH] Initfiles in AMDiS code style. --- AMDiS/src/Initfile.cc | 287 +++++++------ AMDiS/src/Initfile.h | 855 +++++++++++++++++++++----------------- AMDiS/src/UmfPackSolver.h | 12 +- 3 files changed, 636 insertions(+), 518 deletions(-) diff --git a/AMDiS/src/Initfile.cc b/AMDiS/src/Initfile.cc index faf6a14b..595795aa 100644 --- a/AMDiS/src/Initfile.cc +++ b/AMDiS/src/Initfile.cc @@ -8,153 +8,164 @@ using namespace std; namespace AMDiS { -/// the small parser for the initfile. see description of read(Initfile&, istream&) -struct Parser { - Parser(const string& line) { - size_t pos= line.find(':'); - if (pos == string::npos) - throw runtime_error("cannot find the delimiter ':' in line '"+line+"'"); - name= line.substr(0, pos); - value= line.substr(pos+1, line.length() - (pos + 1)); - // remove everything after the % - pos= value.find('%'); - if (pos != string::npos) { - value= value.substr(0, pos); - } - } - string name; - string value; -}; - -Initfile* Initfile::singlett= NULL; -std::set< std::string > Initfile::fn_include_list; - -/// initialize singleton object an global parameters -void Initfile::init(std::string in) { - initIntern(); - singlett->clear(); - fn_include_list.clear(); - singlett->read(in); - - singlett->getInternalParameters(); + /// the small parser for the initfile. see description of read(Initfile&, istream&) + struct Parser { + Parser(const string& line) + { + size_t pos = line.find(':'); + if (pos == string::npos) + throw runtime_error("cannot find the delimiter ':' in line '" + line + "'"); + name = line.substr(0, pos); + value = line.substr(pos + 1, line.length() - (pos + 1)); + + // remove everything after the % + pos = value.find('%'); + if (pos != string::npos) + value = value.substr(0, pos); + } + string name; + string value; + }; + + Initfile* Initfile::singlett= NULL; + std::set<std::string> Initfile::fn_include_list; + + + /// initialize singleton object an global parameters + void Initfile::init(std::string in) + { + initIntern(); + singlett->clear(); + fn_include_list.clear(); + singlett->read(in); + singlett->getInternalParameters(); - // initialize global strcutures using parameters - Global::init(); -}; - -/// Fill an initfile from a file with filename fn -void Initfile::read(std::string fn) { -// read file if its not parsed already - if (fn_include_list.find(fn)==fn_include_list.end()) { - std::ifstream inputFile; - inputFile.open(fn.c_str(), std::ios::in); - if (!inputFile.is_open()) - throw runtime_error("init-file cannot be opened for reading"); + // initialize global strcutures using parameters + Global::init(); + } + + + /// Fill an initfile from a file with filename fn + void Initfile::read(std::string fn) + { + // read file if its not parsed already + if (fn_include_list.find(fn) == fn_include_list.end()) { + std::ifstream inputFile; + inputFile.open(fn.c_str(), std::ios::in); + if (!inputFile.is_open()) + throw runtime_error("init-file cannot be opened for reading"); - fn_include_list.insert(fn); - read(inputFile); - } -}; - -/// Fill an initfile from an input stream -void Initfile::read(istream& in) { - unsigned line_length= 256; - char swap[line_length]; - in.getline(swap, line_length); - while (in.good()) { - std::string whitespaces= " \t\r\f"; - std::string sw(swap); - size_t pos0= sw.find_first_not_of(whitespaces); + fn_include_list.insert(fn); + read(inputFile); + } + } + + + /// Fill an initfile from an input stream + void Initfile::read(istream& in) + { + unsigned line_length = 256; + char swap[line_length]; + in.getline(swap, line_length); + while (in.good()) { + std::string whitespaces = " \t\r\f"; + std::string sw(swap); + size_t pos0 = sw.find_first_not_of(whitespaces); - if (pos0!=std::string::npos && sw[pos0]!='%' && sw[pos0]!='#' && sw[pos0]!=0) { - // parse line and extract map: tag->value - Parser parser(sw); - operator[](parser.name)= parser.value; - } else if (sw[pos0]=='#' && static_cast<size_t>(sw.find("#include"))==pos0) { - // include file by '#include "filename"' or '#include <filename>' - size_t pos= sw.find_first_not_of(whitespaces,std::string("#include").size()+1); - size_t epos= 0; - std::string fn= ""; - std::stringstream errorMsg; - switch (char c= swap[pos++]) { - case '<': - c= '>'; - case '\"': - whitespaces+= c; - epos= sw.find_first_of(whitespaces, pos); - fn= sw.substr(pos,epos-pos); + if (pos0 != std::string::npos && sw[pos0] != '%' && sw[pos0] != '#' && sw[pos0] != 0) { + // parse line and extract map: tag->value + Parser parser(sw); + operator[](parser.name) = parser.value; + } else if (sw[pos0] == '#' && static_cast<size_t>(sw.find("#include")) == pos0) { + // include file by '#include "filename"' or '#include <filename>' + size_t pos = sw.find_first_not_of(whitespaces, std::string("#include").size() + 1); + size_t epos = 0; + std::string fn = ""; + std::stringstream errorMsg; + switch (char c= swap[pos++]) { + case '<': + c= '>'; + case '\"': + whitespaces += c; + epos = sw.find_first_of(whitespaces, pos); + fn = sw.substr(pos, epos - pos); - if (sw[epos]!=c) { - errorMsg << "filename in #include not terminated by " << c; - throw std::runtime_error(errorMsg.str()); - } - break; - default: - throw std::runtime_error("no filename given for #include"); - } - read(fn); - } - in.getline(swap, line_length); - } -}; - -void Initfile::readArgv(int argc, char **argv) -{ - for (int i= 0; i<argc; ++i) { - if (strcmp("-rs", argv[i]) == 0) { - std::string input(argv[i+1]); - add("argv->rs", input, 0); - } + if (sw[epos]!=c) { + errorMsg << "filename in #include not terminated by " << c; + throw std::runtime_error(errorMsg.str()); + } + break; + default: + throw std::runtime_error("no filename given for #include"); } -} + read(fn); + } + in.getline(swap, line_length); + } + } -/// read standard values for output and information of parameter-values -void Initfile::getInternalParameters() -{ - int val= 0; - get("level of information", val, 0); - msgInfo= val; - - val= 1; - get("WAIT", val, 0); - msgWait= val; + + void Initfile::readArgv(int argc, char **argv) + { + for (int i = 0; i < argc; i++) { + if (strcmp("-rs", argv[i]) == 0) { + std::string input(argv[i + 1]); + add("argv->rs", input, 0); + } + } + } + + + /// read standard values for output and information of parameter-values + void Initfile::getInternalParameters() + { + int val = 0; + get("level of information", val, 0); + msgInfo = val; - val= 1; - get("parameter information", val, 0); - paramInfo= val; + val = 1; + get("WAIT", val, 0); + msgWait = val; - val= 0; - get("break on missing tag", val, 0); - breakOnMissingTag= val; - - if (msgInfo==0) - paramInfo= 0; -}; - -/// print all parameters to std::cout -void Initfile::printParameters() { - initIntern(); - Initfile::iterator it; - for (it= singlett->begin(); it!=singlett->end(); it++) - std::cout << (*it).first << " => " << (*it).second << std::endl; -}; - -/// Write data-map to initfile -void Initfile::write(ostream& out) { - Initfile::iterator it; - for (it= begin() ; it!=end(); it++) - out << (*it).first << ": " << (*it).second << std::endl; + val = 1; + get("parameter information", val, 0); + paramInfo = val; -}; - -/// Write data-map to initfile -void Initfile::write(std::string fn) { - std::ofstream outFile; - outFile.open(fn.c_str(), std::ios::out); - if (!outFile.is_open()) - throw runtime_error("init-file cannot be opened for writing"); + val = 0; + get("break on missing tag", val, 0); + breakOnMissingTag = val; + + if (msgInfo == 0) + paramInfo = 0; + } + + + /// print all parameters to std::cout + void Initfile::printParameters() + { + initIntern(); + for (Initfile::iterator it = singlett->begin(); it != singlett->end(); it++) + std::cout << (*it).first << " => " << (*it).second << std::endl; + } + + + /// Write data-map to initfile + void Initfile::write(ostream& out) + { + for (Initfile::iterator it = begin() ; it!=end(); it++) + out << (*it).first << ": " << (*it).second << std::endl; + } + + + /// Write data-map to initfile + void Initfile::write(std::string fn) + { + std::ofstream outFile; + outFile.open(fn.c_str(), std::ios::out); + if (!outFile.is_open()) + throw runtime_error("init-file cannot be opened for writing"); - write(outFile); -}; + write(outFile); + } } diff --git a/AMDiS/src/Initfile.h b/AMDiS/src/Initfile.h index 552f607b..90538216 100644 --- a/AMDiS/src/Initfile.h +++ b/AMDiS/src/Initfile.h @@ -26,419 +26,524 @@ namespace AMDiS { namespace InitfileInternal { - /// Exceptions + /// Exceptions struct WrongVectorSize : std::runtime_error { - WrongVectorSize(std::string m):std::runtime_error(m) {} - }; + WrongVectorSize(std::string m) + : std::runtime_error(m) + {} + }; + struct NoDelim : std::runtime_error { - NoDelim(std::string m):std::runtime_error(m) {} - }; + NoDelim(std::string m) + : std::runtime_error(m) + {} + }; + struct WrongVectorFormat : std::runtime_error { - WrongVectorFormat(std::string m):std::runtime_error(m) {} - }; - template< typename T > + WrongVectorFormat(std::string m) + : std::runtime_error(m) + {} + }; + + template<typename T> struct WrongValueFormat : std::runtime_error { - static std::string name(int ) { return "int"; } - static std::string name(bool ) { return "bool"; } - static std::string name(double ) { return "double"; } - static std::string name(unsigned int ) { return "unsigned int"; } - template< typename G > - static std::string name(G ) { return std::string(typeid(G).name()); } + static std::string name(int) + { + return "int"; + } + + static std::string name(bool) + { + return "bool"; + } + + static std::string name(double) + { + return "double"; + } + + static std::string name(unsigned int) + { + return "unsigned int"; + } + + template<typename G> + static std::string name(G) + { + return std::string(typeid(G).name()); + } - WrongValueFormat(std::string value): std::runtime_error(std::string("cannot convert '") + value + std::string("' into <")+ name(T())+">" ) - {} - }; - template< typename T > - struct BadArithmeticExpression : std::runtime_error { - static std::string name(int ) { return "int"; } - static std::string name(bool ) { return "bool"; } - static std::string name(double ) { return "double"; } - static std::string name(unsigned int ) { return "unsigned int"; } - template< typename G > - static std::string name(G ) { return std::string(typeid(G).name()); } - - BadArithmeticExpression(std::string m, std::string value): std::runtime_error(std::string("cannot evaluate expression '") + value + std::string("' into <")+ name(T())+">\nParser message: '" + m + "'" ) - {} - }; - - /// trim std::string - inline std::string trim(const std::string& oldStr) { - std::string swap(oldStr); - boost::algorithm::trim(swap); - return swap; - } - /// return the delimiter or throw an exception if there is no known delimiter in value - inline size_t checkDelim(const std::string& value, const std::string& delims) { - size_t pos(std::string::npos); - for (unsigned i= 0; i<delims.length(); ++i) { - pos= value.find(delims[i]); - if (pos!=std::string::npos) - return i; - } - throw NoDelim("cannot detect the delimiter in " + value); - return 0; - } - + WrongValueFormat(std::string value) + : std::runtime_error(std::string("cannot convert '") + + value + std::string("' into <") + name(T()) + ">") + {} + }; - /** parse an container from tag tag. The Container must have the properties: - * - type value_type - * - member function push_back - */ - template< typename Container > - inline void getContainer(const std::string val_, Container& c) { + template<typename T> + struct BadArithmeticExpression : std::runtime_error { + static std::string name(int) + { + return "int"; + } + + static std::string name(bool) + { + return "bool"; + } + + static std::string name(double) + { + return "double"; + } + + static std::string name(unsigned int) + { + return "unsigned int"; + } + + template<typename G> + static std::string name(G) + { + return std::string(typeid(G).name()); + } - // accepted brackets and delimiters for vector input - std::string begBrackets= "{[("; - std::string endBrackets= "}])"; - std::string delims= ",;"; - - c.clear(); - std::string val= trim(val_); - size_t pos= begBrackets.find(val[0]); - if( pos == std::string::npos ) - throw WrongVectorFormat("cannot convert '" + val + "' into a list. No leading bracket found!"); - if( val[val.length() - 1] != endBrackets[pos] ) - throw WrongVectorFormat("begin and end bracket are different in value '" + val + "'"); - size_t oldPos= 1; - size_t curDelim= 0; - typedef typename Container::value_type ValueType; - ValueType swap; - try { - curDelim= checkDelim(val, delims); - pos= val.find(delims[curDelim], oldPos); - while( pos != std::string::npos ) { - std::string curWord= val.substr(oldPos, pos - oldPos); - oldPos= pos + 1; - convert(curWord, swap); - c.push_back(swap); - pos= val.find(delims[curDelim], oldPos); - } - //last entry - std::string curWord= val.substr(oldPos, val.length()-1 - oldPos); - convert(curWord, swap); - c.push_back(swap); - } catch (NoDelim nd) { - std::string curWord= val.substr(1, val.length()-2); - curWord = trim(curWord); - if(curWord.length()>0) { - // container with one entry - convert(curWord, swap); - c.push_back(swap); - } - } - } - - /// convert string to string - inline void convert(const std::string valStr, std::string& value) { - value= trim(valStr); - } + BadArithmeticExpression(std::string m, std::string value) + : std::runtime_error(std::string("cannot evaluate expression '") + + value + std::string("' into <") + name(T()) + + ">\nParser message: '" + m + "'") + {} + }; - /// convert string to intrinsic type - template< typename T > - inline void convert(const std::string valStr, T& value , - typename boost::enable_if< boost::is_pod< T > >::type* p = NULL , - typename boost::disable_if< boost::is_enum< T > >::type* p2 = NULL ) - { - using boost::lexical_cast; - using boost::numeric_cast; - - mu::Parser parser; - - parser.DefineConst(_T("M_PI"), m_pi); - parser.DefineConst(_T("M_E"), m_e); - try { - parser.SetExpr(valStr); -// value = lexical_cast< T >(trim(valStr)); - value= numeric_cast< T >(parser.Eval()); - } catch(boost::bad_lexical_cast e) { - throw WrongValueFormat< T >(valStr); - } catch(boost::bad_numeric_cast e) { - throw WrongValueFormat< T >(valStr); - } catch (mu::Parser::exception_type &e) { - throw BadArithmeticExpression< T >(e.GetMsg(), valStr); - } + + /// trim std::string + inline std::string trim(const std::string& oldStr) + { + std::string swap(oldStr); + boost::algorithm::trim(swap); + return swap; + } + + + /// return the delimiter or throw an exception if there is no known delimiter in value + inline size_t checkDelim(const std::string& value, const std::string& delims) + { + size_t pos(std::string::npos); + for (unsigned i = 0; i < delims.length(); i++) { + pos = value.find(delims[i]); + if (pos != std::string::npos) + return i; + } + throw NoDelim("cannot detect the delimiter in " + value); + return 0; + } + + + /** parse an container from tag tag. The Container must have the properties: + * - type value_type + * - member function push_back + */ + template< typename Container > + inline void getContainer(const std::string val_, Container& c) + { + // accepted brackets and delimiters for vector input + std::string begBrackets= "{[("; + std::string endBrackets= "}])"; + std::string delims= ",;"; + + c.clear(); + std::string val = trim(val_); + size_t pos = begBrackets.find(val[0]); + if (pos == std::string::npos) + throw WrongVectorFormat("cannot convert '" + val + "' into a list. No leading bracket found!"); + if (val[val.length() - 1] != endBrackets[pos]) + throw WrongVectorFormat("begin and end bracket are different in value '" + val + "'"); + size_t oldPos = 1; + size_t curDelim = 0; + typedef typename Container::value_type ValueType; + ValueType swap; + try { + curDelim = checkDelim(val, delims); + pos = val.find(delims[curDelim], oldPos); + while (pos != std::string::npos) { + std::string curWord = val.substr(oldPos, pos - oldPos); + oldPos = pos + 1; + convert(curWord, swap); + c.push_back(swap); + pos= val.find(delims[curDelim], oldPos); } - - template< typename T > - inline void convert(const std::string valStr, T& value, - typename boost::enable_if< boost::is_enum< T > >::type* p = NULL) - { - - unsigned int swap= 0; - try { - swap = boost::lexical_cast< unsigned int >(trim(valStr)); - }catch(boost::bad_lexical_cast e) { - throw WrongValueFormat< T >(valStr); - } - value = static_cast< T >(swap); + //last entry + std::string curWord = val.substr(oldPos, val.length() - 1 - oldPos); + convert(curWord, swap); + c.push_back(swap); + } catch (NoDelim nd) { + std::string curWord = val.substr(1, val.length() - 2); + curWord = trim(curWord); + if (curWord.length() > 0) { + // container with one entry + convert(curWord, swap); + c.push_back(swap); } - - /// convert string to WorldVector - template< typename T > - inline void convert(const std::string valStr, WorldVector<T>& c) { - std::vector<T> temp_vec; - getContainer(valStr, temp_vec); - if (static_cast<int>(temp_vec.size())!=c.getSize()) - throw WrongVectorSize("wrong number of entries for WorldVector"); + } + } + + + /// convert string to string + inline void convert(const std::string valStr, std::string& value) + { + value = trim(valStr); + } + + + /// convert string to intrinsic type + template<typename T> + inline void convert(const std::string valStr, T& value , + typename boost::enable_if<boost::is_pod<T> >::type* p = NULL , + typename boost::disable_if<boost::is_enum<T> >::type* p2 = NULL) + { + using boost::lexical_cast; + using boost::numeric_cast; + + mu::Parser parser; + + parser.DefineConst(_T("M_PI"), m_pi); + parser.DefineConst(_T("M_E"), m_e); + try { + parser.SetExpr(valStr); + value = numeric_cast< T >(parser.Eval()); + } catch(boost::bad_lexical_cast e) { + throw WrongValueFormat< T >(valStr); + } catch(boost::bad_numeric_cast e) { + throw WrongValueFormat< T >(valStr); + } catch (mu::Parser::exception_type &e) { + throw BadArithmeticExpression<T>(e.GetMsg(), valStr); + } + } + + + template<typename T> + inline void convert(const std::string valStr, T& value, + typename boost::enable_if< boost::is_enum< T > >::type* p = NULL) + { + unsigned int swap = 0; + try { + swap = boost::lexical_cast<unsigned int>(trim(valStr)); + } catch(boost::bad_lexical_cast e) { + throw WrongValueFormat< T >(valStr); + } + value = static_cast< T >(swap); + } + + + /// convert string to WorldVector + template< typename T > + inline void convert(const std::string valStr, WorldVector<T>& c) + { + std::vector<T> temp_vec; + getContainer(valStr, temp_vec); + if (static_cast<int>(temp_vec.size()) != c.getSize()) + throw WrongVectorSize("wrong number of entries for WorldVector"); - for (unsigned i= 0; i<temp_vec.size(); ++i) - c[i]= temp_vec[i]; - } - - /// convert string to std::list using begBrackets, endBrackets and delims - template< typename T > - inline void convert(const std::string valStr, std::list< T >& value) { - getContainer(valStr, value); - } - - /// convert string to std::vector using begBrackets, endBrackets and delims - template< typename T > - inline void convert(const std::string valStr, std::vector< T >& value) { - getContainer(valStr, value); - } - - /// convert value of arbitrary type to string using stringstream and operator<< for type - template< typename T > - inline void convert(const T value, std::string& valStr) { - std::stringstream ss; - ss << value; - valStr= ss.str(); - } - /// convert WorldVector to string - template< typename T > - inline void convert(const WorldVector<T>& c, std::string& valStr) { - std::vector<T> temp_vec(c.getSize()); - for (unsigned i= 0; i<temp_vec.size(); ++i) - temp_vec[i]= c[i]; - convert(temp_vec, valStr); - } + for (unsigned i = 0; i < temp_vec.size(); i++) + c[i] = temp_vec[i]; + } + + + /// convert string to std::list using begBrackets, endBrackets and delims + template<typename T> + inline void convert(const std::string valStr, std::list<T>& value) + { + getContainer(valStr, value); + } + + + /// convert string to std::vector using begBrackets, endBrackets and delims + template<typename T> + inline void convert(const std::string valStr, std::vector<T>& value) + { + getContainer(valStr, value); + } + + + /// convert value of arbitrary type to string using stringstream and operator<< for type + template<typename T> + inline void convert(const T value, std::string& valStr) + { + std::stringstream ss; + ss << value; + valStr= ss.str(); + } + + + /// convert WorldVector to string + template<typename T> + inline void convert(const WorldVector<T>& c, std::string& valStr) + { + std::vector<T> temp_vec(c.getSize()); + for (unsigned i = 0; i < temp_vec.size(); i++) + temp_vec[i] = c[i]; + convert(temp_vec, valStr); + } } // end namespace InitfileInternal -/** The entry in an initfile. This helper class was constructed to allow calls like - * val = data.get(tag) - * for arbitrary types of val. At current stage, only double and bool is supported - */ - -struct InitEntry { - ///the value as string - std::string valStr; - - /// initialize with value as string - InitEntry(std::string v= ""): - valStr(v) {} - - /// cast string to type T - template< typename T > - operator T() const { T t; convert(valStr, t); return t;} -}; - -/// output-stream for std::list -template< typename T > -std::ostream& operator<<(std::ostream& o, const std::list< T >& l) { - typename std::list< T >::const_iterator it= l.begin(); - o << "["; - for(unsigned i= 0; it!=l.end() && i<l.size(); ++i) { - o << *it << (i<l.size()-1?", ":""); - ++it; - } - o << "]"; - return o; -} -/// output-stream for std::vector -template< typename T > -std::ostream& operator<<(std::ostream& o, const std::vector< T >& l) { - typename std::vector< T >::const_iterator it= l.begin(); - o << "["; - for(unsigned i= 0; it!=l.end() && i<l.size(); ++i) { - o << *it << (i<l.size()-1?", ":""); - ++it; - } - o << "]"; - return o; -} -/** Basis data container as a map of tag on a value as strings. The container throws an exception, if the tag was not found. - */ -struct Initfile : public std::map< std::string, std::string > { - typedef std::map< std::string, std::string > super; - /// Exceptions + /** The entry in an initfile. This helper class was constructed to allow calls like + * val = data.get(tag) + * for arbitrary types of val. At current stage, only double and bool is supported + */ + struct InitEntry { + ///the value as string + std::string valStr; + + /// initialize with value as string + InitEntry(std::string v = "") + : valStr(v) + {} + + /// cast string to type T + template<typename T> + operator T() const + { + T t; + convert(valStr, t); + return t; + } + }; + + + /// output-stream for std::list + template<typename T> + std::ostream& operator<<(std::ostream& o, const std::list< T >& l) + { + typename std::list< T >::const_iterator it = l.begin(); + o << "["; + for (unsigned i = 0; it != l.end() && i < l.size(); i++) { + o << *it << (i < l.size() - 1 ? ", " : ""); + ++it; + } + o << "]"; + return o; + } + + + /// output-stream for std::vector + template<typename T> + std::ostream& operator<<(std::ostream& o, const std::vector<T>& l) + { + typename std::vector<T>::const_iterator it = l.begin(); + o << "["; + for (unsigned i = 0; it != l.end() && i < l.size(); i++) { + o << *it << (i < l.size() - 1 ? ", " : ""); + ++it; + } + o << "]"; + return o; + } + + + /** Basis data container as a map of tag on a value as strings. The container throws an exception, if the tag was not found. + */ + struct Initfile : public std::map<std::string, std::string> + { + typedef std::map< std::string, std::string > super; + + /// Exceptions struct TagNotFound : std::invalid_argument { - TagNotFound(std::string m):std::invalid_argument(m) {} - }; + TagNotFound(std::string m) + : std::invalid_argument(m) + {} + }; + struct TagNotFoundBreak : std::invalid_argument { // print 'tag not found' and exit - TagNotFoundBreak(std::string m):std::invalid_argument(m) {} - }; + TagNotFoundBreak(std::string m) + : std::invalid_argument(m) + {} + }; - /** initialize init-file from file with filename in, read data and save it to singleton-map - * @param in: filename string - */ - static void init(std::string in); - static void init(int print, string filename, const char *flags = NULL) { - WARNING("Parameters::init(int,std::string,const char*) is depreciated. Use Parameters::init(std::string) instead!\n"); - init(filename); - } + /** initialize init-file from file with filename in, read data and save it to singleton-map + * @param in: filename string + */ + static void init(std::string in); + + static void init(int print, string filename, const char *flags = NULL) + { + WARNING("Parameters::init(int,std::string,const char*) is depreciated. Use Parameters::init(std::string) instead!\n"); + init(filename); + } - /** Static get routine for getting parameter-values from init-file initialized in init()-method. - * Cast the value to the desired type using std::stringstream. - * @param tag: The tag to look for - * @param value: The result. - * @param debug_info: msgInfo for current parameter. (0..no printing, 1..print missing parameter info, 2..print parameter value) [optional] - */ - template< typename T > - static void get(const std::string tag, T& value, int debug_info= -1) { - using namespace InitfileInternal; - initIntern(); - if (debug_info==-1) - debug_info= singlett->getMsgInfo(); + /** Static get routine for getting parameter-values from init-file initialized in init()-method. + * Cast the value to the desired type using std::stringstream. + * @param tag: The tag to look for + * @param value: The result. + * @param debugInfo: msgInfo for current parameter. (0..no printing, 1..print missing parameter info, 2..print parameter value) [optional] + */ + template<typename T> + static void get(const std::string tag, T& value, int debugInfo = -1) + { + using namespace InitfileInternal; + initIntern(); + if (debugInfo == -1) + debugInfo = singlett->getMsgInfo(); - try { - std::string valStr(singlett->checkedGet(tag)); - valStr= trim(valStr); - convert(valStr, value); - if (debug_info==2) - std::cout << "Parameter '" << tag << "' initialized with: " << value << std::endl; - } catch (TagNotFound ia) { - if (debug_info>=1) - std::cout << ia.what() << std::endl; - } - } - /// return InitEntry object for tag tag - static InitEntry get(const std::string tag) { - using namespace InitfileInternal; - int debug_info= singlett->getMsgInfo(); - InitEntry result; - try { - std::string valStr(singlett->checkedGet(tag)); - valStr= trim(valStr); - result= InitEntry(valStr); - } catch (TagNotFound ia) { - if (debug_info>=1) - std::cout << ia.what() << std::endl; - } - return result; - } + try { + std::string valStr(singlett->checkedGet(tag)); + valStr = trim(valStr); + convert(valStr, value); + if (debugInfo == 2) + std::cout << "Parameter '" << tag << "' initialized with: " << value << std::endl; + } catch (TagNotFound ia) { + if (debugInfo >= 1) + std::cout << ia.what() << std::endl; + } + } + + + /// return InitEntry object for tag tag + static InitEntry get(const std::string tag) + { + using namespace InitfileInternal; + int debugInfo = singlett->getMsgInfo(); + InitEntry result; + try { + std::string valStr(singlett->checkedGet(tag)); + valStr = trim(valStr); + result = InitEntry(valStr); + } catch (TagNotFound ia) { + if (debugInfo >= 1) + std::cout << ia.what() << std::endl; + } + return result; + } - /// update map tag->value_old to tag->value in singleton - template< typename T > - static void set(const std::string tag, T& value, int debug_info= -1) { - using namespace InitfileInternal; - initIntern(); - if (debug_info==-1) - debug_info= singlett->getMsgInfo(); + + /// update map tag->value_old to tag->value in singleton + template<typename T> + static void set(const std::string tag, T& value, int debugInfo= -1) + { + using namespace InitfileInternal; + initIntern(); + if (debugInfo == -1) + debugInfo = singlett->getMsgInfo(); - std::string swap= ""; - convert(value, swap); - (*singlett)[trim(tag)]= swap; - // update msg parameters msgInfo, msgWait, paramInfo - singlett->getInternalParameters(); - if (debug_info==2) - std::cout << "Parameter '" << tag << "' set to: " << value << std::endl; - } + std::string swap = ""; + convert(value, swap); + (*singlett)[trim(tag)] = swap; + // update msg parameters msgInfo, msgWait, paramInfo + singlett->getInternalParameters(); + if (debugInfo == 2) + std::cout << "Parameter '" << tag << "' set to: " << value << std::endl; + } - /// add map tag->value to data in singleton - template< typename T > - static void add(const std::string tag, T& value, int debug_info= -1) { - set(tag, value, debug_info); - } - - /// rescheduling parameter + /// add map tag->value to data in singleton + template< typename T > + static void add(const std::string tag, T& value, int debugInfo = -1) + { + set(tag, value, debugInfo); + } + + /// rescheduling parameter static void readArgv(int argc, char **argv); - /// Returns specified info level - static int getMsgInfo() - { - return (singlett!=NULL) ? singlett->msgInfo : 0; - } - - /// Returns specified wait value - static int getMsgWait() - { - return (singlett!=NULL) ? singlett->msgWait : 0; - } + /// Returns specified info level + static int getMsgInfo() + { + return (singlett != NULL) ? singlett->msgInfo : 0; + } + + /// Returns specified wait value + static int getMsgWait() + { + return (singlett != NULL) ? singlett->msgWait : 0; + } - /// Checks whether parameters are initialized. if not, call init() - static bool initialized() - { - return (singlett!=NULL); - } - - /// return pointer to singleton - static Initfile *getSingleton() - { - return singlett; - } + /// Checks whether parameters are initialized. if not, call init() + static bool initialized() + { + return (singlett != NULL); + } + + /// return pointer to singleton + static Initfile *getSingleton() + { + return singlett; + } - /// print all data in singleton to std::cout - static void printParameters(); - - /// clear data in singleton - static void clearData() - { - initIntern(); - singlett->clear(); - } + /// print all data in singleton to std::cout + static void printParameters(); + + /// clear data in singleton + static void clearData() + { + initIntern(); + singlett->clear(); + } - /// save singlett-data to file with filename fn - static void save(std::string fn) - { - initIntern(); - singlett->write(fn); - } + /// save singlett-data to file with filename fn + static void save(std::string fn) + { + initIntern(); + singlett->write(fn); + } -protected: - Initfile() : msgInfo(0), msgWait(1), paramInfo(1), breakOnMissingTag(0) {} + protected: + Initfile() + : msgInfo(0), + msgWait(1), + paramInfo(1), + breakOnMissingTag(0) + {} - static void initIntern() { - if (singlett == NULL) - singlett= new Initfile; - } + static void initIntern() + { + if (singlett == NULL) + singlett = new Initfile; + } - /// list of processed files - static std::set< std::string > fn_include_list; + /// list of processed files + static std::set< std::string > fn_include_list; - /// pointer to the singleton that contains the data - static Initfile* singlett; + /// pointer to the singleton that contains the data + static Initfile* singlett; - /// return the value of the given tag or throws an exception if the tag does not exist - std::string checkedGet(const std::string& tag) const { - super::const_iterator it= find(tag); - if (it==end()) { - if(breakOnMissingTag==0 || msgInfo<=2) - throw TagNotFound("there is no tag '"+ tag + "'"); - else - throw TagNotFoundBreak("required tag '"+ tag + "' not found"); - } - return it->second; - } - - /** Fill the initfile from an input stream. - * @param in: the stream to fill the data from. - * Current dataformat: tag:value - * Comment char: percent '%' - * Include files: #include "filename" or #include <filename> - */ - void read(std::istream& in); - - /// Fill the initfile from a file with filename fn - void read(std::string fn); + /// return the value of the given tag or throws an exception if the tag does not exist + std::string checkedGet(const std::string& tag) const + { + super::const_iterator it = find(tag); + if (it == end()) { + if (breakOnMissingTag == 0 || msgInfo <= 2) + throw TagNotFound("there is no tag '"+ tag + "'"); + else + throw TagNotFoundBreak("required tag '"+ tag + "' not found"); + } + return it->second; + } + + /** Fill the initfile from an input stream. + * @param in: the stream to fill the data from. + * Current dataformat: tag:value + * Comment char: percent '%' + * Include files: #include "filename" or #include <filename> + */ + void read(std::istream& in); + + /// Fill the initfile from a file with filename fn + void read(std::string fn); - /** Write data-map to initfile - * @param out: the stream to fill the data in. - */ - void write(std::ostream& out); + /** Write data-map to initfile + * @param out: the stream to fill the data in. + */ + void write(std::ostream& out); - /// Write data-map to initfile with filename fn - void write(std::string fn); - - /// read parameters for msgInfo, msgWait, paramInfo - void getInternalParameters(); + /// Write data-map to initfile with filename fn + void write(std::string fn); - int msgInfo, msgWait, paramInfo, breakOnMissingTag; + /// read parameters for msgInfo, msgWait, paramInfo + void getInternalParameters(); -}; + int msgInfo, msgWait, paramInfo, breakOnMissingTag; + }; -typedef Initfile Parameters; + typedef Initfile Parameters; } // end namespace AMDiS #endif diff --git a/AMDiS/src/UmfPackSolver.h b/AMDiS/src/UmfPackSolver.h index 783cdb8b..4a98a231 100644 --- a/AMDiS/src/UmfPackSolver.h +++ b/AMDiS/src/UmfPackSolver.h @@ -50,13 +50,15 @@ namespace AMDiS { oem(*oem_), solver(NULL), store_symbolic(0), - symmetric_strategy(0) + symmetric_strategy(0), + alloc_init(0.7) { FUNCNAME("Umfpack_runner::Umfpack_runner()"); TEST_EXIT_DBG(oem_ != NULL)("Need real OEMSolver\n"); Parameters::get(oem.getName() + "->store symbolic", store_symbolic); Parameters::get(oem.getName() + "->symmetric strategy", symmetric_strategy); + Parameters::get(oem.getName() + "->alloc init", alloc_init); } template< typename Vector> @@ -64,10 +66,7 @@ namespace AMDiS { { FUNCNAME("Umfpack_runner::solve()"); if (!solver) { - if (!symmetric_strategy) - solver = new mtl::matrix::umfpack::solver<matrix_type>(A); - else - solver = new mtl::matrix::umfpack::solver<matrix_type>(A, UMFPACK_STRATEGY_SYMMETRIC); + solver = new mtl::matrix::umfpack::solver<matrix_type>(A, symmetric_strategy, alloc_init); } else { if (!oem.getMultipleRhs()) { if (store_symbolic) @@ -101,7 +100,10 @@ namespace AMDiS { mtl::matrix::umfpack::solver<matrix_type> *solver; int store_symbolic; + int symmetric_strategy; + + double alloc_init; }; using namespace MTLTypes; -- GitLab