17 #include <boost/bind.hpp>
18 #include <boost/function.hpp>
22 #include <basic/Tracer.hh>
27 void lregister_Slave( lua_State * lstate ) {
28 lregister_BaseRole( lstate );
29 luabind::module(lstate,
"protocols")
31 luabind::namespace_(
"elscripts")
33 luabind::class_<Slave, BaseRole>(
"Slave")
38 static basic::Tracer
TR(
"protocols.elscripts.Slave");
40 Slave::Slave(
int master, boost::uint64_t mem_limit, boost::uint64_t reserved_mem, boost::uint64_t reserved_mem_multiplier) :
42 BaseRole( mem_limit, reserved_mem, reserved_mem_multiplier) {
45 boost::function< boost::uint64_t ()> ref_available_mem = boost::bind( &protocols::elscripts::Slave::available_mem,
this );
50 lregister_Slave(lstate_);
51 luabind::globals(lstate_)[
"slave"] =
this;
52 luabind::globals(lstate_)[
"rank"] = 0;
54 register_calculators();
56 instantiate_scorefxns();
57 instantiate_filters();
60 instantiate_workunits();
64 using namespace utility::lua;
67 if( ! master_comm_->inq().empty() ) {
77 "setmetatable(tmp_run_env, {__index = _G })\n"
79 int err = luaL_dostring ( lstate_, action.c_str() );
81 TR <<
"Creating tmp namespace for run_on_slave() on slave failed. Error is:" << std::endl;
82 TR << lua_tostring(lstate_, -1) << std::endl;
87 luabind::globals(lstate_)[
"tmp_run_env"][
"pipemap"] = castattempt->pipemap().lock();
88 luabind::globals(lstate_)[
"tmp_run_env"][
"state"] = castattempt->state().lock();
89 luabind::globals(lstate_)[
"tmp_run_env"][
"traj_idx"] = castattempt->trajectory_idx();
93 "els_setenv(tmp_run_env)\n"
94 "els.workunits.)"+wuname+
"DELIM(.run_on_slave()\n"
95 "tmp_run_env = {} -- delete tmp_env after calling run()\n"
97 err = luaL_dostring ( lstate_, action.c_str() );
99 TR <<
"Calling lua function for workunit " << wuname <<
" run_on_slave fxn failed. Error is:" << std::endl;
100 TR << lua_tostring(lstate_, -1) << std::endl;
103 lua_gc(lstate_, LUA_GCCOLLECT, 0);
106 master_comm_->outq().push_back( result_wu );