CameraDefend::CameraDefend() { IwRandSeed((int32)s3eTimerGetMs()); for (int i = 0; i < DEFEND_TOUCHES_MAX; i++) { touch[i] = new DefendTouch; touch[i]->drawing = false; } dotTextureGreen = Iw2DCreateImage("textures/defending_dot/defending_dot.png"); dotTextureRed = Iw2DCreateImage("textures/defending_dot/defending_dot_red.png"); dotTexture = dotTextureGreen; dotAngle = 0; animTexturePress = new CIwTexture; animTexturePress->LoadFromFile("textures/defending_dot/defending_anim.png"); animTexturePress->Upload(); animMat = new CIwMaterial; animMat->SetTexture(animTexturePress); animMat->CreateAnim(); animMat->SetAnimCelW((double)animTexturePress->GetWidth()/cells); animMat->SetAnimCelH((double)animTexturePress->GetHeight()/rows); animMat->SetAnimCelPeriod(2); animTextureSuccess = new CIwTexture; animTextureSuccess->LoadFromFile("textures/defending_dot/defending_success.png"); animTextureSuccess->Upload(); animMatSuccess = new CIwMaterial; animMatSuccess->SetTexture(animTextureSuccess); animMatSuccess->CreateAnim(); animMatSuccess->SetAnimCelW((double)animTexturePress->GetWidth()/cellsSuccess); animMatSuccess->SetAnimCelH((double)animTexturePress->GetHeight()/rowsSuccess); animMatSuccess->SetAnimCelPeriod(2); reinit(); active = false; defended = false; }
void start() { mos_sem_init(&send_sem, 0); mos_mutex_init(&send_lock); reinit(); seqNo = 0; rseed = mos_node_id_get(); send_alarm.func = alarmCallback; send_alarm.reset_to = 0; simple_fs_init(); net_init(); deluge_init(); net_proto_register(77, topo_send, topo_recv, topo_ioctl); mos_command_daemon_init(); mos_register_function("getTopo", getTopo); mos_thread_new_havestack(mos_command_daemon, MOS_COMMANDER_STACK_SIZE, commander_stack, PRIORITY_NORMAL); mos_thread_new_havestack(sendThread, 192, send_stack, PRIORITY_NORMAL); }
static int handle_preemption(struct gl_hwdec *hw) { struct priv *p = hw->priv; if (!mp_vdpau_status_ok(p->ctx)) { mark_vdpau_objects_uninitialized(hw); return -1; } if (p->preemption_counter == p->ctx->preemption_counter) return 0; mark_vdpau_objects_uninitialized(hw); p->preemption_counter = p->ctx->preemption_counter; if (reinit(hw, &p->image_params) < 0) return -1; return 1; }
static bool test_format(struct gl_hwdec *hw) { struct priv *p = hw->priv; bool ok = false; struct mp_image_pool *alloc = mp_image_pool_new(1); va_pool_set_allocator(alloc, p->ctx, VA_RT_FORMAT_YUV420); struct mp_image *surface = mp_image_pool_get(alloc, IMGFMT_VAAPI, 64, 64); if (surface) { struct mp_image_params params = surface->params; if (reinit(hw, ¶ms) >= 0) { GLuint textures[4]; ok = map_image(hw, surface, textures) >= 0; } unref_image(hw); } talloc_free(surface); talloc_free(alloc); return ok; }
Frameset::Frameset(const Collapser *col, bool normalize) : m_empty(true), m_aggregated(false), m_collapser(col), m_normalize(normalize) { reinit(); /* We set everything up for aggregation collapsers */ if (m_collapser->get_criterion() != none && m_collapser->get_criterion() != all) { unsigned int len = 0; AggregationCollapser *col = (AggregationCollapser*)m_collapser; switch (m_collapser->get_criterion()) { case chpid: len = col->get_reference_chpids().size(); break; case devno: len = col->get_reference_devnos().size(); break; case wwpn: len = col->get_reference_wwpns().size(); break; case multipath_device: len = col->get_reference_mp_mms().size(); break; default: assert(false); } m_util_stats.resize(len); m_ioerr_stats.resize(len); m_blkiomon_stats.resize(len); m_zfcpdd_stats.resize(len); for (unsigned int i = 0; i < len; ++i) { init_utilization_wrapper(&m_util_stats[i]); m_ioerr_stats[i] = NULL; m_blkiomon_stats[i] = NULL; init_zfcpdd_wrapper(&m_zfcpdd_stats[i]); } } }
///////////////////////////////////////////////////////////////////////////// // Sends data byte to VFD // IN: data byte in <data> // OUT: returns < 0 if display not available or timed out ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_Data(u8 data) { current_lcd_device = mios32_lcd_device; RS_Set(1); RW_Set(0); E_Set(1); lastdata = (lastdata & 0x0F) + (data & 0xF0); MIOS32_BOARD_J15_DataSet(lastdata); E_Set(0); RS_Set(1); RW_Set(0); E_Set(1); lastdata = (lastdata & 0x0F) + (data << 4); MIOS32_BOARD_J15_DataSet(lastdata); E_Set(0); reinit(); return 0; // no error }
FontAtlas::FontAtlas(Font &theFont) : _font(&theFont) , _fontFreeType(nullptr) , _iconv(nullptr) , _currentPageData(nullptr) , _fontAscender(0) , _rendererRecreatedListener(nullptr) , _antialiasEnabled(true) , _currLineHeight(0) { _font->retain(); _fontFreeType = dynamic_cast<FontFreeType*>(_font); if (_fontFreeType) { _lineHeight = _font->getFontMaxHeight(); _fontAscender = _fontFreeType->getFontAscender(); _currentPage = 0; _currentPageOrigX = 0; _currentPageOrigY = 0; _letterEdgeExtend = 2; _letterPadding = 0; if (_fontFreeType->isDistanceFieldEnabled()) { _letterPadding += 2 * FontFreeType::DistanceMapSpread; } reinit(); #if CC_ENABLE_CACHE_TEXTURE_DATA auto eventDispatcher = Director::getInstance()->getEventDispatcher(); _rendererRecreatedListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, CC_CALLBACK_1(FontAtlas::listenRendererRecreated, this)); eventDispatcher->addEventListenerWithFixedPriority(_rendererRecreatedListener, 1); #endif } }
static VALUE rb_nkf_convert(VALUE obj, VALUE opt, VALUE src) { reinit(); StringValue(opt); nkf_split_options(RSTRING_PTR(opt)); if (!output_encoding) rb_raise(rb_eArgError, "no output encoding given"); switch (nkf_enc_to_index(output_encoding)) { case UTF_8_BOM: output_encoding = nkf_enc_from_index(UTF_8); break; case UTF_16BE_BOM: output_encoding = nkf_enc_from_index(UTF_16BE); break; case UTF_16LE_BOM: output_encoding = nkf_enc_from_index(UTF_16LE); break; case UTF_32BE_BOM: output_encoding = nkf_enc_from_index(UTF_32BE); break; case UTF_32LE_BOM: output_encoding = nkf_enc_from_index(UTF_32LE); break; } output_bom_f = FALSE; incsize = INCSIZE; input_ctr = 0; StringValue(src); input = (unsigned char *)RSTRING_PTR(src); i_len = RSTRING_LEN(src); result = rb_str_new(0, i_len*3 + 10); output_ctr = 0; output = (unsigned char *)RSTRING_PTR(result); o_len = RSTRING_LEN(result); *output = '\0'; kanji_convert(NULL); rb_str_set_len(result, output_ctr); OBJ_INFECT(result, src); rb_enc_associate(result, rb_nkf_enc_get(nkf_enc_name(output_encoding))); return result; }
JNL_HTTPGet::JNL_HTTPGet(JNL_AsyncDNS *dns, int recvbufsize, char *proxy) { m_recvbufsize=recvbufsize; m_dns=dns; m_con=NULL; m_http_proxylpinfo=0; m_http_proxyhost=0; m_http_proxyport=0; if (proxy && *proxy) { char *p=(char*)malloc(strlen(proxy)+1); if (p) { char *r=NULL; strcpy(p,proxy); do_parse_url(p,&m_http_proxyhost,&m_http_proxyport,&r,&m_http_proxylpinfo); free(r); free(p); } } m_sendheaders=NULL; reinit(); }
void launch(t_info *info) { int n_path; int index; index = 0; n_path = amount_path(info->list, info); info->path = (t_room ***)ft_memalloc((n_path + 1) * sizeof(t_room **)); get_addend(info->list)->distance = 0; while (index < n_path) { put_val(info, 0); if ((info->path[index] = find_path(info)) == NULL) break ; reinit(info->list); index++; } info->tab = fill_tab(info, n_path); write(1, "\n", 1); if (info->b_path == 1) print_path(info, n_path, info->t_size); launch2(info, n_path); }
bool Screen::newScenario() { bool ret = false; ScenarioInfo info( this ); if( info.exec() ) { ret = true; reinit(); theMap->newUnknownMap( info.getMapHeight(), info.getMapWidth() ); _players.clear(); setScenarioName( info.getName() ); setScenarioTheme( info.getTheme() ); setScenarioDescription( info.getDescription() ); setNbPlayer( info.getNbPlayer() ); setDateByType( 0, info.getDay() > 0 ? info.getDay() : 1 ); setDateByType( 1, 1 ); setDateByType( 2, info.getWeek() > 0 ? info.getWeek() : 1 ); setDateByType( 3, info.getMonth() > 0 ? info.getMonth() : 1); setDateByType( 4, info.getYear() > 0 ? info.getYear() : 1044); for( uint i = 0; i < info.getNbPlayer(); i++ ) { GenericPlayer * player = new GenericPlayer( theMap ); player->setNum( i ); player->setName( QString("Player %1").arg(i) ); _players.append( player ); } emit sig_redrawMap( theMap ); emit sig_enableGame( true ); //HACK to workaround some widget problems _miniMap->slot_mapviewResized( _view->width() / theMap->width(), _view->height() / theMap->height() ); layout()->update(); } return ret; }
bool WBOSC::init(ros::NodeHandle & nh, ControlModel & model, controlit::utility::ControlItParameters * controlitParameters, std::shared_ptr<Timer> timer) { // Ensure this WBOSC is initialized once assert(!initialized); // Save the pointer to the object holding WBC's parameters this->controlitParameters = controlitParameters; this->timer = timer; // Initialize the gravity compensation vector publisher gravityCompensationPublisher.init(nh, model.getActuatedJointNamesVector()); if (reinit(model)) { initialized = true; return true; } else return false; }
/*! Realize the tracking of the object in the image \throw vpException : if the tracking is supposed to have failed \param I : the input image */ void vpMbKltTracker::track(const vpImage<unsigned char>& I) { unsigned int nbInfos = 0; unsigned int nbFaceUsed = 0; try{ preTracking(I, nbInfos, nbFaceUsed); } catch(vpException &e){ throw e; } if(nbInfos < 4 || nbFaceUsed == 0){ vpERROR_TRACE("\n\t\t Error-> not enough data") ; throw vpTrackingException(vpTrackingException::notEnoughPointError, "\n\t\t Error-> not enough data"); } //vpColVector w; computeVVS(nbInfos, m_w); if(postTracking(I, m_w)) reinit(I); }
CameraScreen::CameraScreen(Camera * camera, Screen * screen, double screenDist): Camera(camera) { this->screen = screen; this->screenDist = screenDist; reinit(); }
random_generator::random_generator() { reinit(); }
void XFEMElementPairLocator::update() { reinit(); }
void *client_thread() { int nRet; CHAR *cBuf = (CHAR *) malloc(1); CHAR *cBuf2 = (CHAR *) malloc(40); CHAR *cBuf3 = (CHAR *) malloc(17); int rsize; int Rsize=1; int rsize2; int Rsize2=1; int rsize3; int Rsize3=1; int i; unsigned int servodata[8]={0}; networkCheck(); st_STARX_Session Sinfo; //============================= struct timeval starttime,endtime; gettimeofday(&starttime,0); // 登陆到P2P Server,一直阻塞到有客户端连进来,或者TimeOut到期 while(!g_s32Quit) { SessionHandle = STARX_Listen(MyDID, TimeOut_Sec, UDP_Port, 1,APILicense); if (SessionHandle >= 0) { //有合法客户端连入,取得合法会话句柄 printf("Connected\n"); control_thread_go=0; //go while(!control_thread_go){ usleep(1000); nRet =STARX_Check_Buffer(SessionHandle, VideoChannel, NULL, (UINT32 *) &rsize); STARX_Check_Buffer(SessionHandle, ControlChannel, NULL, (UINT32 *) &rsize2); STARX_Check_Buffer(SessionHandle, ServoChannel, NULL, (UINT32 *) &rsize3); if (nRet == ERROR_STARX_SESSION_CLOSED_TIMEOUT) { printf("control_thread, Session TimeOUT!!\n"); g_s32DoPlay=0; control_thread_go=1; } else if (nRet == ERROR_STARX_SESSION_CLOSED_REMOTE) { printf("control_thread, Session Remote Close!!\n"); g_s32DoPlay=0; control_thread_go=1; } else if (nRet == ERROR_STARX_INVALID_SESSION_HANDLE) { printf("control_thread, invalid session handle!!\n"); g_s32DoPlay=0; control_thread_go=1; } if (rsize > 0) { Rsize =rsize; STARX_Read(SessionHandle, VideoChannel, cBuf, &Rsize,100); if(cBuf[0]==1){ cBuf[0]=0; g_s32DoPlay=1; headflag=1; printf("call 264stream\r\n"); }else if(cBuf[0]=2){ pic.width=(cBuf[1]|cBuf[2]<<8); pic.height=(cBuf[3]|cBuf[4]<<8); fps=(int)cBuf[5]; brightness=(int)cBuf[6]; printf("%d %d %d %d\n",pic.width,pic.height,fps,brightness); reinit(); } } if (rsize2 > 0) { Rsize2 =rsize2; STARX_Read(SessionHandle, ControlChannel, cBuf2, &Rsize2,100); switch(cBuf2[4]){ case 201: //MSP_SET_RAW_GPS gps_mission_add( &ams,cBuf2); memset(cBuf2, 0, sizeof(cBuf2)); break; default: flock(fd_serial,LOCK_EX); if(!write(fd_serial,cBuf2,Rsize2)) printf("serial can't write\n"); flock(fd_serial, LOCK_UN); memset(cBuf2, 0, sizeof(cBuf2)); break; } } if(rsize3 > 0){ Rsize3=rsize3; STARX_Read(SessionHandle, ServoChannel, cBuf3, &Rsize3,100); if(Rsize3>0){ if(cBuf3[0]==0x53){ for(i=0;i<8;i++){ servodata[i]=(cBuf3[i*2+1]|cBuf3[i*2+2]<<8); } softPwmWrite(0,servodata[0]); softPwmWrite(1,servodata[1]); softPwmWrite(2,servodata[2]); softPwmWrite(3,servodata[3]); softPwmWrite(4,servodata[4]); softPwmWrite(5,servodata[5]); } gettimeofday(&starttime,0); } gettimeofday(&endtime,0); double timeuse=1000000*(endtime.tv_sec-starttime.tv_sec)+endtime.tv_usec-starttime.tv_usec; if((timeuse/=1000)>fallsafe_ms){ softPwmWrite(0,0); softPwmWrite(1,0); softPwmWrite(2,0); softPwmWrite(3,0); softPwmWrite(4,0); softPwmWrite(5,0); } memset(cBuf3, 0, sizeof(cBuf3)); } } STARX_Close(SessionHandle); printf("client exit\r\n"); } } if(thread[1]) pthread_join(thread[1],NULL); if(thread[2]) pthread_join(thread[2],NULL); STARX_DeInitialize(); printf("client_thread exit"); pthread_exit(0); }
void options_menu() { show_mouse(screen); DIALOG options_dialog[] = { /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */ {d_bitmap_proc, 0, 0,SCREEN_W,SCREEN_H,0,255, 0, 0, 0, 0, title_back}, {d_gamespeed_proc, 20, 10, 0, 0, 0, 0, 0,D_SELECTED, 0, 0, const_cast<char *>("gamespeed")}, {d_slider_proc, 300, 20, 30, 440, 0, 255, 0, 0, 255, get_config_int("MINER","BPS", 32) - 32, NULL, (void *)speedslider_callback}, {d_mapsize_proc, 20, 60, 0, 0, 0, 0, 0, 0, 0, 0, const_cast<char *>("mapsize")}, {d_slider_proc, 300, 20, 30, 440, 0, 255, 0,D_HIDDEN, 80, get_config_int("MINER","MAP_SIZE",20) - 20, NULL, (void *)mapsizeslider_callback}, {d_sound_proc, 20, 110, 0, 0, 0, 0, 0, 0, 0, 0, const_cast<char *>("sound")}, {d_slider_proc, 300, 40, 30, 300, 0, 255, 0,D_HIDDEN, 6, (int)log2(get_config_int("MINER","NR_OF_VOICES",0) + 1), NULL, (void *)soundslider_callback}, {d_text_proc, 300, 10, 200, 30, 0, 255, 0,D_HIDDEN, 0, 0, const_cast<char *>("Nr of simultaneous sounds")}, {d_number_proc, 330, 20, 0, 0, 0, 0, 0, 0, 3, get_config_int("MINER","BPS", 32), NULL}, {d_number_proc, 330, 20, 0, 0, 0, 0, 0,D_HIDDEN, 3, get_config_int("MINER","MAP_SIZE",20) , NULL}, {d_number_proc, 330, 40, 0, 0, 0, 0, 0,D_HIDDEN, 2, get_config_int("MINER","NR_OF_VOICES",1), NULL}, {d_back_proc, 20, 160, 0, 0, 0, 0, 0, 0, 0, 0, const_cast<char *>("exit menu")}, {NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL} }; the_options_dialog = options_dialog; // ugly, but I found it easier to initialise the dialog // within the function, where all BITMAPS's are loaded etc. PALETTE options_palette; for (int i=0;i < 256;i++) { options_palette[i].r = game_palette[i].g; options_palette[i].g = game_palette[i].b; options_palette[i].b = game_palette[i].r; } set_dialog_color(options_dialog, bestfit_color(options_palette,0,0,0), bestfit_color(options_palette,63,63,63)); DIALOG_PLAYER *p = init_dialog(options_dialog, 1); broadcast_dialog_message(MSG_DRAW, 0); // update_dialog(p); if (fade_speed) { fade_from(desktop_palette,options_palette,fade_speed); } else { set_palette(options_palette); } while(update_dialog(p)); shutdown_dialog(p); set_config_int("MINER","BPS", options_dialog[SPEED_SLIDER].d2 + 32); set_config_int("MINER","MAP_SIZE", options_dialog[MAPSIZE_SLIDER].d2 + 20); set_config_int("MINER","NR_OF_VOICES", (1<<options_dialog[SOUND_SLIDER].d2)); show_mouse(NULL); reinit(); return; }
random_generator::random_generator(const int & seed) { reinit(seed); }
Timer::Timer(void) { reinit(); }
GFXGLShaderConstHandle::GFXGLShaderConstHandle( GFXGLShader *shader, const GFXShaderConstDesc &desc, GLuint loc, S32 samplerNum ) : mShader(shader) { reinit(desc, loc, samplerNum); }
//----------------------------------------------------------------------------// void PixmapFont::setImageNamePrefix(const String& name_prefix) { d_resourceGroup = "*"; d_imageNamePrefix = name_prefix; reinit(); }
qryproc() { register QTREE *root; register QTREE *q; register int i; register int mode; register int result_num; register int retr_uniq; extern long AAccuread; extern long AAccuwrite; extern long AAccusread; extern int derror(); extern QTREE *trbuild(); extern QTREE *readqry(); # ifdef xDTM if (AAtTf(76, 1)) timtrace(23, 0); # endif # ifdef xDTR1 if (AAtTf(50, 0)) AAccuread = AAccusread = AAccuwrite = 0; # endif /* initialize query buffer */ initbuf(Qbuf, QBUFSIZ, QBUFFULL, derror); /* init various variables in decomp for start of this query */ startdecomp(); /* Read in query, range table and mode */ root = readqry(); mode = Qmode; /* Initialize relation descriptors */ initdesc(mode); /* re-build the tree */ root = trbuild(root); if (!root) derror(STACKFULL); /* locate pointers to QLEND and TREE nodes */ for (q = root->right; q->sym.type != QLEND; q = q->right) continue; Qle = q; for (q = root->left; q->sym.type != TREE; q = q->left) continue; Tr = q; /* map the complete tree */ mapvar(root, 0); /* set logical locks */ lockit(root, Resultvar); /* If there is no result variable then this must be a retrieve to the terminal */ Qry_mode = Resultvar < 0 ? (int) mdRETTERM : mode; /* if the mode is retrieve_unique, then make a result rel */ retr_uniq = mode == (int) mdRET_UNI; if (retr_uniq) { mk_unique(root); mode = (int) mdRETR; } /* get id of result relation */ if (Resultvar < 0) result_num = NORESULT; else result_num = Rangev[Resultvar].relnum; /* evaluate aggregates in query */ aggregate(root); /* decompose and process aggregate free query */ decomp(root, mode, result_num); /* If this is a retrieve unique, then retrieve results */ if (retr_uniq) pr_unique(root, Resultvar); if (mode != (int) mdRETR) i = ACK; else i = NOACK; i = endovqp(i); /* call update processor if batch mode */ if (i == UPDATE) { initp(); call_dbu(mdUPDATE, -1); } /* ** send eop back to parser to indicate completion ** if UPDATE then return block comes from dbu else ** return block comes from decomp */ writeback(i == UPDATE ? -1 : 1); # ifdef xDTM if(AAtTf(76, 1)) timtrace(24, 0); # endif # ifdef xDTR1 AAtTfp(50, 1, "DECOMP read %ld pages,%ld catalog pages,wrote %ld pages\n", AAccuread, AAccusread, AAccuwrite); # endif /* clean decomp */ reinit(); /* return */ }
explicit Percent(unsigned max_value, unsigned step = 5) { reinit(max_value, step); }
// slot. To be called when the definition of the tags tree has changed void tags_box_widget::tags_restructured() { reinit(); }
CameraScreen::CameraScreen(Screen * screen, double screenDist) : Camera(P3(screen->getWidth()/2, 0, screen->getHeight()/2), P3(0, 1, 0), 0) { this->screen = screen; this->screenDist = screenDist; reinit(); }
thread_info(int rank, int tid, const char *tag) { reinit(rank, tid, tag); }
/* the optimization loop */ int main(int argc, char **argv) { cmaes_t evo; /* an CMA-ES type struct or "object" */ double *arFunvals, *xfinal, *const*pop; int i,j; int numberDipoles; int id; //Rank int p; //Number processors double elapsed_time;//Time from beginning. double bestValue; int lambda; int maxLambda; int * sendCnts; //For MPI_Alltoallv for arFunVals int * sdispls; //For MPI_Alltoallv for arFunVals int * recvCnts; //For MPI_Alltoallv for arFunVals int * rdispls; //For MPI_Alltoallv for arFunVals int * sendCntsPop; //For MPI_Alltoallv for pop int * sdisplsPop; //For MPI_Alltoallv for pop int * recvCntsPop; //For MPI_Alltoallv for pop int * rdisplsPop; //For MPI_Alltoallv for pop int canTerminate; int canTerminateBuffer; //Start MPI MPI_Init(&argc, &argv); MPI_Barrier(MPI_COMM_WORLD); elapsed_time = -MPI_Wtime(); //Set initial time. MPI_Comm_rank(MPI_COMM_WORLD, &id); //Set id MPI_Comm_size(MPI_COMM_WORLD, &p); //set p for (i=0;i<32;i++) { observations[i]/=1000.0; } //Set number of dipoles, either first argument or default value of 2. numberDipoles=2; if (argc>=2) { numberDipoles=atoi(argv[1]); } //Set lambda based on entry, default of 40 maxLambda=40; if (argc>=3) { maxLambda=atoi(argv[2]); } if (id==0) { printf("Dipoles:%d MaxLambda:%d\n",numberDipoles,maxLambda); } //Allocate lambda pieces to each processor, based on the size of maxLambda and the number of processors. lambda = BLOCK_SIZE(id,p,maxLambda); printf("Id:%d Lambda:%d\n",id,lambda); //Setup send and receive buffers for function evaluations and populations that resulted in those evaluation. sendCnts = malloc(p*sizeof(int)); sdispls = malloc(p*sizeof(int)); recvCnts = malloc(p*sizeof(int)); rdispls = malloc(p*sizeof(int)); sendCntsPop = malloc(p*sizeof(int)); sdisplsPop = malloc(p*sizeof(int)); recvCntsPop = malloc(p*sizeof(int)); rdisplsPop = malloc(p*sizeof(int)); for (i=0;i<p;i++) { sendCnts[i]=lambda;//Same for all others sdispls[i] = BLOCK_LOW(id,p,maxLambda);//Same for all others recvCnts[i] = BLOCK_SIZE(i,p,maxLambda);//Depends on which we receive from. rdispls[i] = BLOCK_LOW(i,p,maxLambda); sendCntsPop[i]=lambda*((numberDipoles*6+2));//Same for all others sdisplsPop[i] = BLOCK_LOW(id,p,maxLambda)*(numberDipoles*6+2);//Same for all others recvCntsPop[i] = BLOCK_SIZE(i,p,maxLambda)*(numberDipoles*6+2);//Depends on which we receive from. rdisplsPop[i] = BLOCK_LOW(i,p,maxLambda)*(numberDipoles*6+2); } for (i=0;i<p;i++) { printf("Id: %d recvCnts[%d]=%d\n",id,i,recvCnts[i]); printf("Id: %d rdispls[%d]=%d\n",id,i,rdispls[i]); printf("Id: %d recvCntsPop[%d]=%d\n",id,i,recvCntsPop[i]); printf("Id: %d rdisplsPop[%d]=%d\n",id,i,rdisplsPop[i]); } /* Initialize everything into the struct evo, 0 means default */ //arFunvals = cmaes_init(&evo, 0, NULL, NULL, 0, 0, "initials.par"); // printf("0\n"); //The maxLambda parameter has been added so all of them will have enough space to store the results arFunvals = reinit(&evo, maxLambda, numberDipoles); //outputCMAES_t(evo,1); // printf("1\n"); resetSignals(&evo, numberDipoles); /* write header and initial values */ //Reset the seed value based on processor (so they don't all come out the same! evo.sp.seed=evo.sp.seed*(id+1)/p; printf("proc: %d seed: %d\n",id,evo.sp.seed); //outputCMAES_t(evo,0); // printf("2\n"); // printf("%s\n", cmaes_SayHello(&evo)); // i=40; // for (i=32;i<40;i*=2) // { // arFunvals = reinit(&evo, i); //outputCMAES_t(evo); evo.sp.lambda=lambda; canTerminate = (0==1); /* Iterate until stop criterion holds */ while(!canTerminate) { /* generate lambda new search points, sample population */ pop = cmaes_SamplePopulation(&evo); /* do not change content of pop */ /* Here you may resample each solution point pop[i] until it becomes feasible, e.g. for box constraints (variable boundaries). function is_feasible(...) needs to be user-defined. Assumptions: the feasible domain is convex, the optimum is not on (or very close to) the domain boundary, initialX is feasible and initialStandardDeviations are sufficiently small to prevent quasi-infinite looping. */ /*for (i = 0; i < lambda; ++i) { cmaes_ReSampleSingle(&evo, i); }*/ for (i = 0; i < lambda; ++i) { while (!is_feasible(evo.rgrgx[i],(int) cmaes_Get(&evo, "dim"))) { cmaes_ReSampleSingle(&evo, i); } } for (i=0;i<lambda;i++) { for(j=0;j<(6*numberDipoles)+2;j++) { evo.rgrgx[BLOCK_LOW(id,p,maxLambda)+i][j]=evo.rgrgx[i][j]; } } /* evaluate the new search points using fitfun from above */ for (i = BLOCK_LOW(id,p,maxLambda); i <= BLOCK_HIGH(id,p,maxLambda); ++i) { arFunvals[i] = fitfun(evo.rgrgx[i], (int) cmaes_Get(&evo, "dim")); //printf("ID:%d, arFunvals[%d]=%lf\n",id,i,arFunvals[i]); } //Now communicate the arFunvals around MPI_Alltoallv(arFunvals,sendCnts,sdispls,MPI_DOUBLE,arFunvals,recvCnts,rdispls,MPI_DOUBLE,MPI_COMM_WORLD); //Now communicate the populations being looked at around MPI_Alltoallv(&evo.rgrgx[0][0],sendCntsPop,sdisplsPop,MPI_DOUBLE,&evo.rgrgx[0][0],recvCntsPop,rdisplsPop,MPI_DOUBLE,MPI_COMM_WORLD); /* update the search distribution used for cmaes_SampleDistribution() */ cmaes_UpdateDistribution(&evo, arFunvals); //Test for any that can terminate. canTerminate = cmaes_TestForTermination(&evo); if (canTerminate) { printf("id:%d can terminate for reason:%s\n",id,cmaes_TestForTermination(&evo)); } MPI_Allreduce(&canTerminate,&canTerminateBuffer,1,MPI_INT,MPI_MAX,MPI_COMM_WORLD);//Get the max, if any are >0, then someone has terminated. canTerminate = canTerminateBuffer;//Reset so the loop will exit. /* read instructions for printing output or changing termination conditions */ // cmaes_ReadSignals(&evo, "signals.par"); // fflush(stdout); /* useful in MinGW */ } // printf("Stop:\n%s\n", cmaes_TestForTermination(&evo)); /* print termination reason */ // cmaes_WriteToFile(&evo, "all", "allcmaes.dat"); /* write final results */ elapsed_time += MPI_Wtime(); /* get best estimator for the optimum, xmean */ xfinal = cmaes_GetNew(&evo, "xmean"); /* "xbestever" might be used as well */ bestValue = fitfun(xfinal, (int) cmaes_Get(&evo, "dim")); printf("Proccesor:%d has last mean of:%lf elapsedTime:%lf\n",id,bestValue,elapsed_time); for (i=0;i<6*numberDipoles;i++) { printf("(%d:%d:%lf)\n",id,i,xfinal[i]); } // cmaes_exit(&evo); /* release memory */ /* do something with final solution and finally release memory */ free(xfinal); free(sendCnts); free(sdispls); free(recvCnts); free(rdispls); free(sendCntsPop); free(sdisplsPop); free(recvCntsPop); free(rdisplsPop); MPI_Finalize(); //} return 0; }
CameraScreen::CameraScreen(P3 & position, P3 & direction, double rotation, Screen * screen, double screenDist): Camera(position, direction, rotation) { this->screen = screen; this->screenDist = screenDist; reinit(); }
int main(int argc, char *argv[]) { printf("ISAKMP: main : <<<START>>> \n"); fd_set *rfds, *wfds; int n, m; size_t mask_size; struct timeval tv, *timeout; // closefrom(STDERR_FILENO + 1); /* * Make sure init() won't alloc fd 0, 1 or 2, as daemon() will close * them. */ /* for (n = 0; n <= 2; n++) if (fcntl(n, F_GETFL, 0) == -1 && errno == EBADF) (void) open("/dev/null", n ? O_WRONLY : O_RDONLY, 0); */ /* Log cmd line parsing and initialization errors to stderr. */ log_to(stderr); parse_args(argc, argv); log_init(debug); /* Open protocols and services databases. */ setprotoent(1); setservent(1); /* Open command fifo */ ui_init(); set_slave_signals(); /* Daemonize before forking unpriv'ed child */ if (!debug) if (daemon(0, 0)) log_fatal("main: daemon (0, 0) failed"); /* Set timezone before priv'separation */ tzset(); write_pid_file(); /* if (monitor_init(debug)) { // The parent, with privileges enters infinite monitor loop. //monitor_loop(debug); //exit(0); // Never reached. }*/ /* Child process only from this point on, no privileges left. */ init(); /* If we wanted IKE packet capture to file, initialize it now. */ if (pcap_file != 0) log_packet_init(pcap_file); /* Allocate the file descriptor sets just big enough. */ // we change here //n = getdtablesize(); n = 1000; mask_size = howmany(n, NFDBITS) * sizeof(fd_mask); rfds = (fd_set *) malloc(mask_size); if (!rfds) log_fatal("main: malloc (%lu) failed", (unsigned long)mask_size); wfds = (fd_set *) malloc(mask_size); if (!wfds) log_fatal("main: malloc (%lu) failed", (unsigned long)mask_size); //monitor_init_done(); while (1) { /* If someone has sent SIGHUP to us, reconfigure. */ if (sighupped) { sighupped = 0; log_print("SIGHUP received"); reinit(); } /* and if someone sent SIGUSR1, do a state report. */ if (sigusr1ed) { sigusr1ed = 0; log_print("SIGUSR1 received"); report(); } /* * and if someone set 'sigtermed' (SIGTERM, SIGINT or via the * UI), this indicates we should start a controlled shutdown * of the daemon. * * Note: Since _one_ message is sent per iteration of this * enclosing while-loop, and we want to send a number of * DELETE notifications, we must loop atleast this number of * times. The daemon_shutdown() function starts by queueing * the DELETEs, all other calls just increments the * 'sigtermed' variable until it reaches a "safe" value, and * the daemon exits. */ if (sigtermed) daemon_shutdown(); /* Setup the descriptors to look for incoming messages at. */ bzero(rfds, mask_size); n = transport_fd_set(rfds); FD_SET(ui_socket, rfds); if (ui_socket + 1 > n) n = ui_socket + 1; /* * XXX Some day we might want to deal with an abstract * application class instead, with many instantiations * possible. */ if (!app_none && app_socket >= 0) { FD_SET(app_socket, rfds); if (app_socket + 1 > n) n = app_socket + 1; } /* Setup the descriptors that have pending messages to send. */ bzero(wfds, mask_size); m = transport_pending_wfd_set(wfds); printf(" m = %d , n = %d \n", m,n); if (m > n) n = m; /* Find out when the next timed event is. */ timeout = &tv; timer_next_event(&timeout); printf(" select (n n= %d )\n ",n ); n = select(n, rfds, wfds, 0, timeout); if (n == -1) { if (errno != EINTR) { log_error("main: select"); /* * In order to give the unexpected error * condition time to resolve without letting * this process eat up all available CPU * we sleep for a short while. */ sleep(1); } } else if (n) { transport_handle_messages(rfds); transport_send_messages(wfds); if (FD_ISSET(ui_socket, rfds)) ui_handler(); if (!app_none && app_socket >= 0 && FD_ISSET(app_socket, rfds)) app_handler(); } timer_handle_expirations(); } }