void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { char *windowName, n = 1; short int figureHandle; HWND hwnd; RECT rectWin; /* check for proper number of input arguments */ if( !(nrhs > 0) || !(nrhs < 3) || !(nlhs == 0) ) mexErrMsgIdAndTxt("MATLAB:winontop", "Improper number of input or output arguments"); /* first input argument: figure handle */ figureHandle = (short int)mxGetScalar(prhs[0]); windowName = mxCalloc(1,sizeof(figureHandle)+8); sprintf(windowName,"Figure %d",figureHandle); /* check that first input argument is a valid figure handle */ if( mexGet(figureHandle,"Visible") == NULL ) mexErrMsgIdAndTxt("MATLAB:winontop", "First input argument must be a figure handle"); /* second input argument: changes 'topmost' property */ if( nrhs == 2 ) n = (char)mxGetScalar(prhs[1]); /* check that second input argument is valid */ if( !( (n == 1) || (n == 0) ) ) mexErrMsgIdAndTxt("MATLAB:winontop", "Second input argument must be 0 or 1"); /* set state of topmost property */ if (hwnd = FindWindow(NULL,windowName)) { // get window position GetWindowRect(hwnd, &rectWin); if( n == 1 ) SetWindowPos(hwnd,HWND_TOPMOST,rectWin.left,rectWin.top,0,0,SWP_NOSIZE); else SetWindowPos(hwnd,HWND_NOTOPMOST,rectWin.left,rectWin.top,0,0,SWP_NOSIZE); } }
/////////////////////////////// the MAIN LOOP void iterate(double handle) { #ifdef TIMING tic(&total_time); #endif int frq = 500000; // number iteration between MATLAB calls of 'drawnow' int numits; int outer = 0; REAL updownratio_break; bool adaptiveschedule = false; numits = (int) itmax; if (frq > numits) { frq = numits; outer = 1; } else { outer = numits/frq; } if (gammaDE != 0) // then we have an adative temp-schedule { REAL itmax_d = gammaDE; stats.lam_deltaE = itmax_d; birthstats.lam_deltaE = itmax_d; deathstats.lam_deltaE = itmax_d; shiftstats.lam_deltaE = itmax_d; capstats.lam_deltaE = itmax_d; vfstats.lam_deltaE = itmax_d; connstats.lam_deltaE = itmax_d; adaptiveschedule = true; } else { adaptiveschedule = false; } #ifdef PARALLEL_OPENMP omp_set_dynamic(0); // Explicitly disable dynamic teams omp_set_num_threads(numcores); // Use n threads for all consecutive parallel regions #endif #ifdef LINUX_MACHINE static struct timeval timeS; #endif long time =0; int f; for (f = 0; f < outer;f++) { stats.clear(); birthstats.clear(); deathstats.clear(); connstats.clear(); shiftstats.clear(); capstats.clear(); vfstats.clear(); //fprintf(stderr,"parain\n"); fflush(stderr); time = 0; #ifdef LINUX_MACHINE gettimeofday( &timeS, NULL); time -= (timeS.tv_sec*1000000 + timeS.tv_usec); #endif #ifdef PARALLEL_OPENMP #pragma omp parallel for #endif for (int it = 0; it < frq;it++) { if (!pcontainer.needs_reallocation) iterate_onestep(); } if (pcontainer.needs_reallocation) { if (pcontainer.reallocate() == -1) { fprintf(stderr,"out of Memory!!\n"); return; } } #ifdef LINUX_MACHINE gettimeofday( &timeS, NULL); time += (timeS.tv_sec*1000000 + timeS.tv_usec); #endif fprintf(stderr,"#freeslots: %i pcnt:%i #particles:%i\n", (int) pcontainer.freeslots.size(),(int) pcontainer.pcnt,(int)(pcontainer.pcnt-pcontainer.freeslots.size())); pcontainer.defrag(); fprintf(stderr,"#it: %ik #p: %i #c: %i time: %.2fs \n", frq*(f+1)/1000, pcontainer.pcnt,pcontainer.concnt,double(time)/1000000); stats.report_movetype(" total:"); char buf[256]; sprintf(buf,"birth (%.3f):",p_birth); birthstats.report_movetype(buf); sprintf(buf,"death (%.3f):",p_death); deathstats.report_movetype(buf); sprintf(buf,"shift (%.3f):",p_shift); shiftstats.report_movetype(buf); sprintf(buf,"model (%.3f):",p_Dmod); capstats.report_movetype(buf); sprintf(buf,"volfr (%.3f):",p_vfmod); vfstats.report_movetype(buf); sprintf(buf,"track (%.3f):",p_conprob); connstats.report_movetype(buf); REAL cr = (REAL) pcontainer.celloverflows; if (cr > 0.01) fprintf(stderr,"warning: celloverflows : %.2f \n",cr); if (handle != 0) { mexEvalString("drawnow"); if (mexGet(handle,"Tag") == 0) { fprintf(stderr,"Termination by User.\n\n"); break; } } accepted = 0; if (adaptiveschedule && stats.deltaE < 0) { fprintf(stderr,"equilibrium threshold reached, breaking\n"); break; } } iterations_done = (f+1)*frq; //it; }