M2_arrayint SchreyerFrame::getBetti(int type) { if (type == 4) { computeFrame(); decltype(timer()) timeA, timeB; timeA = timer(); computeRanks(mHiSlantedDegree, maxLevel()); timeB = timer(); timeComputeRanks += seconds(timeB-timeA); return mBettiMinimal.getBetti(); } if (type == 0 or type == 1) return getBettiFrame(); if (type == 5) return mComputationStatus.getBetti(); ERROR("betti display not implemenented yet"); return 0; }
void SchreyerFrame::start_computation(StopConditions& stop) { // This is the computation of the non-minimal maps themselves decltype(timer()) timeA, timeB; // if (level(0).size() == 0) // mState = Done;; computeFrame(); if (M2_gbTrace >= 1) { std::cout << "computation status after computing frame: " << std::endl; mComputationStatus.output(); } int top_slanted_degree = mHiSlantedDegree; if (stop.stop_after_degree and mHiSlantedDegree > stop.degree_limit->array[0]) top_slanted_degree = stop.degree_limit->array[0]; computeSyzygies(top_slanted_degree ,mMaxLength); if (M2_gbTrace >= 1) { showMemoryUsage(); std::cout << "total time for make matrix: " << timeMakeMatrix << std::endl; std::cout << "total time for sort matrix: " << timeSortMatrix << std::endl; std::cout << "total time for reorder matrix: " << timeReorderMatrix << std::endl; std::cout << "total time for gauss matrix: " << timeGaussMatrix << std::endl; std::cout << "total time for clear matrix: " << timeClearMatrix << std::endl; std::cout << "total time for reset hash table: " << timeResetHashTable << std::endl; std::cout << "total time for computing ranks: " << timeComputeRanks << std::endl; } return; #if 0 if (M2_gbTrace >= 1) { std::cout << "computation status after computing syzygies: " << std::endl; mComputationStatus.output(); } timeA = timer(); computeRanks(mHiSlantedDegree, mMaxLength); timeB = timer(); timeComputeRanks += seconds(timeB-timeA); if (M2_gbTrace >= 1) { std::cout << "computation status after computing ranks: " << std::endl; mComputationStatus.output(); } // This next part needs to be computed after the frame, as otherwise mHiSlantedDegree isn't yet set. int top_slanted_degree = 0; top_slanted_degree = mHiSlantedDegree; if (stop.stop_after_degree and mHiSlantedDegree > stop.degree_limit->array[0]) top_slanted_degree = stop.degree_limit->array[0]; while (true) { switch (mState) { case Initializing: break; case Frame: std::cerr << "ERROR: should not get to this point anymore..." << std::endl; if (M2_gbTrace >= 1) std::cout << "maxsize = " << mFrame.mLevels.size() << " and mCurrentLevel = " << mCurrentLevel << std::endl; if (mCurrentLevel >= mFrame.mLevels.size() or computeNextLevel() == 0) { //show(6); mState = Matrices; mCurrentLevel = 2; getBounds(mLoSlantedDegree, mHiSlantedDegree, mMaxLength); mSlantedDegree = mLoSlantedDegree; setBettiDisplays(); if (M2_gbTrace >= 1) { std::cout << "non-minimal betti: " << std::endl; mBettiNonminimal.output(); } //for (int i=0; i<mMinimalizeTODO.size(); i++) // { // auto a = mMinimalizeTODO[i]; // std::cout << "(" << a.first << "," << a.second << ") "; // } // std::cout << std::endl; } break; case Matrices: if (M2_gbTrace >= 1) std::cout << "start_computation: entering matrices(" << mSlantedDegree << ", " << mCurrentLevel << ")" << std::endl; if (stop.always_stop) return; if (mCurrentLevel > mMaxLength) { mCurrentLevel = 2; mSlantedDegree++; if (mSlantedDegree > top_slanted_degree) { if (M2_gbTrace >= 1) showMemoryUsage(); #if 0 debugCheckOrderAll(); #endif timeA = timer(); for (auto it=mMinimalizeTODO.cbegin(); it != mMinimalizeTODO.cend(); ++it) { int rk = rank(it->first, it->second); mBettiMinimal.entry(it->first, it->second) -= rk; mBettiMinimal.entry(it->first+1, it->second-1) -= rk; } timeB = timer(); timeComputeRanks += seconds(timeB-timeA); mState = Done; if (M2_gbTrace >= 1) mBettiMinimal.output(); break; } // if (stop.stop_after_degree and mSlantedDegree > stop.degree_limit->array[0]) // return; } if (M2_gbTrace >= 2) { std::cout << "construct(" << mSlantedDegree << ", " << mCurrentLevel << ")..." << std::flush; } mComputer.construct(mCurrentLevel, mSlantedDegree+mCurrentLevel); if (M2_gbTrace >= 2) { std::cout << "done" << std::endl; } ///std::cout << "Number of distinct monomials so far = " << mAllMonomials.count() << std::endl; mCurrentLevel++; break; case Done: if (M2_gbTrace >= 1) { std::cout << "total time for make matrix: " << timeMakeMatrix << std::endl; std::cout << "total time for sort matrix: " << timeSortMatrix << std::endl; std::cout << "total time for reorder matrix: " << timeReorderMatrix << std::endl; std::cout << "total time for gauss matrix: " << timeGaussMatrix << std::endl; std::cout << "total time for clear matrix: " << timeClearMatrix << std::endl; std::cout << "total time for reset hash table: " << timeResetHashTable << std::endl; std::cout << "total time for computing ranks: " << timeComputeRanks << std::endl; } return; default: break; } } #endif }
BettiDisplay SchreyerFrame::minimalBettiNumbers( bool stop_after_degree, int top_slanted_degree, int length_limit ) { // The lo degree will be: mLoSlantedDegree. // The highest slanted degree will either be mHiSlantedDegree, or top_slanted_degree (minimum of these two). // The length we need to compute to is either maxLevel(), or length_limit+1. // We set maxlevel to length_limit. We insist that length_limit <= maxLevel() - 2. // Here is what needs to be computed: // lo: . . . . . . . // . . . . . . . /// hi: . . . . . . // Each dot in all rows other than 'hi' needs to have syzygies computed for it. // if hi == mHiSlantedDegree, then we do NOT need to compute syzygies in this last row. // else we need to compute syzygies in these rows, EXCEPT not at level maxlevel+1 computeFrame(); int top_degree; // slanted degree if (stop_after_degree) { top_degree = std::min(top_slanted_degree, mHiSlantedDegree); top_degree = std::max(mLoSlantedDegree, top_degree); } else { top_degree = mHiSlantedDegree; } // First: if length_limit is too low, extend the Frame if (length_limit >= maxLevel()) { std::cout << "WARNING: cannot extend resolution length" << std::endl; length_limit = maxLevel()-1; // Extend the length of the Frame, change mMaxLength, possibly mHiSlantedDegree // increase mComputationStatus if needed, mMinimalBetti, ... // computeFrame() } // What needs to be computed? // lodeg..hideg, level: 0..maxlevel. Note: need to compute at level maxlevel+1 in order to get min betti numbers at // level maxlevel. // Also note: if hideg is the highest degree that occurs in the frame, we do not need to compute any matrices for these. for (int deg=mLoSlantedDegree; deg <= top_degree-1; deg++) for (int lev=1; lev<=length_limit+1; lev++) computeRank(deg, lev); for (int lev=1; lev<=length_limit; lev++) computeRank(top_degree, lev); if (M2_gbTrace >= 1) { showMemoryUsage(); std::cout << "total setPoly: " << poly_constructor::ncalls << std::endl; std::cout << "total setPolyFromArray: " << poly_constructor::ncalls_fromarray << std::endl; std::cout << "total ~poly: " << poly::npoly_destructor << std::endl; std::cout << "total time for make matrix: " << timeMakeMatrix << std::endl; std::cout << "total time for sort matrix: " << timeSortMatrix << std::endl; std::cout << "total time for reorder matrix: " << timeReorderMatrix << std::endl; std::cout << "total time for gauss matrix: " << timeGaussMatrix << std::endl; std::cout << "total time for clear matrix: " << timeClearMatrix << std::endl; std::cout << "total time for reset hash table: " << timeResetHashTable << std::endl; std::cout << "total time for computing ranks: " << timeComputeRanks << std::endl; } BettiDisplay B(mBettiMinimal); // copy B.resize(mLoSlantedDegree, top_degree, length_limit); return B; }
void Worker::doWork (InputParametersRS input) { // if the last input is different from this input only in the frame number, // then we can re-use some of the results from previous invocation bool cacheValid = false; if( m_lastInput.fitsLocation.uniqueId() == input.fitsLocation.uniqueId() && ! m_lastInput.isNull && m_lastInput.bottom == input.bottom && m_lastInput.top == input.top && m_lastInput.left == input.left && m_lastInput.right == input.right) { cacheValid = true; } else { cacheValid = false; m_currRes = ResultsRS(); m_currRes.nFramesComputed = 0; } m_lastInput = input; // for null input emit null output if( input.isNull) { m_currRes.status_ = ResultsRS::NullInput; emit done(m_currRes); return; } // initialize the parser if it's not already initialized if( ! m_parser) m_parser = new FitsParser(); // if the parser is working on a different filename, reopen it if( currentFitsLocation_.uniqueId () != input.fitsLocation.uniqueId ()) { bool res = m_parser->loadFile ( input.fitsLocation); if( ! res) throw std::runtime_error("Could not open file"); else currentFitsLocation_ = input.fitsLocation; } // get a reference to the fits header const FitsParser::HeaderInfo & hdr = m_parser->getHeaderInfo (); // check for more input errors now that we have fits header input.left = clamp( input.left, 0, hdr.naxis1-1); input.right = clamp( input.right, 0, hdr.naxis1-1); input.top = clamp( input.top, 0, hdr.naxis2-1); input.bottom = clamp( input.bottom, 0, hdr.naxis2-1); if( input.left > input.right) std::swap( input.left, input.right); if( input.top > input.bottom) std::swap( input.top, input.bottom); // prepare results (partial) m_currRes.input = input; // save reference to (fixed) input m_currRes.width = m_currRes.input.right - m_currRes.input.left + 1; m_currRes.height = m_currRes.input.bottom - m_currRes.input.top + 1; m_currRes.totalPixels = m_currRes.width * m_currRes.height; m_currRes.depth = hdr.totalFrames; m_currRes.currentFrame = m_currRes.input.currentFrame; throwIfInterrupt(); int frame = m_currRes.input.currentFrame; // get the frame results for the current frame, unless we can retrieve this already // from the last time m_currRes.frames.resize( hdr.totalFrames); if( cacheValid && frame < m_currRes.nFramesComputed) { } else { m_currRes.frames[ frame] = computeFrame( input, frame); } ResultsRS::FrameRes & cfr = m_currRes.frames[ frame]; // copy out the relevant bits m_currRes.nanPixels = cfr.nanPixels; m_currRes.min = cfr.min; m_currRes.max = cfr.max; m_currRes.average = cfr.average; m_currRes.sum = cfr.sum; m_currRes.rms = cfr.rms; m_currRes.bkgLevel = cfr.bkgLevel; m_currRes.sumMinusBkg = cfr.sumMinusBkg; m_currRes.maxMinusBkg = cfr.maxMinusBkg; m_currRes.maxPos = cfr.maxPos; { // total flux double bmin = 0.0, bmaj = 0.0; bool ok = true; if( ok) bmin = hdr.bmin.toDouble( & ok); if( ok) bmaj = hdr.bmaj.toDouble( & ok); if( ok) { m_currRes.beamArea = bmin * bmaj * 1.13309003545679845240692073642916670254 / (hdr.cdelt1 * hdr.cdelt2); m_currRes.beamArea = fabs( m_currRes.beamArea); m_currRes.totalFluxDensity = m_currRes.sum / m_currRes.beamArea; m_currRes.aboveBackground = m_currRes.sumMinusBkg / m_currRes.beamArea; } else { m_currRes.totalFluxDensity = std::numeric_limits<double>::quiet_NaN(); m_currRes.aboveBackground = std::numeric_limits<double>::quiet_NaN(); m_currRes.beamArea = std::numeric_limits<double>::quiet_NaN(); } } // if the results are already complete, we are done if( m_currRes.nFramesComputed == hdr.totalFrames) { m_currRes.status_ = ResultsRS::Complete; emit done (m_currRes); return; } // otherwise we'll have to compute the remaining frames, but in any case, // report a partial result right now with the current frame m_currRes.status_ = ResultsRS::Partial; emit progress( m_currRes); // initialize timer for reporting progress QTime progressTimer; progressTimer.restart (); // now extract all the other frames int startFrame = m_currRes.nFramesComputed; for( int i = startFrame ; i < hdr.totalFrames ; i ++ ) { throwIfInterrupt(); if( i == frame) continue; // skip the current frame, we already did that one // compute the frame m_currRes.frames[i] = computeFrame( input, i); m_currRes.nFramesComputed = i + 1; // report progress every second or so, but not for the last frame... if( progressTimer.elapsed () > 1000 && i+1 < hdr.totalFrames) { progressTimer.restart (); throwIfInterrupt (); emit progress( m_currRes); } } // we are done m_currRes.status_ = ResultsRS::Complete; m_currRes.nFramesComputed = m_currRes.depth; throwIfInterrupt (); emit done (m_currRes); }
void Worker::doWorkOld (InputParametersRS input) { ResultsRS r; // for null input emit null output if( input.isNull) { r.status_ = ResultsRS::NullInput; emit done(r); return; } // initialize the parser if it's not already initialized if( ! m_parser) m_parser = new FitsParser(); // if the parser is working on a different filename, reopen it if( currentFitsLocation_.uniqueId () != input.fitsLocation.uniqueId ()) { bool res = m_parser->loadFile ( input.fitsLocation); if( ! res) throw std::runtime_error("Could not open file"); else currentFitsLocation_ = input.fitsLocation; } // get a reference to the fits header const FitsParser::HeaderInfo & hdr = m_parser->getHeaderInfo (); // check for more input errors now that we have fits header input.left = clamp( input.left, 0, hdr.naxis1-1); input.right = clamp( input.right, 0, hdr.naxis1-1); input.top = clamp( input.top, 0, hdr.naxis2-1); input.bottom = clamp( input.bottom, 0, hdr.naxis2-1); if( input.left > input.right) std::swap( input.left, input.right); if( input.top > input.bottom) std::swap( input.top, input.bottom); // prepare results (partial) r.input = input; // save reference to (fixed) input r.width = r.input.right - r.input.left + 1; r.height = r.input.bottom - r.input.top + 1; r.totalPixels = r.width * r.height; r.status_ = ResultsRS::Partial; r.depth = hdr.totalFrames; r.currentFrame = r.input.currentFrame; throwIfInterrupt(); // emit progress (r); int frame = r.input.currentFrame; // get the frame results for the current frame r.frames.resize( hdr.totalFrames); r.frames[ frame] = computeFrame( input, frame); ResultsRS::FrameRes & cfr = r.frames[ frame]; // cfr = computeForFrame( input, frame); // copy out the relevant bits r.nanPixels = cfr.nanPixels; r.min = cfr.min; r.max = cfr.max; r.average = cfr.average; r.sum = cfr.sum; r.rms = cfr.rms; r.bkgLevel = cfr.bkgLevel; r.sumMinusBkg = cfr.sumMinusBkg; r.maxMinusBkg = cfr.maxMinusBkg; r.maxPos = cfr.maxPos; emit progress( r); // initialize timer for reporting progress QTime progressTimer; progressTimer.restart (); // now extract all the other frames for( int i = 0 ; i < hdr.totalFrames ; i ++ ) { throwIfInterrupt(); if( i == frame) continue; // skip the current frame, we already did that one // compute the frame r.frames[i] = computeFrame( input, i); r.nFramesComputed = i + 1; // report progress every second or so, but not for the last frame... if( progressTimer.elapsed () > 1000 && i+1 < hdr.totalFrames) { progressTimer.restart (); throwIfInterrupt (); emit progress( r); } } // we are done r.status_ = ResultsRS::Complete; r.nFramesComputed = r.depth; throwIfInterrupt (); emit done (r); }
int main(int argc, char **argv) { // TEST LES ARGUMENTS // if(argc < 5) { printf("Usage : vie_sdl width height nbCasesX nbCasesY\nExemple : ./vie_sdl 1920 1080 190 100\n"); return -1; } printf("Dimensions de la fenetre : %dx%d\nDimensions de la surface de jeu : %dx%d\n", atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), atoi(argv[4])); // VARIABLES // /// Dimensions de la fenetre int winWidth = atoi(argv[1]), winHeight = atoi(argv[2]); SDL_Surface *screen = NULL, *text = NULL; TTF_Font *police = NULL; SDL_Event event; SDL_Color couleurBlanche = {255, 255, 255}; /// Titre de la fenêtre, infos à afficher char caption[64], infos[200]; int continuer = 1, moving = 0, proliferation = 0, grid = 1; Fps fps = initFps(); Simulation sim; // INITIALISATION // srand(time(NULL)); /// Les arguments 3 et 4 sont les dimensions de la surface de jeu initSimulation(&sim, atoi(argv[3]), atoi(argv[4])); initSDL(&screen, &police, winWidth, winHeight); // BOUCLE PRINCIPALE // do { fps.realCpt++; /* Gère les évenements */ while(SDL_PollEvent(&event)) { switch(event.type) { // Clique droit = bouger la vue case SDL_MOUSEBUTTONDOWN: switch(event.button.button) { case SDL_BUTTON_RIGHT: moving = 1; break; default: break; } break; case SDL_MOUSEBUTTONUP: switch(event.button.button) { case SDL_BUTTON_RIGHT: moving = 0; break; default: break; } break; // Si la souris bouge et que le clique droit est enfoncé // On déplace la vue case SDL_MOUSEMOTION: if(moving) { sim.dispX += event.motion.xrel; sim.dispY += event.motion.yrel; } break; case SDL_KEYDOWN: // Gère l'appui sur une touche switch(event.key.keysym.sym) { // Bouge la surface case SDLK_a: moving = 1; break; case SDLK_g: grid = !grid; break; // Active la fonction ANTICONVERGENCE !! case SDLK_UP: proliferation = !proliferation; break; // Met en pause ou reprend la simulation case SDLK_SPACE: sim.pause = !sim.pause; break; // Zoom + et - case SDLK_KP_PLUS: sim.largeurCase++; break; case SDLK_KP_MINUS: if(sim.largeurCase > 1) sim.largeurCase--; break; // Mode plein écran case SDLK_F11: screen = SDL_SetVideoMode(winWidth, winHeight, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN); break; case SDLK_ESCAPE: continuer = 0; default: break; } break; case SDL_KEYUP: switch(event.key.keysym.sym) { case SDLK_a: moving = 0; break; default: break; } break; // Redimensionnement de la fenêtre case SDL_VIDEORESIZE: winWidth = event.resize.w; winHeight = event.resize.h; screen = SDL_SetVideoMode(winWidth, winHeight, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE); break; case SDL_QUIT: continuer = 0; } } /* Calculs */ if(!sim.pause) { computeFrame(&sim); /// ANTICONVERGENCE if(proliferation) sim.buffers[sim.actualBuffer][rand()%sim.nbCasesX][rand()%sim.nbCasesY] = 1; } /* Dessine l'écran */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 50,50,50)); /// Dessine les carrés et la grille sur la surface du jeu drawGameMatrix(screen, &sim, grid); /// Ecrit les infos sprintf(infos, "dispX = %d dispY = %d", sim.dispX, sim.dispY); text = TTF_RenderText_Blended(police, infos, couleurBlanche); SDL_BlitSurface(text,NULL, screen, NULL); // Change le buffer de travail if(!sim.pause) sim.actualBuffer = !sim.actualBuffer; // Régule les FPS tempoFps(&fps); // Calcul les vrais FPS computeTrueFps(&fps); // Met à jour le titre de la fenêtre sprintf(caption, "Game Of Life ! %d fps !", fps.real); SDL_WM_SetCaption(caption, NULL); SDL_Flip(screen); }while (continuer); free3DTab(&sim.buffers, 2, sim.nbCasesX); TTF_CloseFont(police); TTF_Quit(); SDL_FreeSurface(screen); SDL_Quit(); return 0; }