Commit 8698e7fe authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

Initfiles in AMDiS code style.

parent f025c9bb
...@@ -8,153 +8,164 @@ using namespace std; ...@@ -8,153 +8,164 @@ using namespace std;
namespace AMDiS { namespace AMDiS {
/// the small parser for the initfile. see description of read(Initfile&, istream&) /// the small parser for the initfile. see description of read(Initfile&, istream&)
struct Parser { struct Parser {
Parser(const string& line) { Parser(const string& line)
size_t pos= line.find(':'); {
if (pos == string::npos) size_t pos = line.find(':');
throw runtime_error("cannot find the delimiter ':' in line '"+line+"'"); if (pos == string::npos)
name= line.substr(0, pos); throw runtime_error("cannot find the delimiter ':' in line '" + line + "'");
value= line.substr(pos+1, line.length() - (pos + 1)); name = line.substr(0, pos);
// remove everything after the % value = line.substr(pos + 1, line.length() - (pos + 1));
pos= value.find('%');
if (pos != string::npos) { // remove everything after the %
value= value.substr(0, pos); pos = value.find('%');
} if (pos != string::npos)
} value = value.substr(0, pos);
string name; }
string value; string name;
}; string value;
};
Initfile* Initfile::singlett= NULL;
std::set< std::string > Initfile::fn_include_list; 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(); /// initialize singleton object an global parameters
singlett->clear(); void Initfile::init(std::string in)
fn_include_list.clear(); {
singlett->read(in); initIntern();
singlett->clear();
singlett->getInternalParameters(); fn_include_list.clear();
singlett->read(in);
singlett->getInternalParameters();
// initialize global strcutures using parameters // initialize global strcutures using parameters
Global::init(); Global::init();
}; }
/// Fill an initfile from a file with filename fn
void Initfile::read(std::string fn) { /// Fill an initfile from a file with filename fn
// read file if its not parsed already void Initfile::read(std::string fn)
if (fn_include_list.find(fn)==fn_include_list.end()) { {
std::ifstream inputFile; // read file if its not parsed already
inputFile.open(fn.c_str(), std::ios::in); if (fn_include_list.find(fn) == fn_include_list.end()) {
if (!inputFile.is_open()) std::ifstream inputFile;
throw runtime_error("init-file cannot be opened for reading"); 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); fn_include_list.insert(fn);
read(inputFile); read(inputFile);
} }
}; }
/// Fill an initfile from an input stream
void Initfile::read(istream& in) { /// Fill an initfile from an input stream
unsigned line_length= 256; void Initfile::read(istream& in)
char swap[line_length]; {
in.getline(swap, line_length); unsigned line_length = 256;
while (in.good()) { char swap[line_length];
std::string whitespaces= " \t\r\f"; in.getline(swap, line_length);
std::string sw(swap); while (in.good()) {
size_t pos0= sw.find_first_not_of(whitespaces); 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) { if (pos0 != std::string::npos && sw[pos0] != '%' && sw[pos0] != '#' && sw[pos0] != 0) {
// parse line and extract map: tag->value // parse line and extract map: tag->value
Parser parser(sw); Parser parser(sw);
operator[](parser.name)= parser.value; operator[](parser.name) = parser.value;
} else if (sw[pos0]=='#' && static_cast<size_t>(sw.find("#include"))==pos0) { } else if (sw[pos0] == '#' && static_cast<size_t>(sw.find("#include")) == pos0) {
// include file by '#include "filename"' or '#include <filename>' // include file by '#include "filename"' or '#include <filename>'
size_t pos= sw.find_first_not_of(whitespaces,std::string("#include").size()+1); size_t pos = sw.find_first_not_of(whitespaces, std::string("#include").size() + 1);
size_t epos= 0; size_t epos = 0;
std::string fn= ""; std::string fn = "";
std::stringstream errorMsg; std::stringstream errorMsg;
switch (char c= swap[pos++]) { switch (char c= swap[pos++]) {
case '<': case '<':
c= '>'; c= '>';
case '\"': case '\"':
whitespaces+= c; whitespaces += c;
epos= sw.find_first_of(whitespaces, pos); epos = sw.find_first_of(whitespaces, pos);
fn= sw.substr(pos,epos-pos); fn = sw.substr(pos, epos - pos);
if (sw[epos]!=c) { if (sw[epos]!=c) {
errorMsg << "filename in #include not terminated by " << c; errorMsg << "filename in #include not terminated by " << c;
throw std::runtime_error(errorMsg.str()); throw std::runtime_error(errorMsg.str());
} }
break; break;
default: default:
throw std::runtime_error("no filename given for #include"); 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);
}
} }
} read(fn);
}
in.getline(swap, line_length);
}
}
/// read standard values for output and information of parameter-values
void Initfile::getInternalParameters() void Initfile::readArgv(int argc, char **argv)
{ {
int val= 0; for (int i = 0; i < argc; i++) {
get("level of information", val, 0); if (strcmp("-rs", argv[i]) == 0) {
msgInfo= val; std::string input(argv[i + 1]);
add("argv->rs", input, 0);
val= 1; }
get("WAIT", val, 0); }
msgWait= val; }
/// 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; val = 1;
get("parameter information", val, 0); get("WAIT", val, 0);
paramInfo= val; msgWait = val;
val= 0; val = 1;
get("break on missing tag", val, 0); get("parameter information", val, 0);
breakOnMissingTag= val; paramInfo = 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 = 0;
get("break on missing tag", val, 0);
/// Write data-map to initfile breakOnMissingTag = val;
void Initfile::write(std::string fn) {
std::ofstream outFile; if (msgInfo == 0)
outFile.open(fn.c_str(), std::ios::out); paramInfo = 0;
if (!outFile.is_open()) }
throw runtime_error("init-file cannot be opened for writing");
/// 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);
}; }
} }
This diff is collapsed.
...@@ -50,13 +50,15 @@ namespace AMDiS { ...@@ -50,13 +50,15 @@ namespace AMDiS {
oem(*oem_), oem(*oem_),
solver(NULL), solver(NULL),
store_symbolic(0), store_symbolic(0),
symmetric_strategy(0) symmetric_strategy(0),
alloc_init(0.7)
{ {
FUNCNAME("Umfpack_runner::Umfpack_runner()"); FUNCNAME("Umfpack_runner::Umfpack_runner()");
TEST_EXIT_DBG(oem_ != NULL)("Need real OEMSolver\n"); TEST_EXIT_DBG(oem_ != NULL)("Need real OEMSolver\n");
Parameters::get(oem.getName() + "->store symbolic", store_symbolic); Parameters::get(oem.getName() + "->store symbolic", store_symbolic);
Parameters::get(oem.getName() + "->symmetric strategy", symmetric_strategy); Parameters::get(oem.getName() + "->symmetric strategy", symmetric_strategy);
Parameters::get(oem.getName() + "->alloc init", alloc_init);
} }
template< typename Vector> template< typename Vector>
...@@ -64,10 +66,7 @@ namespace AMDiS { ...@@ -64,10 +66,7 @@ namespace AMDiS {
{ {
FUNCNAME("Umfpack_runner::solve()"); FUNCNAME("Umfpack_runner::solve()");
if (!solver) { if (!solver) {
if (!symmetric_strategy) solver = new mtl::matrix::umfpack::solver<matrix_type>(A, symmetric_strategy, alloc_init);
solver = new mtl::matrix::umfpack::solver<matrix_type>(A);
else
solver = new mtl::matrix::umfpack::solver<matrix_type>(A, UMFPACK_STRATEGY_SYMMETRIC);
} else { } else {
if (!oem.getMultipleRhs()) { if (!oem.getMultipleRhs()) {
if (store_symbolic) if (store_symbolic)
...@@ -101,7 +100,10 @@ namespace AMDiS { ...@@ -101,7 +100,10 @@ namespace AMDiS {
mtl::matrix::umfpack::solver<matrix_type> *solver; mtl::matrix::umfpack::solver<matrix_type> *solver;
int store_symbolic; int store_symbolic;
int symmetric_strategy; int symmetric_strategy;
double alloc_init;
}; };
using namespace MTLTypes; using namespace MTLTypes;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment