14 #if defined (USEBOOSTMPI) && defined (USELUA)
17 #include <boost/bind.hpp>
18 #include <boost/function.hpp>
19 #include <boost/lexical_cast.hpp>
21 #ifdef USEBOOSTSERIALIZE
22 #include <boost/archive/binary_oarchive.hpp>
27 #include <basic/options/option.hh>
28 #include <basic/options/keys/els.OptionKeys.gen.hh>
30 #include <utility/lua/LuaIterator.hh>
32 #include <utility/Factory.hh>
37 #include <basic/Tracer.hh>
43 static basic::Tracer
TR(
"protocols.elscripts.MPI_Master");
45 void lregister_MPI_Master( lua_State * lstate ) {
46 lregister_Master( lstate );
47 luabind::module(lstate,
"protocols")
49 luabind::namespace_(
"elscripts")
51 luabind::class_<MPI_Master, Master>(
"MPI_Master")
56 MPI_Master::MPI_Master( boost::mpi::communicator world, std::vector<int> slaves,
int num_trajectories, boost::uint64_t mem_limit, boost::uint64_t reserved_mem, boost::uint64_t reserved_mem_multiplier) :
58 last_status_sweep_time_( boost::posix_time::microsec_clock::universal_time() - boost::posix_time::minutes(100)),
60 Master( num_trajectories, mem_limit, reserved_mem, reserved_mem_multiplier) {
61 using namespace basic::options;
62 using namespace basic::options::OptionKeys;
66 boost::function< boost::uint64_t ()> ref_available_mem = boost::bind( &protocols::elscripts::MPI_Master::available_mem,
this );
74 (option[OptionKeys::els::num_traj]() / option[OptionKeys::els::traj_per_master]() ) +
75 (!( option[OptionKeys::els::num_traj]() % option[OptionKeys::els::traj_per_master]() == 0 ))
78 lregister_MPI_Master(lstate_);
79 luabind::globals(lstate_)[
"master"] =
this;
80 luabind::globals(lstate_)[
"rank"] = world_.rank();
82 instantiate_inputterstream();
85 void MPI_Master::go(){
86 using namespace utility::lua;
104 if ( ( boost::posix_time::microsec_clock::universal_time() - last_status_sweep_time_) > boost::posix_time::seconds(basic::options::option[basic::options::OptionKeys::els::shortest_wu]())){
105 for(
int i = 0; i < slaves_.size(); i++ ) {
106 if( ! slave_comm_->has_open_status( slaves_[i] ) ) {
111 slave_comm_->send_status_request( slaves_[i] );
114 last_status_sweep_time_ = boost::posix_time::microsec_clock::universal_time();
119 if( mpicounter_ >= 10000000 ) {
121 if ( ( boost::posix_time::microsec_clock::universal_time() - last_generate_initial_wu_time_) > boost::posix_time::seconds( 60 )){
125 int m = luaL_dostring ( lstate_,
"loop_every()" );
127 TR <<
"calling lua function loop_every() failed. Error is:" << std::endl;
128 TR << lua_tostring(lstate_, -1) << std::endl;
131 last_generate_initial_wu_time_ = boost::posix_time::microsec_clock::universal_time();
137 slave_comm_->act_on_status_response( ref_slave_initiate_wu_sendrecv );
145 if( castattempt != 0 ) {
149 luabind::globals(lstate_)[
"traj_env"][traj_idx_][
"pipemap"] = castattempt->pipemap().lock();
150 luabind::globals(lstate_)[
"traj_env"][traj_idx_][
"state"] = castattempt->state().lock();
156 " local _ENV = traj_env[)" + boost::lexical_cast<
std::string>(traj_idx_) +
"(]\n"
157 " if wu_done.)"+wuname+
"( == nil then\n"
158 " wu_done.)"+wuname+
"( = 0\n"
160 " wu_done.)"+wuname+
"( = wu_done.)"+wuname+
"( + 1\n"
161 " els_setenv(_ENV)\n"
162 " els.workunits.)"+wuname+
"DELIM(.proceed_on_master()\n"
165 int err = luaL_dostring ( lstate_, action.c_str() );
167 TR <<
"Calling lua function for workunit " << wuname <<
" proceed_on_master fxn failed. Error is:" << std::endl;
168 TR << lua_tostring(lstate_, -1) << std::endl;
171 luabind::globals(lstate_)[
"traj_env"][traj_idx_][
"pipemap"] = luabind::nil;
172 luabind::globals(lstate_)[
"traj_env"][traj_idx_][
"state"] = luabind::nil;
173 lua_gc(lstate_, LUA_GCCOLLECT, 0);
185 slave_comm_->cleanup_reqs();