void demo() { printf("Demo: Stacked mode\n"); printf("- Multiple 2D CA are run as layers within a 3D CA\n"); if (info->matrix_depth == 1) { printf("ERROR: A matrix depth of 2 or greater is required\n"); return; } write_lut(lut_to_2D(LUT_XOR), 0); printf("Same init state for each layer:\n"); for (int z = 0; z < info->matrix_depth; z++) { for (int i = 0; i < 1; i++) { write_state(i,i,z, 1); } } swap_run_swap(); print_states(); printf("Different init state for each layer:\n"); for (int z = 0; z < info->matrix_depth; z++) { for (int i = 0; i < z; i++) { write_state(i,i,z, 1); } } swap_run_swap(); print_states(); }
void test() { /* Matrix: * 0 1 0 * 0 | 0 * 1 & 1 * 0 1 0 */ printf("Test: Sblock Matrix\n"); write_lut(LUT_SELF, 0); write_lut(LUT_AND4, 1); write_lut(LUT_OR, 2); write_type(0,1,1, 2); write_type(0,2,1, 1); write_state(0,0,1, 1); write_state(0,2,0, 1); write_state(0,2,2, 1); write_state(0,3,1, 1); swap_cell_storage(); config(); step(1); readback(); swap_cell_storage(); read_state(0,0,1); read_state(0,1,1); read_state(0,2,1); read_state(0,3,1); step(1); readback(); swap_cell_storage(); read_state(0,0,1); read_state(0,1,1); read_state(0,2,1); read_state(0,3,1); assert_uint32(1, get_state()); assert_uint32(1, get_state()); assert_uint32(0, get_state()); assert_uint32(1, get_state()); assert_uint32(1, get_state()); assert_uint32(1, get_state()); assert_uint32(1, get_state()); assert_uint32(1, get_state()); }
void queue::push(const ioremap::elliptics::data_pointer &d) { auto found = m_chunks.find(m_state.chunk_id_push); if (found == m_chunks.end()) { // create new empty chunk ioremap::elliptics::session tmp = m_client.create_session(); auto p = std::make_shared<chunk>(tmp, m_queue_id, m_state.chunk_id_push, m_chunk_max); auto inserted = m_chunks.insert(std::make_pair(m_state.chunk_id_push, p)); found = inserted.first; } int chunk_id = found->first; auto chunk = found->second; if (chunk->push(d)) { LOG_INFO("chunk %d filled", chunk_id); ++m_state.chunk_id_push; write_state(); chunk->add(&m_statistics.chunks_pushed); } ++m_statistics.push_count; }
/* uuid_create -- generator a UUID */ int uuid_create(uuid_t * uuid) { uuid_time_t timestamp, last_time; unsigned16 clockseq; uuid_node_t node; uuid_node_t last_node; int f; /* acquire system wide lock so we're alone */ LOCK; /* get current time */ get_current_time(×tamp); /* get node ID */ get_ieee_node_identifier(&node); /* get saved state from NV storage */ f = read_state(&clockseq, &last_time, &last_node); /* if no NV state, or if clock went backwards, or node ID changed (e.g., net card swap) change clockseq */ if (!f || memcmp(&node, &last_node, sizeof(uuid_node_t))) clockseq = true_random(); else if (timestamp < last_time) clockseq++; /* stuff fields into the UUID */ format_uuid_v1(uuid, clockseq, timestamp, node); /* save the state for next time */ write_state(clockseq, timestamp, node); UNLOCK; return(1); };
void queue::clear() { LOG_INFO("clearing queue"); LOG_INFO("erasing state"); queue_state state = m_state; memset(&m_state, 0, sizeof(m_state)); write_state(); LOG_INFO("removing chunks, from %d to %d", state.chunk_id_ack, state.chunk_id_push); std::map<int, shared_chunk> remove_list; remove_list.swap(m_chunks); remove_list.insert(m_wait_ack.cbegin(), m_wait_ack.cend()); m_wait_ack.clear(); for (auto i = remove_list.cbegin(); i != remove_list.cend(); ++i) { int chunk_id = i->first; auto chunk = i->second; chunk->remove(); } remove_list.clear(); LOG_INFO("dropping statistics"); clear_counters(); LOG_INFO("queue cleared"); }
void DAILY_XFER_HISTORY::poll() { static double last_time= 0; if (!dirty) return; if (gstate.now - last_time < DAILY_XFER_HISTORY_PERIOD) return; last_time = gstate.now; write_state(); }
void write_full_state(const DIGT_SGRID::index_t gt, const unsigned ref_gt, std::ostream& os) { write_state(gt,ref_gt,os); os << "_" << get_het_count(gt); if(is_strand_state(gt)) os << "_strand"; }
int main(void) { write_state(); read_state(); printf("\n"); printf("State properly reset, generated random numbers are correct\n\n"); exit(0); }
int main() { // Model, Domain and Boundary const auto flow = std::make_unique<Flow>("Couette3D"); const auto lbmodel = flow->get_lbmodel(); const auto domain = flow->get_domain(); const auto boundary = flow->get_boundary(); // Define problem and its data const auto problem = std::make_unique<PLBPD>(lbmodel, domain, boundary); auto simdata = SimData(domain->get_dimensions(), lbmodel->get_num_directions()); // Solve problem problem->initialize(simdata); simdata.write_state("init_state.h5"); problem->march_in_time(flow->get_num_timesteps(), simdata); simdata.write_state("final_state.h5"); problem->print_times(); }
double GSLOptimizer::evaluate(const gsl_vector *v) { /* set model state */ write_state(v); /* get score */ double score= get_scoring_function()->evaluate(false); best_score_=std::min(score, best_score_); if (score < stop_score_) { throw AllDone(); } return score; }
void slice_set::write(const string& file, const scheduler_type type, vm::all *all) const { write_state(file, all); write_work_queue(file, all); write_processed_facts(file, all); write_sent_facts(file, all); write_stolen_nodes(file, all); write_steal_requests(file, all); if(is_priority_sched(type)) write_priority_queue(file, all); }
/** * Handle USER command * @param cmd Command with args * @param state Current client connection state */ void ftp_user(Command *cmd, State *state) { User user; if(get_user(cmd->arg,users,&user)>=0){ state->user = user; state->username_ok = 1; state->message = "331 User name okay, need password\n"; }else{ state->message = "530 Invalid username\n"; } write_state(state); }
// Write a whole StateSet in one go. The optional argument sort_order can be // given to write states in an order different from their order in the // StateSet (for example, in order of increasing energy). void Datafile::write_stateset(StateSet const& stateset, int step, std::list<size_t> const* sort_order) { hsize_t states_cur_size[2]; hsize_t state_history_cur_size[1]; try { ensure_states_data(); ensure_state_history_data(); // calculate current size of states_data states_data.getSpace().getSimpleExtentDims(states_cur_size); // new slot for states will be same as states_cur_size[0] const hsize_t new_slot = states_cur_size[0]; state_history_pair pair; pair.step = step; pair.index = static_cast<int>(new_slot); // calculate current size of state_history_data and extend by one state_history_data.getSpace().getSimpleExtentDims(state_history_cur_size); hsize_t new_size = state_history_cur_size[0]+1; state_history_data.extend(&new_size); space_1d.setExtentSimple(1, &new_size); space_1d.selectElements(H5S_SELECT_SET, 1, state_history_cur_size); validate_selection(space_1d); // record what was the step when states were saved state_history_data.write(&pair, state_history_type, scalar_space, space_1d); // write states const size_t N = stateset.get_num_states(); if (sort_order == NULL) for (size_t m=0; m<N; m++) write_state(new_slot, m, stateset[m]); else { std::list<size_t>::const_iterator it = sort_order->begin(); for (size_t m=0; m<N; m++) { write_state(new_slot, m, stateset[*it]); it++; } } } catch(H5::Exception& e) { e.printError(); throw; } }
/** * Generates response message for client * @param cmd Current command * @param state Current connection state */ void response(Command *cmd, State *state) { switch(lookup_cmd(cmd->command)){ case USER: ftp_user(cmd,state); break; case PASS: ftp_pass(cmd,state); break; case PASV: ftp_pasv(cmd,state); break; case LIST: ftp_list(cmd,state); break; case CWD: ftp_cwd(cmd,state); break; case PWD: ftp_pwd(cmd,state); break; case MKD: ftp_mkd(cmd,state); break; case RMD: ftp_rmd(cmd,state); break; case RETR: ftp_retr(cmd,state); break; case STOR: ftp_stor(cmd,state); break; case DELE: ftp_dele(cmd,state); break; case SIZE: ftp_size(cmd,state); break; case ABOR: ftp_abor(state); break; case QUIT: ftp_quit(state); break; case TYPE: ftp_type(cmd,state); break; case CDUP: ftp_cdup(state); break; case HELP: ftp_help(cmd, state); break; case NLST: ftp_nlst(cmd, state); break; case RNFR: ftp_rnfr(cmd, state); break; case RNTO: ftp_rnto(cmd, state); break; case APPE: ftp_appe(cmd, state); break; case NOOP: if(state->logged_in){ state->message = "200 Zzz...\n"; }else{ state->message = "530 Please login with USER and PASS\n"; } write_state(state); break; default: state->message = "500 Unknown command\n"; write_state(state); break; } }
/** PASS command */ void ftp_pass(Command *cmd, State *state) { if(state->username_ok==1){ if (strcmp(state->user.password,cmd->arg)==0 || strlen(state->user.password)==0) { state->logged_in = 1; state->message = "230 Login successful\n"; chdir(state->user.root); } else { state->message = "500 Invalid username or password\n"; } }else{ state->message = "530 Invalid username\n"; } write_state(state); }
double GSLOptimizer::optimize(unsigned int iter, const gsl_multimin_fminimizer_type*t, double ms, double mxs) { fis_= get_optimized_attributes(); best_score_=std::numeric_limits<double>::max(); unsigned int n= get_dimension(); if (n ==0) { IMP_LOG(TERSE, "Nothing to optimize" << std::endl); return get_scoring_function()->evaluate(false); } gsl_multimin_fminimizer *s=gsl_multimin_fminimizer_alloc (t, n); gsl_vector *x= gsl_vector_alloc(get_dimension()); update_state(x); gsl_vector *ss= gsl_vector_alloc(get_dimension()); gsl_vector_set_all(ss, mxs); gsl_multimin_function f= internal::create_f_function_data(this); gsl_multimin_fminimizer_set (s, &f, x, ss); try { int status; do { --iter; //update_state(x); status = gsl_multimin_fminimizer_iterate(s); if (status) { IMP_LOG(TERSE, "Ending optimization because of state " << s << std::endl); break; } double sz= gsl_multimin_fminimizer_size(s); status= gsl_multimin_test_size(sz, ms); update_states(); if (status == GSL_SUCCESS) { IMP_LOG(TERSE, "Ending optimization because of small size " << sz << std::endl); break; } } while (status == GSL_CONTINUE && iter >0); } catch (AllDone){ } gsl_vector *ret=gsl_multimin_fminimizer_x (s); best_score_=gsl_multimin_fminimizer_minimum (s); write_state(ret); gsl_multimin_fminimizer_free (s); gsl_vector_free (x); return best_score_; }
int core::run() { // writes the config and process id to file write_state(); quit_mainloop=0; while (!quit_mainloop && term_signal==0 && quit_signal==0) { // wait for a job to run... job * this_job=NULL; result* this_result=NULL; try { this_job=wait_for_input(); } catch (job_exception je) { this_result=new error_result(job_counter,je); } if (quit_mainloop!=0 || term_signal!=0) { if (this_job!=NULL) delete this_job; break; } // do the work ... if (this_job!=NULL) { this_result=do_the_job(*this_job); if (term_signal!=0) { delete this_job; if (this_result!=NULL) delete this_result; break; } } else this_job=new job(job_counter); if (this_result==NULL) { this_result=new error_result(job_counter,"unexpected: did not get any result"); } // tell them... write_to_output(*this_job,*this_result); delete this_result; delete this_job; job_counter++; } // deletes config file remove_state(); return 0; }
double GSLOptimizer::evaluate_derivative(const gsl_vector *v, gsl_vector *df) { /* set model state */ write_state(v); /* get score */ double score= get_scoring_function()->evaluate(true); best_score_=std::min(score, best_score_); if (score < stop_score_) { throw AllDone(); } /* get derivatives */ { for (unsigned int i=0; i< fis_.size(); ++i) { double d= get_scaled_derivative(fis_[i]); gsl_vector_set(df, i, d); } } return score; }
static int sched_switch_handler(struct trace_seq *s, struct tep_record *record, struct event_format *event, void *context) { struct format_field *field; unsigned long long val; if (tep_get_field_val(s, event, "prev_pid", record, &val, 1)) return trace_seq_putc(s, '!'); field = tep_find_any_field(event, "prev_comm"); if (field) { write_and_save_comm(field, record, s, val); trace_seq_putc(s, ':'); } trace_seq_printf(s, "%lld ", val); if (tep_get_field_val(s, event, "prev_prio", record, &val, 0) == 0) trace_seq_printf(s, "[%d] ", (int) val); if (tep_get_field_val(s, event, "prev_state", record, &val, 0) == 0) write_state(s, val); trace_seq_puts(s, " ==> "); if (tep_get_field_val(s, event, "next_pid", record, &val, 1)) return trace_seq_putc(s, '!'); field = tep_find_any_field(event, "next_comm"); if (field) { write_and_save_comm(field, record, s, val); trace_seq_putc(s, ':'); } trace_seq_printf(s, "%lld", val); if (tep_get_field_val(s, event, "next_prio", record, &val, 0) == 0) trace_seq_printf(s, " [%d]", (int) val); return 0; }
void queue::ack(const entry_id id) { auto found = m_wait_ack.find(id.chunk); if (found == m_wait_ack.end()) { LOG_ERROR("ack for chunk %d (pos %d) which is not in waiting list", id.chunk, id.pos); return; } auto chunk = found->second; chunk->ack(id.pos); if (chunk->meta().acked() == chunk->meta().low_mark()) { // Real end of the chunk's lifespan, all popped entries are acked m_wait_ack.erase(found); chunk->add(&m_statistics.chunks_popped); // Chunk would be uncomplete here only if its the only chunk in the queue // (filled partially and serving both as a push and a pop/ack target) if (chunk->meta().complete()) { chunk->remove(); LOG_INFO("chunk %d complete", id.chunk); } // Set chunk_id_ack to the lowest active chunk //NOTE: its important to have m_chunks and m_wait_ack both sorted m_state.chunk_id_ack = m_state.chunk_id_push; if (!m_chunks.empty()) { m_state.chunk_id_ack = std::min(m_state.chunk_id_ack, m_chunks.begin()->first); } if (!m_wait_ack.empty()) { m_state.chunk_id_ack = std::min(m_state.chunk_id_ack, m_wait_ack.begin()->first); } write_state(); } ++m_statistics.ack_count; }
void gb_save_state(VIRTUAL_FILE *fd, byte *buf) { const int tbl_ram[]={1,1,1,4,16,8}; // 0と1は保険 #ifdef CHEAT_SUPPORT if (buf || fd) cheat_decreate_cheat_map(); #endif write_state(fd, &rom_get_info()->gb_type,sizeof(int)); if (rom_get_info()->gb_type<=2){ // normal gb & sgb write_state(fd, cpu_get_ram(),0x2000); // ram write_state(fd, cpu_get_vram(),0x2000); // vram write_state(fd, get_sram(),tbl_ram[rom_get_info()->ram_size]*0x2000); // sram write_state(fd, cpu_get_oam(),0xA0); write_state(fd, cpu_get_stack(),0x80); int page,ram_page; page=(mbc_get_rom()-get_rom())/0x4000; ram_page=(mbc_get_sram()-get_sram())/0x2000; write_state(fd, &page,sizeof(int)); // rom_page write_state(fd, &ram_page,sizeof(int)); // ram_page int dmy=0; write_state(fd, cpu_get_c_regs(),sizeof(struct cpu_regs)); // cpu_reg write_state(fd, &g_regs,sizeof(struct gb_regs));//sys_reg int halt=((*cpu_get_halt())?1:0); write_state(fd, &halt,sizeof(int)); write_state(fd, &dmy,sizeof(int)); // 元の版ではシリアル通信通信満了までのクロック数 // (通信の仕様が大幅に変わったためダミーで埋めている) int mbc_dat=mbc_get_state(); write_state(fd, &mbc_dat,sizeof(int));//MBC int ext_is=mbc_is_ext_ram()?1:0; write_state(fd, &ext_is,sizeof(int)); // ver 1.1 追加 write_state(fd, apu_get_stat_cpu(),sizeof(struct apu_stat)); write_state(fd, apu_get_mem(),0x30); write_state(fd, apu_get_stat_gen(),sizeof(struct apu_stat)); byte resurved[256]; memset(resurved,0,256); write_state(fd, resurved,256);//将来のために確保 // RIN拡張 if(now_gb_mode==2){ write_state(fd, &sgb_mode, sizeof(int)); write_state(fd, &bit_received, sizeof(int)); write_state(fd, &bits_received, sizeof(int)); write_state(fd, &packets_received, sizeof(int)); write_state(fd, &sgb_state, sizeof(int)); write_state(fd, &sgb_index, sizeof(int)); write_state(fd, &sgb_multiplayer, sizeof(int)); write_state(fd, &sgb_fourplayers, sizeof(int)); write_state(fd, &sgb_nextcontrol, sizeof(int)); write_state(fd, &sgb_readingcontrol, sizeof(int)); write_state(fd, &sgb_mask, sizeof(int)); write_state(fd, sgb_palette, sizeof(unsigned short)*8*16); write_state(fd, sgb_palette_memory, sizeof(unsigned short)*512*4); write_state(fd, sgb_buffer, 7*16); write_state(fd, sgb_ATF, 18*20); write_state(fd, sgb_ATF_list, 45*20*18); /* sceIoWrite(fd, sgb_border, 2048); sceIoWrite(fd, sgb_borderchar, 32*256); int i, j, n=0; for (i=0; i<224; i++){ for (j=0; j<256; j++){ if (i>=40 && i<=183 && j==48) j=208; border_tmp[n++] = sgb_border_buffer[i*256+j]; } } sceIoWrite(fd, border_tmp, sizeof(border_tmp)); */ } } else if (rom_get_info()->gb_type>=3){ // GB Colour / GBA write_state(fd, cpu_get_ram(),0x2000*4); // ram write_state(fd, cpu_get_vram(),0x2000*2); // vram write_state(fd, get_sram(),tbl_ram[rom_get_info()->ram_size]*0x2000); // sram write_state(fd, cpu_get_oam(),0xA0); write_state(fd, cpu_get_stack(),0x80); int cpu_dat[16]; cpu_save_state(cpu_dat); int page,ram_page; page=(mbc_get_rom()-get_rom())/0x4000; ram_page=(mbc_get_sram()-get_sram())/0x2000; write_state(fd, &page,sizeof(int)); // rom_page write_state(fd, &ram_page,sizeof(int)); // ram_page write_state(fd, cpu_dat+0,sizeof(int));//int_page //color write_state(fd, cpu_dat+1,sizeof(int));//vram_page //color int dmy=0; write_state(fd, cpu_get_c_regs(),sizeof(struct cpu_regs)); // cpu_reg write_state(fd, &g_regs,sizeof(struct gb_regs));//sys_reg write_state(fd, &cg_regs,sizeof(struct gbc_regs));//col_reg //color write_state(fd, lcd_get_pal(0),sizeof(word)*(8*4*2));//palette //color int halt=((*cpu_get_halt())?1:0); write_state(fd, &halt,sizeof(int)); write_state(fd, &dmy,sizeof(int)); // 元の版ではシリアル通信通信満了までのクロック数 int mbc_dat=mbc_get_state(); write_state(fd, &mbc_dat,sizeof(int));//MBC int ext_is=mbc_is_ext_ram()?1:0; write_state(fd, &ext_is,sizeof(int)); //その他諸々 write_state(fd, cpu_dat+2,sizeof(int)); //color write_state(fd, cpu_dat+3,sizeof(int)); //color write_state(fd, cpu_dat+4,sizeof(int)); //color write_state(fd, cpu_dat+5,sizeof(int)); //color write_state(fd, cpu_dat+6,sizeof(int)); //color write_state(fd, cpu_dat+7,sizeof(int)); //color // ver 1.1 追加 write_state(fd, apu_get_stat_cpu(),sizeof(struct apu_stat)); write_state(fd, apu_get_mem(),0x30); write_state(fd, apu_get_stat_gen(),sizeof(struct apu_stat)); byte resurved[256],reload=1; memset(resurved,0,256); // resurved[0]=1; write_state(fd, &reload,1); write_state(fd, resurved,256);//将来のために確保 } #ifdef CHEAT_SUPPORT if (buf || fd) cheat_create_cheat_map(); #endif return; }
void resetAll() { if (LOG) printf(" starting reset\n"); currentGeneration = 0; write_state(sta_file_selector, 10); write_state(sta_file_variator, 8); if (LOG) printf(" variator, selector states 8, 10\n"); while(1){ if (read_state(sta_file_variator) != 9) { write_state(sta_file_variator, 8); }; if (read_state(sta_file_selector) != 11) { write_state(sta_file_selector, 10); }; if (read_state(sta_file_variator) == 9 && read_state(sta_file_selector) == 11) { updateVariatorSeed(); write_state(ini_file_variator,0); // make ini file ready for writing write_state(sta_file_variator, 0); if (LOG) printf(" variator state 0\n"); if (LOG) printf(" currentGeneration = %d \n",currentGeneration); break; }; wait(poll); } while(1) { if (read_state(sta_file_variator) == 1) { copyInitialPop(); write_state(arc_file_selector,0); // make arc file ready for write write_state(sel_file_selector,0); // make sel file ready for write write_state(sta_file_selector, 1); if (LOG) printf(" ini_pop done; selector state 1\n"); break; }; wait(poll); } while(1) { if (read_state(sta_file_selector) == 2) { copyArchiveSelected(); appendOutput(); write_state(var_file_variator,0); // make var file ready for write write_state(sta_file_variator, 2); if (LOG) printf(" selection done; variator state 2\n"); break; }; wait(poll); } return; }
size_t gb_save_state(byte *out) { const int tbl_ram[]={1,1,1,4,16,8}; // 0と1は保険 const int has_bat[]={0,0,0,1,0,0,1,0,0,1,0,0,1,1,0,1,1,0,0,1,0,0,0,0,0,0,0,1,0,1,1,0}; // 0x20以下 byte *outbak = out; if (outbak) cheat_decreate_cheat_map(); write_state(&rom_get_info()->gb_type,sizeof(int),out,outbak); if (rom_get_info()->gb_type<=2){ // normal gb & sgb write_state(cpu_get_ram(),0x2000,out,outbak); // ram write_state(cpu_get_vram(),0x2000,out,outbak); // vram write_state(get_sram(),tbl_ram[rom_get_info()->ram_size]*0x2000,out,outbak); // sram write_state(cpu_get_oam(),0xA0,out,outbak); write_state(cpu_get_stack(),0x80,out,outbak); int page,ram_page; page=(mbc_get_rom()-get_rom())/0x4000; ram_page=(mbc_get_sram()-get_sram())/0x2000; write_state(&page,sizeof(int),out,outbak); // rom_page write_state(&ram_page,sizeof(int),out,outbak); // ram_page int dmy=0; write_state(cpu_get_c_regs(),sizeof(struct cpu_regs),out,outbak); // cpu_reg write_state(&g_regs,sizeof(struct gb_regs),out,outbak);//sys_reg int halt=((*cpu_get_halt())?1:0); write_state(&halt,sizeof(int),out,outbak); write_state(&dmy,sizeof(int),out,outbak); // 元の版ではシリアル通信通信満了までのクロック数 // (通信の仕様が大幅に変わったためダミーで埋めている) int mbc_dat=mbc_get_state(); write_state(&mbc_dat,sizeof(int),out,outbak);//MBC int ext_is=mbc_is_ext_ram()?1:0; write_state(&ext_is,sizeof(int),out,outbak); // ver 1.1 追加 write_state(apu_get_stat_cpu(),sizeof(struct apu_stat),out,outbak); write_state(apu_get_mem(),0x30,out,outbak); write_state(apu_get_stat_gen(),sizeof(struct apu_stat),out,outbak); byte resurved[256]; memset(resurved,0,256); write_state(resurved,256,out,outbak);//将来のために確保 // RIN拡張 if(now_gb_mode==2){ write_state(&sgb_mode, sizeof(int),out,outbak); write_state(&bit_received, sizeof(int),out,outbak); write_state(&bits_received, sizeof(int),out,outbak); write_state(&packets_received, sizeof(int),out,outbak); write_state(&sgb_state, sizeof(int),out,outbak); write_state(&sgb_index, sizeof(int),out,outbak); write_state(&sgb_multiplayer, sizeof(int),out,outbak); write_state(&sgb_fourplayers, sizeof(int),out,outbak); write_state(&sgb_nextcontrol, sizeof(int),out,outbak); write_state(&sgb_readingcontrol, sizeof(int),out,outbak); write_state(&sgb_mask, sizeof(int),out,outbak); write_state(sgb_palette, sizeof(unsigned short)*8*16,out,outbak); write_state(sgb_palette_memory, sizeof(unsigned short)*512*4,out,outbak); write_state(sgb_buffer, 7*16,out,outbak); write_state(sgb_ATF, 18*20,out,outbak); write_state(sgb_ATF_list, 45*20*18,out,outbak); } } else if (rom_get_info()->gb_type>=3){ // GB Colour / GBA write_state(cpu_get_ram(),0x2000*4,out,outbak); // ram write_state(cpu_get_vram(),0x2000*2,out,outbak); // vram write_state(get_sram(),tbl_ram[rom_get_info()->ram_size]*0x2000,out,outbak); // sram write_state(cpu_get_oam(),0xA0,out,outbak); write_state(cpu_get_stack(),0x80,out,outbak); int cpu_dat[16]; cpu_save_state(cpu_dat); int page,ram_page; page=(mbc_get_rom()-get_rom())/0x4000; ram_page=(mbc_get_sram()-get_sram())/0x2000; write_state(&page,sizeof(int),out,outbak); // rom_page write_state(&ram_page,sizeof(int),out,outbak); // ram_page write_state(cpu_dat+0,sizeof(int),out,outbak);//int_page //color write_state(cpu_dat+1,sizeof(int),out,outbak);//vram_page //color int dmy=0; write_state(cpu_get_c_regs(),sizeof(struct cpu_regs),out,outbak); // cpu_reg write_state(&g_regs,sizeof(struct gb_regs),out,outbak);//sys_reg write_state(&cg_regs,sizeof(struct gbc_regs),out,outbak);//col_reg //color //save the gbc palette write_state(lcd_get_pal_addr(),sizeof(word)*(8*4*2),out,outbak);//palette //color int halt=((*cpu_get_halt())?1:0); write_state(&halt,sizeof(int),out,outbak); write_state(&dmy,sizeof(int),out,outbak); // 元の版ではシリアル通信通信満了までのクロック数 int mbc_dat=mbc_get_state(); write_state(&mbc_dat,sizeof(int),out,outbak);//MBC int ext_is=mbc_is_ext_ram()?1:0; write_state(&ext_is,sizeof(int),out,outbak); //その他諸々 write_state(cpu_dat+2,sizeof(int),out,outbak); //color write_state(cpu_dat+3,sizeof(int),out,outbak); //color write_state(cpu_dat+4,sizeof(int),out,outbak); //color write_state(cpu_dat+5,sizeof(int),out,outbak); //color write_state(cpu_dat+6,sizeof(int),out,outbak); //color write_state(cpu_dat+7,sizeof(int),out,outbak); //color // ver 1.1 追加 write_state(apu_get_stat_cpu(),sizeof(struct apu_stat),out,outbak); write_state(apu_get_mem(),0x30,out,outbak); write_state(apu_get_stat_gen(),sizeof(struct apu_stat),out,outbak); byte resurved[256],reload=1; memset(resurved,0,256); // resurved[0]=1; write_state(&reload,1,out,outbak); write_state(resurved,256,out,outbak);//将来のために確保 } if(outbak) cheat_create_cheat_map(); return out-outbak; }
int main(int argc, char **argv) { //print usage if needed if (argc != 2) { fprintf(stderr, "Usage: %s totalRecordNumber\n", argv[0]); exit(0); } //get total record number from argument int totalRecordNumber = atoi(argv[1]); // time the program struct timeval sysTimeStart, sysTimeEnd; gettimeofday(&sysTimeStart, NULL); // set up directories; mkdir("cities", 0777); mkdir("datestamps", 0777); mkdir("messages", 0777); mkdir("states", 0777); mkdir("timestamps", 0777); mkdir("users", 0777); mkdir("bplus", 0777); // set up some counters, etc. unsigned int recordCount = 0, userCount = 0, cityCount = 0, stateCount = 0, timestampCount = 0, datestampCount = 0, messageCount = 0, i,j; // SET UP HASH TABLES FOR CITIES, STATES, TIMESTAMPS, DATESTAMPS // cities city_node *cityHT[HASH_SIZE]; for (i = 0; i < HASH_SIZE; i++) { cityHT[i] = malloc(sizeof(city_node)); cityHT[i] = NULL; } // states state_node *stateHT[HASH_SIZE]; for (i = 0; i < HASH_SIZE; i++) { stateHT[i] = malloc(sizeof(state_node)); stateHT[i] = NULL; } // timestamps timestamp_node *timestampHT[HASH_SIZE]; for (i = 0; i < HASH_SIZE; i++) { timestampHT[i] = malloc(sizeof(timestamp_node)); timestampHT[i] = NULL; } // datestamps datestamp_node *datestampHT[HASH_SIZE]; for (i = 0; i < HASH_SIZE; i++) { datestampHT[i] = malloc(sizeof(datestamp_node)); datestampHT[i] = NULL; } // LOOP OVER RECORD FILES char filename[1024]; FILE *fp = NULL; for (i = 0; i < totalRecordNumber; i++) { //open the corresponding file sprintf(filename, "record_%06d.dat", i); fp = fopen(filename,"rb"); if (!fp) { fprintf(stderr, "Cannot open %s\n", filename); continue; } record_t *record = read_record(fp); // split location into city and state, as best we can char cityStr[TEXT_SHORT]; char stateStr[TEXT_SHORT]; // there's one record where the location is \0, which strtok breaks on if (record->location[0] == '\0') { strncpy(cityStr, "", TEXT_SHORT); strncpy(stateStr, "", TEXT_SHORT); } else { char loc[TEXT_SHORT]; strncpy(loc, record->location, TEXT_SHORT); strncpy(cityStr, strtok(loc, ","), TEXT_SHORT); strncpy(stateStr, strtok(NULL, ","), TEXT_SHORT); } // create state state_t state; strncpy(state.name, stateStr, TEXT_SHORT); // get stateId from hash if we have it already unsigned int stateHash = hash_state(&state) % HASH_SIZE; state_node *s; int stateId = -1; for(s = stateHT[stateHash]; (s != NULL) && (stateId == -1); s = s->next) { if (compare_states(&state, &(s->state)) == 0) { stateId = s->state.stateId; } } // assign stateId, add to hash table, and write file if we don't have it if (stateId == -1) { state.stateId = stateCount; stateId = stateCount; write_state(stateCount, &state); stateCount++; s = malloc(sizeof(state_node)); s->state = state; s->next = stateHT[stateHash]; stateHT[stateHash] = s; } // create city city_t city; city.stateId = stateId; strncpy(city.name, cityStr, TEXT_SHORT); // get cityId from hash if we have it already unsigned int cityHash = hash_city(&city) % HASH_SIZE; city_node *c; int cityId = -1; for(c = cityHT[cityHash]; (c != NULL) && (cityId == -1); c = c->next) { if (compare_cities(&city, &(c->city)) == 0) { cityId = c->city.cityId; } } // assign cityId, add to hash table, and write file if we don't have it if (cityId == -1) { city.cityId = cityCount; cityId = cityCount; write_city(cityCount, &city); cityCount++; c = malloc(sizeof(city_node)); c->city = city; c->next = cityHT[cityHash]; cityHT[cityHash] = c; } // create and write user user_t user; user.userId = record->id; user.cityId = cityId; user.stateId = stateId; strncpy(user.name, record->name, TEXT_SHORT); write_user(userCount, &user); userCount++; // loop over messages for(j = 0; j < record->message_num; j++) { // create timestamp timestamp_t timestamp; timestamp.hour = record->messages[j].hour; timestamp.minute = record->messages[j].minute; // get timestampId from hash if we have it already unsigned int timestampHash = hash_timestamp(×tamp) % HASH_SIZE; timestamp_node *t; int tsId = -1; for(t = timestampHT[timestampHash]; (t != NULL) && (tsId == -1); t = t->next) { if (compare_timestamps(×tamp, &(t->timestamp)) == 0) { tsId = t->timestamp.timestampId; } } // assign timestampId, add to hash table, and write file if we don't have it if (tsId == -1) { timestamp.timestampId = timestampCount; tsId = timestampCount; write_timestamp(timestampCount, ×tamp); timestampCount++; t = malloc(sizeof(timestamp_node)); t->timestamp = timestamp; t->next = timestampHT[timestampHash]; timestampHT[timestampHash] = t; } // create datestamp datestamp_t datestamp; datestamp.year = record->messages[j].year; datestamp.month = record->messages[j].month; datestamp.day = record->messages[j].day; // get datestampId from hash if we have it already unsigned int datestampHash = hash_datestamp(&datestamp) % HASH_SIZE; datestamp_node *d; int dsId = -1; for(d = datestampHT[datestampHash]; (d != NULL) && (dsId == -1); d = d->next) { if (compare_datestamps(&datestamp, &(d->datestamp)) == 0) { dsId = d->datestamp.datestampId; } } // assign datestampId, add to hash table, and write file if we don't have it if (dsId == -1) { datestamp.datestampId = datestampCount; dsId = datestampCount; write_datestamp(datestampCount, &datestamp); datestampCount++; d = malloc(sizeof(datestamp_node)); d->datestamp = datestamp; d->next = datestampHT[datestampHash]; datestampHT[datestampHash] = d; } // create and write message message_t message; strncpy(message.text, record->messages[j].text, TEXT_LONG); message.userId = user.userId; message.timestampId = tsId; message.datestampId = dsId; message.messageId = messageCount; write_message(messageCount, &message); messageCount++; } // free and close record free_record(record); fclose(fp); } // free city nodes city_node *cNode; for (i = 0; i < HASH_SIZE; i++) { cNode = cityHT[i]; while (cNode != NULL) { city_node* tmp = cNode; cNode = cNode->next; free (tmp); } } // free state nodes state_node *sNode; for (i = 0; i < HASH_SIZE; i++) { sNode = stateHT[i]; while (sNode != NULL) { state_node* tmp = sNode; sNode = sNode->next; free (tmp); } } // free timestamp nodes timestamp_node *tNode; for (i = 0; i < HASH_SIZE; i++) { tNode = timestampHT[i]; while (tNode != NULL) { timestamp_node* tmp = tNode; tNode = tNode->next; free (tmp); } } // free datestamp nodes datestamp_node *dNode; for (i = 0; i < HASH_SIZE; i++) { dNode = datestampHT[i]; while (dNode != NULL) { datestamp_node* tmp = dNode; dNode = dNode->next; free (tmp); } } // create, write, print file count information file file_count_t fc; fc.users = userCount; fc.cities = cityCount; fc.states = stateCount; fc.messages = messageCount; fc.timestamps = timestampCount; fc.datestamps = datestampCount; write_file_count(&fc); print_file_count(&fc); // end timing the program gettimeofday(&sysTimeEnd, NULL); float totaltime2 = (sysTimeEnd.tv_sec - sysTimeStart.tv_sec) + (sysTimeEnd.tv_usec - sysTimeStart.tv_usec) / 1000000.0f; printf("Process time %f seconds\n", totaltime2); return 0; }
void leimkuhler_tree(double maxtime) { int i; const double tinterval = 1.0; float time_start, time_end; if (verbosity > 0) { fprintf(err, "Using leimkuhler_tree integrator.\n" "TIME_CAP: %3i\n", TIME_CAP); fprintf(err, "-------------------------------------------------\n"); } /*======================================================================== * Calculate the initial forces and time steps, start the integrator * by first drifting. *======================================================================*/ for (i=0; i < NPARTICLES; i++) lkACCEL_AND_POTENTIAL(ps[i], 0); for (i=0; i < NPARTICLES; i++) { double h2 = sqrt(SELECT_TIME_STEP(ps[i])); DRIFT(ps[i], h2); ps[i]->time = 0; ps[i]->timeNext = h2; } write_state(0); /*======================================================================== * Put each particle into the priority queue *======================================================================*/ struct pqNode *head = ps[0]; for (i=1; i < NPARTICLES; i++) { struct pqNode *p = ps[i]; PQ_MERGE(head, p); } pTree *tree; tree = pintBuildTree(ps, NULL); #if 1 time_start = CPUTIME; for (i=0; i < 50000; i++) tree = pintBuildTree(ps, NULL); time_end = CPUTIME; #endif #if DYNAMIC_TREE //fprintf(err, "tree->cell.fMass = %e\n", tree->cell.fMass); #endif fprintf(err, "comparisonCount = %i\n", comparisonCount); fprintf(err, "nodeCount = %i\n", nodeCount); fprintf(err, "tree construction time = %e\n", (time_end - time_start) / 50000.); //fprintf(err, "tree construction time = %e\n", (time_end - time_start) ); //assert(tree->cell.fMass == 1.0); #if 0 #if DYNAMIC_TREE int len = walk_tree(tree, NULL, 0); fprintf(err, "\n"); #else int len = walk_tree(tree, ps, 0); fprintf(err, "\n"); #endif #endif #if 0 #if DYNAMIC_TREE fprintf(err, "\n\n"); struct pqNode **ps2 = (struct pqNode **)malloc(NPARTICLES * sizeof(struct pqNode *)); int len = walk_tree(tree, ps2, 0); fprintf(err, "len = %i\n", len); assert(len == NPARTICLES); struct pqNode *ps3 = (struct pqNode *)malloc(NPARTICLES * sizeof(struct pqNode)); assert(ps3 != NULL); for (i=0; i < NPARTICLES; i++) memcpy(&(ps3[i]), ps2[i], sizeof(struct pqNode)); for (i=0; i < NPARTICLES; i++) ps2[i] = &(ps3[i]); time_start = CPUTIME; for (i=0; i < 5000; i++) tree = pintBuildTree(ps2, NULL); time_end = CPUTIME; fprintf(err, "tree->cell.fMass = %e\n", tree->cell.fMass); fprintf(err, "tree construction time = %e\n", (time_end - time_start) / 5000.); #endif #endif //assert(tree->cell.fMass == 1.0); return; /*======================================================================== * Run the simulation *======================================================================*/ double prevtimeNext = 0; double tout = tinterval; fflush(out); fflush(err); RESET_ACCEL_HIST(); while (1) { struct pqNode *p; PQ_REMOVE_MIN(head, p); assert(prevtimeNext <= p->timeNext); prevtimeNext = p->timeNext; fprintf(out, "%i %f %f %f\n", p->id, p->r[0], p->r[1], p->r[2]); fflush(out); /*==================================================================== * Write output *==================================================================*/ if (p->timeNext < tout && tout <= head->timeNext) { tout += tinterval; RESET_ACCEL_HIST(); for (i=0; i < NPARTICLES; i++) ACCEL_HIST(ps[i]->a); write_state(p->timeNext); AccelCount = 0; if (p->timeNext < maxtime && maxtime <= head->timeNext) break; #if !DYNAMIC_TREE //tree = pintBuildTree2(ps, tree); tree = pintBuildTree(ps, NULL); #endif } /*==================================================================== * Drift, Kick, Drift *==================================================================*/ double h1 = p->timeNext - p->time; DRIFT(p, h1); lkACCEL_AND_POTENTIAL(p, p->timeNext); KICK(p, h1); double h2 = SELECT_TIME_STEP(p) / h1; KICK(p, h2); DRIFT(p, h2); /*==================================================================== * Update particle's time and put it back in the queue *==================================================================*/ p->time = p->timeNext + h2; p->timeNext = p->time + h2; #if DYNAMIC_TREE _DA_ time_start = CPUTIME; tree = tree_update(p, tree); _DA_ time_end = CPUTIME; _DA_ fprintf(err, "tree update time = %e\n", time_end - time_start); #endif #if 0 #if DYNAMIC_TREE _DA_ time_start = CPUTIME; tree = tree_insert(p, tree); _DA_ time_end = CPUTIME; _DA_ fprintf(err, "tree insert time = %e\n", time_end - time_start); #endif #endif PQ_MERGE(head, p); } }
int main(int argc, char *argv[]) { int current_state = 0; int monitor_state = 1; /* polling variator (0) or selector (1) */ int variator_terminated = 0; int selector_terminated = 0; if (argc == 8) { sscanf(argv[1], "%s", parnamebase_variator); sscanf(argv[2], "%s", filenamebase_variator); sscanf(argv[3], "%s", parnamebase_selector); sscanf(argv[4], "%s", filenamebase_selector); sscanf(argv[5], "%s", parnamebase_monitor); sscanf(argv[6], "%s", filenamebase_monitor); sscanf(argv[7], "%lf", &poll); assert(poll >= 0); } else { printf("Monitor - wrong number of arguments:\n"); printf("monitor varPar varBase selPar selBase monPar monBase poll\n"); return (1); } /* generate file names based on 'filenamebase'*/ sprintf(var_file_variator, "%svar", filenamebase_variator); sprintf(sel_file_variator, "%ssel", filenamebase_variator); sprintf(cfg_file_variator, "%scfg", filenamebase_variator); sprintf(ini_file_variator, "%sini", filenamebase_variator); sprintf(arc_file_variator, "%sarc", filenamebase_variator); sprintf(sta_file_variator, "%ssta", filenamebase_variator); sprintf(var_file_selector, "%svar", filenamebase_selector); sprintf(sel_file_selector, "%ssel", filenamebase_selector); sprintf(cfg_file_selector, "%scfg", filenamebase_selector); sprintf(ini_file_selector, "%sini", filenamebase_selector); sprintf(arc_file_selector, "%sarc", filenamebase_selector); sprintf(sta_file_selector, "%ssta", filenamebase_selector); /* initialize common parameters */ alpha = 0; mu = 0; lambda = 0; dimension = 0; /* read and check common parameters (they should be equal)*/ read_common_parameters(cfg_file_variator); read_common_parameters(cfg_file_selector); /* read monitor parameters */ read_local_parameters(); /* seed random generator */ srand(seed); /* print information file of monitor */ printInformation(); for (currentRun = 0 ; currentRun < numberOfRuns; currentRun++ ) { if (LOG) printf("currentRun = %d \n",currentRun); resetAll(); for (currentGeneration = 1 ; currentGeneration <= numberOfGenerations; currentGeneration++ ) { if (LOG) printf(" currentGeneration = %d \n",currentGeneration); while(1) { if (read_state(sta_file_variator) == 3) { copyVariate(); write_state(sta_file_selector,3); if (LOG) printf(" variation done; selector state 3\n"); break; } wait(poll); } while(1) { if (read_state(sta_file_selector) == 2) { copyArchiveSelected(); appendOutput(); write_state(sta_file_variator, 2); if (LOG) printf(" selection done; variator state 2\n"); break; }; wait(poll); } } } if (LOG) printf("selector state 6 (kill)\n"); write_state(sta_file_selector, 6); while(1) { if (read_state(sta_file_selector) == 7) { if (LOG) printf("selector killed\n"); break; } wait(poll); } while(1) { if (read_state(sta_file_variator) == 3) { if (LOG) printf("variator state 4 (kill)\n"); write_state(sta_file_variator, 4); break; } wait(poll); } while(1) { if (read_state(sta_file_variator) == 5) { if (LOG) printf("variator killed\n"); break; } wait(poll); } if (LOG) printf("kill myself\n"); return (0); }
// Write the client_state.xml file // int CLIENT_STATE::write_state_file() { MFILE mf; int retval, ret1, ret2, attempt; #ifdef _WIN32 char win_error_msg[4096]; #endif for (attempt=1; attempt<=MAX_STATE_FILE_WRITE_ATTEMPTS; attempt++) { if (attempt > 1) boinc_sleep(1.0); if (log_flags.statefile_debug) { msg_printf(0, MSG_INFO, "[statefile] Writing state file" ); } #ifdef _WIN32 retval = mf.open(STATE_FILE_NEXT, "wc"); #else retval = mf.open(STATE_FILE_NEXT, "w"); #endif if (retval) { if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) { msg_printf(0, MSG_INTERNAL_ERROR, "Can't open %s: %s", STATE_FILE_NEXT, boincerror(retval) ); } if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue; return ERR_FOPEN; } MIOFILE miof; miof.init_mfile(&mf); ret1 = write_state(miof); ret2 = mf.close(); if (ret1) { if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Couldn't write state file: %s", boincerror(retval) ); } if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue; return ret1; } if (ret2) { if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue; return ret2; } // only attempt to rename the current state file if it exists. // if (boinc_file_exists(STATE_FILE_NAME)) { if (boinc_file_exists(STATE_FILE_PREV)) { retval = boinc_delete_file(STATE_FILE_PREV); if (retval) { if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) { #ifdef _WIN32 msg_printf(0, MSG_INFO, "Can't delete previous state file; %s", windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg)) ); #else msg_printf(0, MSG_INFO, "Can't delete previous state file: %s", strerror(errno) ); #endif } if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue; } } retval = boinc_rename(STATE_FILE_NAME, STATE_FILE_PREV); if (retval) { if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) { #ifdef _WIN32 msg_printf(0, MSG_INFO, "Can't rename current state file to previous state file; %s", windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg)) ); #else msg_printf(0, MSG_INFO, "Can't rename current state file to previous state file: %s", strerror(errno) ); #endif } if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue; } } retval = boinc_rename(STATE_FILE_NEXT, STATE_FILE_NAME); if (log_flags.statefile_debug) { msg_printf(0, MSG_INFO, "[statefile] Done writing state file" ); } if (!retval) break; // Success! if ((attempt == MAX_STATE_FILE_WRITE_ATTEMPTS) || log_flags.statefile_debug) { #ifdef _WIN32 msg_printf(0, MSG_INFO, "rename error: %s", windows_format_error_string(GetLastError(), win_error_msg, sizeof(win_error_msg)) ); #elif defined (__APPLE__) if (log_flags.statefile_debug) { system("ls -al /Library/Application\\ Support/BOINC\\ Data/client*.*"); } #endif } if (attempt < MAX_STATE_FILE_WRITE_ATTEMPTS) continue; return ERR_RENAME; } return 0; }