void create(void) { if (file_exists(DATAFILE)) { restore_me(); } else { /* Setup a list of default skills encase we do not have a list */ skills = ( { "combat/unarmed", "combat/defense", "combat/edge/small", "combat/edge/medium", "combat/edge/large", "combat/blunt/large", "combat/blunt/medium", "combat/blunt/small", "combat/sharp/small", "combat/sharp/medium", "combat/sharp/large", "language/catfolk", "language/dwarven", "language/elvish", "language/gnomish", "language/grunt", "spell/cure", "spell/missile", "value", } ); save_me(); }
std::pair<std::size_t,std::size_t> node_server::save(integer loc_id, std::string fname) const { static hpx::lcos::local::mutex mtx; std::size_t total_cnt = 0; std::size_t bytes_written = 0; std::list<hpx::future<std::pair<std::size_t,std::size_t>>> futs; integer nloc = hpx::find_all_localities().size(); if( my_location.level() == 0 && loc_id == 0 ) { if( file_exists( fname )) { std::string command = "rm "; command += fname; if(system( command.c_str())){} } for( integer i = 0; i != nloc; ++i) { auto this_name = fname + std::string(".") + std::to_string(integer(hpx::get_locality_id())); if( file_exists( this_name)) { std::string command = "rm "; command += this_name; if(system( command.c_str())){} } } } std::list<hpx::future<std::pair<std::size_t,std::size_t> >> sfuts; if( is_refined ) { for( auto i = children.begin(); i != children.end(); ++i) { sfuts.push_back( i->save(loc_id, fname)); } } { boost::lock_guard<hpx::lcos::local::mutex> file_lock(mtx); FILE* fp = fopen( (fname + std::string(".") + std::to_string(integer(hpx::get_locality_id()))).c_str(), "ab"); total_cnt++; bytes_written += my_location.save(fp); bytes_written += save_me(fp); fclose(fp); } if( is_refined ) { for( auto i = sfuts.begin(); i != sfuts.end(); ++i) { auto tmp = i->get(); total_cnt += tmp.first; bytes_written += tmp.second; } } if( loc_id == 0 && my_location.level() == 0) { FILE* fp = fopen("size.tmp2", "wb"); bytes_written += 2 * fwrite( &total_cnt, sizeof(integer), 1, fp) * sizeof(integer); std::size_t tmp = bytes_written + 2 * sizeof(std::size_t) + sizeof(real); bytes_written += 2 * fwrite( &tmp, sizeof(std::size_t), 1, fp)*sizeof(std::size_t); fclose( fp); my_system( "cp size.tmp2 size.tmp1\n"); fp = fopen("size.tmp1", "ab"); real omega = grid::get_omega(); bytes_written += fwrite( &omega, sizeof(real), 1, fp) * sizeof(real); fclose( fp); std::string command = "rm -r -f " + fname + "\n"; my_system (command); command = "cat size.tmp1 "; for( integer i = 0; i != nloc; ++i ) { command += fname + "." + std::to_string(integer(i)) + " "; } command += "size.tmp2 > " + fname + "\n"; my_system( command); command = "rm -f -r " + fname + ".*\n"; my_system( command); my_system( "rm -r -f size.tmp?\n"); printf( "Saved %i sub-grids with %lli bytes written\n", int(total_cnt), (long long)(bytes_written)); } return std::make_pair(total_cnt, bytes_written); }