14 #if defined (USEBOOSTMPI) && defined (USELUA)
18 #include <boost/bind.hpp>
19 #include <boost/function.hpp>
23 #include <basic/Tracer.hh>
28 void lregister_MPI_Slave( lua_State * lstate ) {
29 lregister_Slave( lstate );
30 luabind::module(lstate,
"protocols")
32 luabind::namespace_(
"elscripts")
34 luabind::class_<MPI_Slave, Slave>(
"MPI_Slave")
39 static basic::Tracer
TR(
"protocols.elscripts.MPI_Slave");
41 MPI_Slave::MPI_Slave( boost::mpi::communicator world,
int master, boost::uint64_t mem_limit, boost::uint64_t reserved_mem, boost::uint64_t reserved_mem_multiplier) :
43 Slave( master, mem_limit, reserved_mem, reserved_mem_multiplier) {
46 boost::function< boost::uint64_t ()> ref_available_mem = boost::bind( &protocols::elscripts::MPI_Slave::available_mem,
this );
50 lregister_MPI_Slave(lstate_);
51 luabind::globals(lstate_)[
"slave"] =
this;
52 luabind::globals(lstate_)[
"rank"] = world_.rank();
56 using namespace utility::lua;
63 master_comm_->check_and_act_clearcommand();
64 master_comm_->check_and_act_status_request( ref_listen_wu_sendrecv );
68 while( mem_limit_ - current_mem() < 2 * reserved_mem_ ) {
73 master_comm_->check_and_act_status_request( ref_listen_wu_sendrecv );
74 master_comm_->cleanup_reqs();
89 "setmetatable(tmp_run_env, {__index = _G })\n"
91 int err = luaL_dostring ( lstate_, action.c_str() );
93 TR <<
"Creating tmp namespace for run_on_slave() on slave failed. Error is:" << std::endl;
94 TR << lua_tostring(lstate_, -1) << std::endl;
99 luabind::globals(lstate_)[
"tmp_run_env"][
"pipemap"] = castattempt->pipemap().lock();
100 luabind::globals(lstate_)[
"tmp_run_env"][
"state"] = castattempt->state().lock();
101 luabind::globals(lstate_)[
"tmp_run_env"][
"traj_idx"] = castattempt->trajectory_idx();
105 "els_setenv(tmp_run_env)\n"
106 "els.workunits.)"+wuname+
"DELIM(.run_on_slave()\n"
107 "tmp_run_env = {} -- delete tmp_env after calling run_on_slave()\n"
109 err = luaL_dostring ( lstate_, action.c_str() );
111 TR <<
"Calling lua function for workunit " << wuname <<
" run_on_slave fxn failed. Error is:" << std::endl;
112 TR << lua_tostring(lstate_, -1) << std::endl;
115 lua_gc(lstate_, LUA_GCCOLLECT, 0);
118 master_comm_->outq().push_back( result_wu );
126 master_comm_->cleanup_reqs();