Commit f1e70c5f authored by Christof Metzger-Kraus's avatar Christof Metzger-Kraus
Browse files

first step towards parsing opt pilot commands using Opal parser

parent 3cad0820
......@@ -41,12 +41,19 @@
/////////////////////////////////////////////////////////////////////
// public static members of IpplInfo, initialized to default values
Communicate *IpplInfo::Comm = new Communicate();
IpplStats *IpplInfo::Stats = new IpplStats();
Inform *IpplInfo::Info = new Inform("Ippl");
Inform *IpplInfo::Warn = new Inform("Warning", std::cerr);
Inform *IpplInfo::Error = new Inform("Error", std::cerr, INFORM_ALL_NODES);
Inform *IpplInfo::Debug = new Inform("**DEBUG**", std::cerr, INFORM_ALL_NODES);
Communicate *IpplInfo::Comm = 0;
IpplStats *IpplInfo::Stats = 0;
Inform *IpplInfo::Info = 0;
Inform *IpplInfo::Warn = 0;
Inform *IpplInfo::Error = 0;
Inform *IpplInfo::Debug = 0;
// Communicate *IpplInfo::Comm = new Communicate();
// IpplStats *IpplInfo::Stats = new IpplStats();
// Inform *IpplInfo::Info = new Inform("Ippl");
// Inform *IpplInfo::Warn = new Inform("Warning", std::cerr);
// Inform *IpplInfo::Error = new Inform("Error", std::cerr, INFORM_ALL_NODES);
// Inform *IpplInfo::Debug = new Inform("**DEBUG**", std::cerr, INFORM_ALL_NODES);
std::stack<StaticIpplInfo> IpplInfo::stashedStaticMembers;
//dks base member of IpplInfo initialized to default values
......@@ -178,6 +185,14 @@ IpplInfo::IpplInfo(int& argc, char**& argv, int removeargs, MPI_Comm mpicomm) {
communicator_m = mpicomm;
if (NumCreated == 0) {
Comm = new Communicate();
Stats = new IpplStats();
Info = new Inform("Ippl");
Warn = new Inform("Warning", std::cerr);
Error = new Inform("Error", std::cerr, INFORM_ALL_NODES);
Debug = new Inform("**DEBUG**", std::cerr, INFORM_ALL_NODES);
}
// You can only specify argc, argv once; if it is done again, print a warning
// and continue as if we had not given argc, argv.
if ( CommInitialized ) {
......@@ -564,6 +579,15 @@ IpplInfo::IpplInfo(int& argc, char**& argv, int removeargs, MPI_Comm mpicomm) {
/////////////////////////////////////////////////////////////////////
// Constructor 2: default constructor.
IpplInfo::IpplInfo() {
if (NumCreated == 0) {
Comm = new Communicate();
Stats = new IpplStats();
Info = new Inform("Ippl");
Warn = new Inform("Warning", std::cerr);
Error = new Inform("Error", std::cerr, INFORM_ALL_NODES);
Debug = new Inform("**DEBUG**", std::cerr, INFORM_ALL_NODES);
}
// just indicate we've also been created
NumCreated++;
}
......@@ -572,6 +596,15 @@ IpplInfo::IpplInfo() {
/////////////////////////////////////////////////////////////////////
// Constructor 3: copy constructor.
IpplInfo::IpplInfo(const IpplInfo&) {
if (NumCreated == 0) {
Comm = new Communicate();
Stats = new IpplStats();
Info = new Inform("Ippl");
Warn = new Inform("Warning", std::cerr);
Error = new Inform("Error", std::cerr, INFORM_ALL_NODES);
Debug = new Inform("**DEBUG**", std::cerr, INFORM_ALL_NODES);
}
// just indicate we've also been created
NumCreated++;
}
......@@ -1175,4 +1208,4 @@ void __C_runtime_error ( int trap_code, char *name, int line_no, ... ) {
* $RCSfile: IpplInfo.cpp,v $ $Author: adelmann $
* $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
* IPPL_VERSION_ID: $Id: IpplInfo.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
***************************************************************************/
***************************************************************************/
\ No newline at end of file
......@@ -2,8 +2,8 @@
/***************************************************************************
*
* The IPPL Framework
*
* This program was prepared by PSI.
*
* This program was prepared by PSI.
* All rights in the program are reserved by PSI.
* Neither PSI nor the author(s)
* makes any warranty, express or implied, or assumes any liability or
......@@ -17,7 +17,7 @@
/***************************************************************************
*
* The IPPL Framework
*
*
*
* Visit http://people.web.psi.ch/adelmann/ for more details
*
......@@ -39,14 +39,13 @@
// include files
#include "Utility/Timer.h"
#ifdef IPPL_XT3
#include <catamount/dclock.h>
#endif
#if defined(IPPL_T3E)
#define tick_secs(ticks, clock_ticks) \
( (double) ticks / (double) clock_ticks )
( (double) ticks / (double) clock_ticks )
#endif
// TIMERON and TIMEROFF define the current state of a Timer
......@@ -67,7 +66,7 @@
Timer::Timer()
{
#ifdef __MWERKS__
// For now, stub out all Timer guts for MetroWerks
......@@ -98,7 +97,7 @@ Timer::Timer()
Timer::~Timer()
{
#ifdef __MWERKS__
// For now, stub out all Timer guts for MetroWerks
......@@ -129,7 +128,7 @@ Timer::~Timer()
void Timer::clear()
{
#ifdef __MWERKS__
// For now, stub out all Timer guts for MetroWerks
......@@ -170,7 +169,7 @@ void Timer::clear()
void Timer::start()
{
#ifdef __MWERKS__
// For now, stub out all Timer guts for MetroWerks
......@@ -221,7 +220,7 @@ void Timer::start()
void Timer::stop()
{
#ifdef __MWERKS__
// For now, stub out all Timer guts for MetroWerks
......@@ -276,7 +275,7 @@ void Timer::stop()
double Timer::clock_time()
{
#ifdef __MWERKS__
// For now, stub out all Timer guts for MetroWerks
......@@ -285,7 +284,7 @@ double Timer::clock_time()
#if !defined(IPPL_XT3)
long seconds; // seconds elapsed
#if !defined(IPPL_T3E)
long useconds; // useconds (mirco-seconds) elapsed
#endif
......@@ -299,7 +298,7 @@ double Timer::clock_time()
// Timer is currently off, so just return accumulated time
#if !defined(IPPL_XT3)
seconds = current_secs;
#if !defined(IPPL_T3E)
useconds = current_usecs;
#endif
......@@ -347,7 +346,7 @@ double Timer::clock_time()
#endif
return ret_val;
#endif // __MWERKS__
}
/* END OF FUNCTION clock_time */
......@@ -366,13 +365,13 @@ double Timer::clock_time()
double Timer::user_time()
{
#ifdef __MWERKS__
// For now, stub out all Timer guts for MetroWerks
return 0.0;
#else
double ret_val; // Return value
double ret_val; // Return value
#if ( defined(IPPL_T3E) || defined(IPPL_XT3) )
// Not defined yet on T3E or TFLOP.
......@@ -415,7 +414,7 @@ double Timer::user_time()
double Timer::system_time()
{
#ifdef __MWERKS__
// For now, stub out all Timer guts for MetroWerks
......@@ -452,5 +451,5 @@ double Timer::system_time()
/***************************************************************************
* $RCSfile: Timer.cpp,v $ $Author: adelmann $
* $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
* IPPL_VERSION_ID: $Id: Timer.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
***************************************************************************/
* IPPL_VERSION_ID: $Id: Timer.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
***************************************************************************/
\ No newline at end of file
......@@ -36,30 +36,34 @@ namespace client { namespace parser
// The expression grammar
///////////////////////////////////////////////////////////////////////////////
template <typename Iterator>
struct expression : qi::grammar<Iterator, ast::expression(), skipper<Iterator> >
struct expression : qi::grammar<Iterator, ast::expression(), qi::locals<char>, skipper<Iterator> >
{
expression(error_handler<Iterator>& error_handler);
qi::rule<Iterator, ast::expression(), skipper<Iterator> >
qi::rule<Iterator, ast::expression(), qi::locals<char>, skipper<Iterator> >
expr, equality_expr, relational_expr,
logical_or_expr, logical_and_expr,
additive_expr, multiplicative_expr
;
qi::rule<Iterator, ast::operand(), skipper<Iterator> >
qi::rule<Iterator, ast::operand(), qi::locals<char>, skipper<Iterator> >
unary_expr, primary_expr, constant_expr
;
qi::rule<Iterator, ast::function_call(), skipper<Iterator> >
qi::rule<Iterator, ast::function_call(), qi::locals<char>, skipper<Iterator> >
function_call
;
qi::rule<Iterator, std::list<ast::function_call_argument>(), skipper<Iterator> >
qi::rule<Iterator, std::list<ast::function_call_argument>(), qi::locals<char>, skipper<Iterator> >
argument_list
;
qi::rule<Iterator, std::string(), skipper<Iterator> >
identifier, quoted_string
qi::rule<Iterator, std::string(), qi::locals<char>, skipper<Iterator> >
identifier
;
qi::rule<Iterator, std::string(), qi::locals<char>, skipper<Iterator> >
quoted_string
;
qi::symbols<char, ast::optoken>
......@@ -74,6 +78,4 @@ namespace client { namespace parser
};
}}
#endif
#endif
\ No newline at end of file
......@@ -8,6 +8,9 @@
#include "error_handler.hpp"
#include "annotation.hpp"
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/fusion/adapted.hpp>
//#include <boost/spirit/include/qi_lit.hpp>
namespace client { namespace parser
{
......@@ -19,6 +22,7 @@ namespace client { namespace parser
// qi::_2_type _2;
qi::_3_type _3;
qi::_4_type _4;
qi::_a_type _a;
qi::char_type char_;
qi::uint_type uint_;
......@@ -26,6 +30,9 @@ namespace client { namespace parser
qi::_val_type _val;
qi::raw_type raw;
qi::lexeme_type lexeme;
qi::lit_type lit;
qi::no_skip_type no_skip;
qi::omit_type omit;
qi::alpha_type alpha;
qi::alnum_type alnum;
qi::bool_type bool_;
......@@ -142,9 +149,9 @@ namespace client { namespace parser
;
quoted_string %=
'"'
> *(char_ - '"')
> '"'
omit [ char_("'\"") [_a = _1] ]
>> no_skip [ *(char_ - char_(_a)) ]
>> lit(_a)
;
argument_list = -((expr | quoted_string) % ',');
......
......@@ -86,4 +86,4 @@ private:
SDDSVariable var_;
};
#endif
#endif
\ No newline at end of file
......@@ -96,32 +96,22 @@ public:
, comm_(comm)
, cmd_args_(args)
{
global_rank_ = comm_->globalRank();
if(global_rank_ == 0) {
std::cout << "\033[01;35m";
std::cout << " _ _ _ _ " << std::endl;
std::cout << " | | (_) | | | " << std::endl;
std::cout << " ___ _ __ | |_ ______ _ __ _| | ___ | |_ " << std::endl;
std::cout << " / _ \\| '_ \\| __|______| '_ \\| | |/ _ \\| __|" << std::endl;
std::cout << "| (_) | |_) | |_ | |_) | | | (_) | |_ " << std::endl;
std::cout << " \\___/| .__/ \\__| | .__/|_|_|\\___/ \\__|" << std::endl;
std::cout << " | | | | " << std::endl;
std::cout << " |_| |_| " << std::endl;
// ADA std::cout << "☷ Version: \t" << PACKAGE_VERSION << std::endl;
//std::cout << "☷ Git: \t\t" << GIT_VERSION << std::endl;
//std::cout << "☷ Build Date: \t" << BUILD_DATE << std::endl;
std::cout << "\e[0m";
std::cout << std::endl;
}
parseInputFile(known_expr_funcs);
MPI_Barrier(MPI_COMM_WORLD);
setup(known_expr_funcs);
}
// here the control flow starts to diverge
if ( comm_->isOptimizer() ) { startOptimizer(); }
else if ( comm_->isWorker() ) { startWorker(); }
else if ( comm_->isPilot() ) { startPilot(); }
Pilot(CmdArguments_t args, boost::shared_ptr<Comm_t> comm,
functionDictionary_t known_expr_funcs,
const DVarContainer_t &dvar,
const Expressions::Named_t &obj,
const Expressions::Named_t &cons)
: Poller(comm->mpiComm())
, comm_(comm)
, cmd_args_(args)
, objectives_(obj)
, constraints_(cons)
, dvars_(dvar)
{
setup(known_expr_funcs);
}
~Pilot()
......@@ -175,6 +165,35 @@ private:
boost::scoped_ptr<Trace> job_trace_;
void setup(functionDictionary_t known_expr_funcs) {
global_rank_ = comm_->globalRank();
if(global_rank_ == 0) {
std::cout << "\033[01;35m";
std::cout << " _ _ _ _ " << std::endl;
std::cout << " | | (_) | | | " << std::endl;
std::cout << " ___ _ __ | |_ ______ _ __ _| | ___ | |_ " << std::endl;
std::cout << " / _ \\| '_ \\| __|______| '_ \\| | |/ _ \\| __|" << std::endl;
std::cout << "| (_) | |_) | |_ | |_) | | | (_) | |_ " << std::endl;
std::cout << " \\___/| .__/ \\__| | .__/|_|_|\\___/ \\__|" << std::endl;
std::cout << " | | | | " << std::endl;
std::cout << " |_| |_| " << std::endl;
// ADA std::cout << "☷ Version: \t" << PACKAGE_VERSION << std::endl;
//std::cout << "☷ Git: \t\t" << GIT_VERSION << std::endl;
//std::cout << "☷ Build Date: \t" << BUILD_DATE << std::endl;
std::cout << "\e[0m";
std::cout << std::endl;
}
parseInputFile(known_expr_funcs);
MPI_Barrier(MPI_COMM_WORLD);
// here the control flow starts to diverge
if ( comm_->isOptimizer() ) { startOptimizer(); }
else if ( comm_->isWorker() ) { startWorker(); }
else if ( comm_->isPilot() ) { startPilot(); }
}
void parseInputFile(functionDictionary_t known_expr_funcs) {
try {
......@@ -643,4 +662,4 @@ void run() {
};
#endif
#endif
\ No newline at end of file
......@@ -146,6 +146,8 @@ struct OpalDataImpl {
bool isInOPALEnvMode_m;
bool isInOPALThickTrackerMode_m;
bool isInPrepState_m;
std::vector<std::string> arguments_m;
};
......@@ -802,3 +804,14 @@ std::vector<std::string> OpalData::getAllNames() {
return result;
}
void OpalData::storeArguments(int argc, char *argv[]) {
p->arguments_m.clear();
for (int i = 0; i < argc; ++ i) {
p->arguments_m.push_back(argv[i]);
}
}
std::vector<std::string> OpalData::getArguments() {
return p->arguments_m;
}
\ No newline at end of file
......@@ -259,6 +259,8 @@ public:
void setMaxTrackSteps(unsigned long long s);
void incMaxTrackSteps(unsigned long long s);
void storeArguments(int argc, char *argv[]);
std::vector<std::string> getArguments();
private:
static bool isInstantiated;
......@@ -277,4 +279,4 @@ private:
//extern OpalData OPAL;
#endif // OPAL_OpalData_HH
#endif // OPAL_OpalData_HH
\ No newline at end of file
......@@ -33,6 +33,12 @@
#include "Expressions/SValue.h"
#include "Utilities/OpalException.h"
#include "AbstractObjects/OpalData.h"
#include "ValueDefinitions/RealVariable.h"
#include "Utilities/Util.h"
#include <boost/regex.hpp>
using std::string;
using namespace Expressions;
......@@ -294,16 +300,46 @@ namespace Attributes {
std::string getString(const Attribute &attr) {
if(AttributeBase *base = &attr.getBase()) {
std::string expr;
if(dynamic_cast<String *>(&attr.getHandler())) {
return dynamic_cast<SValue<std::string> *>(base)->evaluate();
expr = dynamic_cast<SValue<std::string> *>(base)->evaluate();
} else if(SValue<SRefAttr<std::string> > *ref =
dynamic_cast<SValue<SRefAttr<std::string> > *>(base)) {
const SRefAttr<std::string> &value = ref->evaluate();
return value.evaluate();
expr = value.evaluate();
} else {
throw OpalException("Attributes::getString()", "Attribute \"" +
attr.getName() + "\" is not string.");
}
auto opal = OpalData::getInstance();
boost::regex variableRE("\\$\\{(.*?)\\}");
boost::smatch what;
std::string exprDeref;
std::string::const_iterator start = expr.begin();
std::string::const_iterator end = expr.end();
while (boost::regex_search(start, end, what, variableRE, boost::match_default)) {
exprDeref += std::string(start, what[0].first);
std::string variable = Util::toUpper(std::string(what[1].first, what[1].second));
if (Object *obj = opal->find(variable)) {
std::ostringstream value;
RealVariable *real = static_cast<RealVariable*>(obj);
real->printValue(value);
exprDeref += value.str();
} else {
exprDeref += std::string(what[0].first, what[0].second);
}
start = what[0].second;
}
exprDeref += std::string(start, end);
return exprDeref;
} else {
return std::string();
}
......@@ -335,7 +371,37 @@ namespace Attributes {
std::vector<std::string> getStringArray(const Attribute &attr) {
if(AttributeBase *base = &attr.getBase()) {
if(dynamic_cast<StringArray *>(&attr.getHandler())) {
return dynamic_cast<AValue<std::string>*>(base)->evaluate();
auto opal = OpalData::getInstance();
boost::regex variableRE("\\$\\{(.*?)\\}");
boost::smatch what;
std::vector<std::string> value = dynamic_cast<AValue<std::string>*>(base)->evaluate();
for (auto expr: value) {
std::string exprDeref;
std::string::const_iterator start = expr.begin();
std::string::const_iterator end = expr.end();
while (boost::regex_search(start, end, what, variableRE, boost::match_default)) {
exprDeref += std::string(start, what[0].first);
std::string variable = Util::toUpper(std::string(what[1].first, what[1].second));
if (Object *obj = opal->find(variable)) {
std::ostringstream value;
RealVariable *real = static_cast<RealVariable*>(obj);
real->printValue(value);
exprDeref += value.str();
} else {
exprDeref += std::string(what[0].first, what[0].second);
}
start = what[0].second;
}
expr = exprDeref + std::string(start, end);
}
return value;
} else {
throw OpalException("Attributes::getStringArray()", "Attribute \"" +
attr.getName() + "\" is not a string array.");
......@@ -453,4 +519,4 @@ namespace Attributes {
attr.set(new AValue<std::list<Token> >(value));
}
}
}
\ No newline at end of file
......@@ -20,12 +20,8 @@
#include "Ippl.h"
#include "Attributes/Attributes.h"
#include "AbstractObjects/Object.h"
#include "AbstractObjects/OpalData.h"
#include <cstdlib>
#include <boost/regex.hpp>
#include <boost/algorithm/string.hpp>
// Class PSystem
// ------------------------------------------------------------------------
......@@ -56,28 +52,6 @@ PSystem *PSystem::clone(const std::string &name) {
void PSystem::execute() {
std::string command = Attributes::getString(itsAttr[0]);
boost::regex variablesRe("\\$\\$\\{([^\\}]+?)\\}");
boost::smatch match;
OpalData *opal = OpalData::getInstance();
while (boost::regex_search(command, match, variablesRe)) {
Object *object = 0;
std::string variableName = match[1];
boost::to_upper(variableName);
if ((object = opal->find(variableName)) == 0) {
ERRORMSG("SYSTEM: Could not replace $${" << match[1] << "}, "
<< "unknown variable" << endl);
std::string unknownReplacement = "\\\\$\\\\${" + match[1] + "}";
boost::regex unknownRe("\\$\\$\\{" + match[1] + "\\}");
command = boost::regex_replace(command, unknownRe, unknownReplacement);
continue;
}
std::ostringstream os;
object->printValue(os);
boost::regex variableRe("\\$\\$\\{" + match[1] + "\\}");
command = boost::regex_replace(command, variableRe, os.str());
}
int res = system(command.c_str());
if (res!=0)
......
......@@ -20,12 +20,8 @@
#include "Ippl.h"
#include "Attributes/Attributes.h"
#include "AbstractObjects/Object.h"
#include "AbstractObjects/OpalData.h"
#include <cstdlib>
#include <boost/regex.hpp>
#include <boost/algorithm/string.hpp>
// Class System
// ------------------------------------------------------------------------
......@@ -57,28 +53,6 @@ System *System::clone(const std::string &name) {
void System::execute() {
if (Ippl::myNode() == 0) {
std::string command = Attributes::getString(itsAttr[0]);
boost::regex variablesRe("\\$\\$\\{([^\\}]+?)\\}");
boost::smatch match;