void EventDriven::Setup(void(*init_cb)()) { for (int i=0; i<TIMER_TOTAL; i++) { m_old_time[i] = millis(); m_new_time[i] = millis(); m_timer[i] = 0; } init_cb(); }
static int launch_cb(struct skynet_context * context, void *ud, int type, int session, uint32_t source , const void * msg, size_t sz) { assert(type == 0 && session == 0); struct snlua *l = ud; skynet_callback(context, NULL, NULL); // 将消息处理函数置空,以免别的消息发过来 int err = init_cb(l, context, msg, sz); // 消息处理:通过 loader.lua 加载 lua 代码块 if (err) { skynet_command(context, "EXIT", NULL); } return 0; }
/* * Create a new cache based on the initializer callback init_cb. */ cache_t * cache_new(cache_init_cb_t init_cb) { cache_t *cache; if (!(cache = malloc(sizeof(cache_t)))) return NULL; init_cb(cache); pthread_mutex_init(&cache->mutex, NULL); return cache; }
// perform a heatbath int hb_update( struct site *lat , const struct hb_info HBINFO , const char *traj_name , const GLU_output storage , const char *output_details , const GLU_bool continuation ) { // counters size_t i ; // seed the parallel RNG char str[ 256 ] ; // strip the number in the infile if it has one char *pch = strtok( (char*)traj_name , "." ) ; sprintf( str , "%s.%zu.rand" , pch , Latt.flow ) ; if( continuation == GLU_FALSE ) { fprintf( stdout , "[UPDATE] initialising par_rng from pool\n" ) ; if( initialise_par_rng( NULL ) == GLU_FAILURE ) { return GLU_FAILURE ; } } else { fprintf( stdout , "[UPDATE] restarting from a previous trajectory\n" ) ; if( initialise_par_rng( str ) == GLU_FAILURE ) { return GLU_FAILURE ; } } // initialise the draughtboard struct draughtboard db ; if( init_cb( &db , LVOLUME , ND ) == GLU_FAILURE ) { return GLU_FAILURE ; } // this guy appears throughout the HB algorithm const double inverse_beta = NC/(HBINFO.beta) ; // give us some information fprintf( stdout , "[UPDATE] Performing %zu HB-OR iterations\n" , HBINFO.iterations ) ; fprintf( stdout , "[UPDATE] Themalising for %zu iterations\n" , HBINFO.therm ) ; fprintf( stdout , "[UPDATE] %zu over-relaxations per heatbath\n" , HBINFO.Nor ) ; fprintf( stdout , "[UPDATE] Saving every %zu iteration(s)\n" , HBINFO.Nsave ) ; fprintf( stdout , "[UPDATE] Using beta = %1.12f \n" , HBINFO.beta ) ; // thermalise start_timer( ) ; for( i = 0 ; i < HBINFO.therm ; i++ ) { update_lattice( lat , inverse_beta , db , HBINFO.Nor ) ; if( !(i&15) ) { fprintf( stdout , "\n[UPDATE] config %zu done \n" , i ) ; print_time() ; } } print_time( ) ; // iterate the number of runs const size_t start = Latt.flow ; for( i = Latt.flow ; i < HBINFO.iterations ; i++ ) { // perform a hb-OR step update_lattice( lat , inverse_beta , db , HBINFO.Nor ) ; // set the lattice flow // if we are saving the data print out the plaquette and write a file if( i%HBINFO.Nmeasure == 0 ) { // write out the plaquette fprintf( stdout , "[UPDATE] %zu :: {P} %1.12f \n" , i , av_plaquette( lat ) ) ; // write the temporal polyakov loop, (re,im) |L| const double complex L = poly( lat , ND-1 ) / ( LCU * NC ) ; fprintf( stdout , "[UPDATE] {L} ( %f , %f ) %f \n" , creal( L ) , cimag( L ) , cabs( L ) ) ; } // if we hit a save point we write out the configuration if( i%HBINFO.Nsave == 0 && i != start ) { // write a configuration sprintf( str , "%s.%zu" , traj_name , i ) ; write_configuration( lat , str , storage , output_details ) ; // write out the rng state sprintf( str , "%s.rand" , str ) ; write_par_rng_state( str ) ; } Latt.flow = i + 1 ; } // free the draughtboard free_cb( &db ) ; // tell us how long this generation took print_time() ; // free the rng free_par_rng( ) ; return GLU_SUCCESS ; }
int IupPlotSetFormula(Ihandle* ih, int sample_count, const char* formula, const char* init) { lua_State *L; int i, ds_index, ret_count = 1; double min, max, step, p, x, y; char formula_func[1024]; IFnL init_cb; iupASSERT(iupObjectCheck(ih)); if (!iupObjectCheck(ih)) return -1; /* must be an IupMatrix */ if (ih->iclass->nativetype != IUP_TYPECANVAS || !IupClassMatch(ih, "plot")) return -1; L = luaL_newstate(); luaL_openlibs(L); { const char* register_global = "function openpackage(ns)\n" " for n, v in pairs(ns) do _G[n] = v end\n" "end\n" "openpackage(math)\n"; luaL_dostring(L, register_global); } if (init) luaL_dostring(L, init); init_cb = (IFnL)IupGetCallback(ih, "FORMULAINIT_CB"); if (init_cb) init_cb(ih, L); lua_pushlightuserdata(L, ih); lua_setglobal(L, "plot"); if (IupGetInt(ih, "FORMULA_PARAMETRIC")) ret_count = 2; sprintf(formula_func, "function plot_formula(sample_index, %s)\n" " return %s\n" "end\n", ret_count == 2 ? "t" : "x", formula); if (luaL_dostring(L, formula_func) != 0) { ShowFormulaError(ih, L); lua_close(L); return -1; } min = IupGetDouble(ih, "FORMULA_MIN"); max = IupGetDouble(ih, "FORMULA_MAX"); step = (max - min) / (double)(sample_count - 1); IupPlotBegin(ih, 0); for (i = 0, p = min; i < sample_count; i++, p += step) { lua_getglobal(L, "plot_formula"); lua_pushinteger(L, i); lua_pushnumber(L, p); if (lua_pcall(L, 2, ret_count, 0) != 0) { ShowFormulaError(ih, L); lua_close(L); return -1; } if (!lua_isnumber(L, -1)) { const char* str_message = IupGetLanguageString("IUP_ERRORINVALIDFORMULA"); IupMessageError(IupGetDialog(ih), str_message); lua_close(L); return -1; } if (ret_count == 2) { if (!lua_isnumber(L, -2)) { const char* str_message = IupGetLanguageString("IUP_ERRORINVALIDFORMULA"); IupMessageError(IupGetDialog(ih), str_message); lua_close(L); return -1; } x = lua_tonumber(L, -2); y = lua_tonumber(L, -1); lua_pop(L, 2); /* remove the result from the stack */ } else { x = p; y = lua_tonumber(L, -1); lua_pop(L, 1); /* remove the result from the stack */ } IupPlotAdd(ih, x, y); } ds_index = IupPlotEnd(ih); lua_close(L); return ds_index; }
evgMrm::evgMrm(const std::string& id, volatile epicsUInt8* const pReg): mrf::ObjectInst<evgMrm>(id), irqStop0_queued(0), irqStop1_queued(0), irqExtInp_queued(0), m_syncTimestamp(false), m_buftx(id+":BUFTX",pReg+U32_DataBufferControl, pReg+U8_DataBuffer_base), m_id(id), m_pReg(pReg), m_acTrig(id+":AcTrig", pReg), m_evtClk(id+":EvtClk", pReg), m_softEvt(id+":SoftEvt", pReg), m_seqRamMgr(this), m_softSeqMgr(this) { try{ for(int i = 0; i < evgNumEvtTrig; i++) { std::ostringstream name; name<<id<<":TrigEvt"<<i; m_trigEvt.push_back(new evgTrigEvt(name.str(), i, pReg)); } for(int i = 0; i < evgNumMxc; i++) { std::ostringstream name; name<<id<<":Mxc"<<i; m_muxCounter.push_back(new evgMxc(name.str(), i, this)); } for(int i = 0; i < evgNumDbusBit; i++) { std::ostringstream name; name<<id<<":Dbus"<<i; m_dbus.push_back(new evgDbus(name.str(), i, pReg)); } for(int i = 0; i < evgNumFrontInp; i++) { std::ostringstream name; name<<id<<":FrontInp"<<i; m_input[ std::pair<epicsUInt32, InputType>(i, FrontInp) ] = new evgInput(name.str(), i, FrontInp, pReg + U32_FrontInMap(i)); } for(int i = 0; i < evgNumUnivInp; i++) { std::ostringstream name; name<<id<<":UnivInp"<<i; m_input[ std::pair<epicsUInt32, InputType>(i, UnivInp) ] = new evgInput(name.str(), i, UnivInp, pReg + U32_UnivInMap(i)); } for(int i = 0; i < evgNumRearInp; i++) { std::ostringstream name; name<<id<<":RearInp"<<i; m_input[ std::pair<epicsUInt32, InputType>(i, RearInp) ] = new evgInput(name.str(), i, RearInp, pReg + U32_RearInMap(i)); } for(int i = 0; i < evgNumFrontOut; i++) { std::ostringstream name; name<<id<<":FrontOut"<<i; m_output[std::pair<epicsUInt32, evgOutputType>(i, FrontOut)] = new evgOutput(name.str(), i, FrontOut, pReg + U16_FrontOutMap(i)); } for(int i = 0; i < evgNumUnivOut; i++) { std::ostringstream name; name<<id<<":UnivOut"<<i; m_output[std::pair<epicsUInt32, evgOutputType>(i, UnivOut)] = new evgOutput(name.str(), i, UnivOut, pReg + U16_UnivOutMap(i)); } m_wdTimer = new wdTimer("Watch Dog Timer", this); m_timerEvent = new epicsEvent(); init_cb(&irqStop0_cb, priorityHigh, &evgMrm::process_eos0_cb, m_seqRamMgr.getSeqRam(0)); init_cb(&irqStop1_cb, priorityHigh, &evgMrm::process_eos1_cb, m_seqRamMgr.getSeqRam(1)); init_cb(&irqExtInp_cb, priorityHigh, &evgMrm::process_inp_cb, this); scanIoInit(&ioScanTimestamp); } catch(std::exception& e) { errlogPrintf("Error: %s\n", e.what()); } }