Ejemplo n.º 1
0
void Bleu::saveClippedHits(const vector<string>& candSentenWords, const vector< vector<string> >& refSentensWords,
    size_t gramNum) {
    map<string, size_t> candStats = collectStats(candSentenWords, gramNum);
    vector< map<string, size_t> > refStats;
    for (auto& refSentenWords : refSentensWords) {
        map<string, size_t> refStat = collectStats(refSentenWords, gramNum);
        refStats.push_back(refStat);
        refStat.clear();
    }

    if (BLEU_DEBUG) {
        std::cout << "\nGramNum: " << gramNum 
                  << "\ncandStats: " << std::endl;
        for (auto& candStat : candStats) 
            std::cout << candStat.first << " : " << candStat.second << std::endl;
        int cnt = 0;
        for (auto& refStat : refStats) {
            std::cout << "refStats[" << cnt << "]: " << std::endl;
            for (auto& item : refStat)
                std::cout << item.first << " : " << item.second << std::endl;
            cnt++;
        }
    }

    for (map<string, size_t>::iterator it = candStats.begin(); it != candStats.end(); it++) {
        size_t minLength = it->second;
        size_t maxRef = 0;
        for (auto& refStat : refStats) {
            map<string, size_t>::iterator findIt = refStat.find(it->first);
            if (findIt != refStat.end() ) {
                maxRef = (findIt->second > maxRef ? findIt->second : maxRef);
            }
        }
        minLength = (minLength < maxRef ? minLength : maxRef);
        candClipSum[gramNum - 1] += minLength;

        if (BLEU_DEBUG) {
            std::cout << it->first
                << "\tcandidateLength: " << it->second
                << "\tmaxRef: " << maxRef 
                << "\tcandClipSum[" << gramNum - 1 << "]: " << candClipSum[gramNum - 1] << std::endl;
        }
    }
}
Ejemplo n.º 2
0
/*public*/
void
Quadtree::insert(const Envelope *itemEnv, void* item)
{
	collectStats(*itemEnv);

	Envelope *insertEnv=ensureExtent(itemEnv,minExtent);
	if ( insertEnv != itemEnv ) newEnvelopes.emplace_back(insertEnv);
	root.insert(insertEnv,item);
#if GEOS_DEBUG
	cerr<<"Quadtree::insert("<<itemEnv->toString()<<", "<<item<<")"<<endl;
	cerr<<"       insertEnv:"<<insertEnv->toString()<<endl;
	cerr<<"       tree:"<<endl<<root.toString()<<endl;
#endif
}
void Cache::writeStats(StatsTarget &target)
{
    CacheStats stats;
    collectStats(stats);
    target.writeCounter(
        "CacheHits", stats.nHits);
    target.writeCounter(
        "CacheHitsSinceInit", stats.nHitsSinceInit);
    target.writeCounter(
        "CacheRequests", stats.nRequests);
    target.writeCounter(
        "CacheRequestsSinceInit", stats.nRequestsSinceInit);
    target.writeCounter(
        "CacheVictimizations", stats.nVictimizations);
    target.writeCounter(
        "CacheVictimizationsSinceInit", stats.nVictimizationsSinceInit);
    target.writeCounter(
        "CacheDirtyPages", stats.nDirtyPages);
    target.writeCounter(
        "CachePagesRead", stats.nPageReads);
    target.writeCounter(
        "CachePagesReadSinceInit", stats.nPageReadsSinceInit);
    target.writeCounter(
        "CachePagesWritten", stats.nPageWrites);
    target.writeCounter(
        "CachePagesWrittenSinceInit", stats.nPageWritesSinceInit);
    target.writeCounter(
        "CachePagePrefetchesRejected", stats.nRejectedPrefetches);
    target.writeCounter(
        "CachePagePrefetchesRejectedSinceInit",
        stats.nRejectedPrefetchesSinceInit);
    target.writeCounter(
        "CachePageIoRetries", stats.nIoRetries);
    target.writeCounter(
        "CachePageIoRetriesSinceInit",
        stats.nIoRetriesSinceInit);
    target.writeCounter(
        "CachePagesPrefetched", stats.nSuccessfulPrefetches);
    target.writeCounter(
        "CachePagesPrefetchedSinceInit",
        stats.nSuccessfulPrefetchesSinceInit);
    target.writeCounter("CacheLazyWrites", stats.nLazyWrites);
    target.writeCounter("CacheLazyWritesSinceInit", stats.nLazyWritesSinceInit);
    target.writeCounter("CacheLazyWriteCalls", stats.nLazyWriteCalls);
    target.writeCounter(
        "CacheLazyWriteCallsSinceInit",
        stats.nLazyWriteCallsSinceInit);
    target.writeCounter("CacheVictimizationWrites", stats.nVictimizationWrites);
    target.writeCounter(
        "CacheVictimizationWritesSinceInit",
        stats.nVictimizationWritesSinceInit);
    target.writeCounter("CacheCheckpointWrites", stats.nCheckpointWrites);
    target.writeCounter(
        "CacheCheckpointWritesSinceInit",
        stats.nCheckpointWritesSinceInit);
    target.writeCounter(
        "CachePagesAllocated", stats.nMemPagesAllocated);
    target.writeCounter(
        "CachePagesUnused", stats.nMemPagesUnused);
    target.writeCounter(
        "CachePagesAllocationLimit", stats.nMemPagesMax);
}
Ejemplo n.º 4
0
void Master::solve() {  

        lastCubeFinished = wallClockTime();
        num_threads = so.num_threads;
        job_start_time.growTo(num_threads, DONT_DISTURB);
        job_start_time_backup.growTo(num_threads, DONT_DISTURB);
        cur_job.growTo(num_threads, NULL);
        lhead.growTo(num_threads, 0);
        last_send_learnts.growTo(num_threads, 0);
        global_learnts.reserve(10000000);
        long maxCycleTime = 0;
        stoppedInit = false;
        if(engine.opt_var){
          bestObjReceived = engine.opt_type ? engine.opt_var->getMin() : engine.opt_var->getMax();
        }
        
        if(so.purePortfolio){
          for(int i = 0 ; i < num_threads ; i++)
            job_queue.push(new SClause());
        }
        else
          job_queue.push(new SClause());
        
        for(int i = 0 ; i < num_threads ; i++){
          if(so.greedyInit && (i  % 3 < 2)){
            slaveStates.push_back(RUNNING_GREEDY);
            slavesRunningGreedy++;
            setState(i, RUNNING_GREEDY);
          }
          else{
            slaveStates.push_back(NORMAL_SEARCH);
            setState(i, NORMAL_SEARCH);
          }
        } 

        MPI_Buffer_attach(malloc(MPI_BUFFER_SIZE), MPI_BUFFER_SIZE);

        // Search:
        int lastPrinted = time(NULL);
        int tStart = lastPrinted;
        long lastSleep = clock();
        bool stealJobsNow = true;
        while (status == RES_UNK && time(NULL) < so.time_out) {
                //fprintf(stderr, "Trying to send jobs...\n");
                while (num_free_slaves > 0 && job_queue.size() > 0) {
                  if(!sendJob())
                    break;
                }
                /**************************************************************************
                 * Ask all jobs to finish the first phase, if this has not happened yet.
                 * */
                if(!stoppedInit &&  time(NULL) > engine.half_time){
                  if(PAR_DEBUG) fprintf(stderr, "Asking remaining init-workers to continue with normal search...\n");
                  for(int i = 0 ; i < num_threads ; i++){
                    if(slaveStates[i] == RUNNING_GREEDY){
                      setState(i, NORMAL_SEARCH);
                    }
                  }
                  stoppedInit = true;
                }
                int received;
                MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &received, &s);
                if (received) {
                        double t;
                        profile_start();
                      //  printf("Profiling started...\n");
                        switch (s.MPI_TAG) {
                                case REPORT_TAG:
                                    //    printf("It was a report!\n");
                                        receiveReport();
                                    //    printf("ReceiveReport done!\n");
                                        profile_end("receive report", 0);
                                        continue;
                                case SPLIT_TAG:
                                     //   printf("Split tag received!\n");
                                        receiveJobs();
                                        profile_end("receive jobs", 0);
                                        continue;
                                case REPORT_SOLUTION_TAG:
                                    if(PAR_DEBUG) fprintf(stderr, "Received solution! \n");
                                    receiveSolution();
                                    continue;
                                case REPORT_OPTIMUM_TAG:
                                  receiveOptObj();
                                  continue;
                                case SOLUTION_PHASE_TAG:
                                  receivePhase();
                                  continue;
                                case SLAVE_NEW_STATE_TAG:
                                  int dummy;
                                  MPI_Recv(&dummy, 1, MPI_INT, s.MPI_SOURCE, SLAVE_NEW_STATE_TAG, MPI_COMM_WORLD, &s);
                                  if(PAR_DEBUG) fprintf(stderr, "Setting state of slave %d to %d\n", s.MPI_SOURCE-1, dummy);
                                  if(slaveStates[s.MPI_SOURCE-1] == RUNNING_GREEDY && dummy == NORMAL_SEARCH)
                                    slavesRunningGreedy--;
                                  slaveStates[s.MPI_SOURCE-1] = dummy;
                                  continue;
                                  continue;
                                default:
                                        assert(false);
                        }
                }
                if (job_queue.size() < 2*num_threads-2 && !so.purePortfolio ) { 
                  // Steal jobs if 
                  // - normal mode
                  // - greedy-init, and at least one job finished now...
                  if(!so.greedyInit || slavesRunningGreedy < num_threads){
                    stealJobs(); 
                    //continue; 
                  }
                  
                }
                
                long now = clock();
                maxCycleTime = std::max(maxCycleTime, now - lastSleep);
                usleep(500);
                lastSleep = clock();
                
                
        }
        if (PAR_DEBUG){
          fprintf(stderr, "Waiting for slaves to terminate...\n");
          fprintf(stderr, "Max cycle time: %d (%lf)\n", maxCycleTime, (double)maxCycleTime/CLOCKS_PER_SEC);
          fprintf(stderr, "End of problem called\n");
        }
        MPI_Request r;
        for (int i = 0; i < num_threads; i++) {
                MPI_Isend(NULL, 0, MPI_INT, i+1, INTERRUPT_TAG, MPI_COMM_WORLD, &r);
                MPI_Isend(NULL, 0, MPI_INT, i+1, FINISH_TAG, MPI_COMM_WORLD, &r);
        }

        while (num_free_slaves != num_threads) {
                MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &s);
                int thread_no = s.MPI_SOURCE-1;

                MPI_Get_count(&s, MPI_INT, &message_length);
                message = (int*) malloc(message_length*sizeof(int));
                MPI_Recv(message, message_length, MPI_INT, s.MPI_SOURCE, s.MPI_TAG, MPI_COMM_WORLD, &s);
                if (s.MPI_TAG == REPORT_TAG) {
                        if (message[0] != RES_SEA) {
                                assert(job_start_time[thread_no] != NOT_WORKING);
                                num_free_slaves++;
                                job_start_time[thread_no] = NOT_WORKING;
                                if (PAR_DEBUG) fprintf(stderr, "%d is free, %f\n", thread_no, wallClockTime());
                        }
                }

                free(message);
        }

        collectStats();
        if(PAR_DEBUG) fprintf(stderr, "Master terminating with obj in %d and %d, bestResult= %d\n", engine.opt_var->getMin(), engine.opt_var->getMax(), bestObjReceived);
        if(so.verbosity > 0)
          printStats();

}