void ClusterBenchmark::testInsertionPerformance() { Cluster storage; Cell* cell = 0; qDebug() << "measuring loading-like insertion..."; Time::tval start = 0; Time::tval ticks = 0; int col = 1; int row = 1; int cols = 100; int rows = 10000; long counter = 0; start = Time::stamp(); for (int r = row; r <= rows; ++r) { for (int c = col; c <= cols; c += 1) { storage.insert(cell, c, r); counter += 1; } } ticks = Time::elapsed(start); qDebug() << qPrintable(Time::printAverage(ticks, counter)); qDebug() << "measuring random singular insertion..."; storage.clear(); counter = 0; while (counter < Time::iterations) { col = 1 + rand() % 1000; row = 1 + rand() % 1000; cols = col + 1; rows = row + 1; start = Time::stamp(); for (int r = row; r <= rows; ++r) { for (int c = col; c <= cols && counter < Time::iterations; c += 1) { storage.insert(cell, c, r); counter += 1; } } ticks += Time::elapsed(start); } qDebug() << qPrintable(Time::printAverage(ticks, counter)); }
/* * Identify all clusters in the system. */ void ClusterIdentifier::identifyClusters() { // Initialize all data structures: // Setup a grid of empty cells cellList_.setup(system().boundary(), cutoff_); // Clear clusters array and all links clusters_.clear(); for (int i = 0; i < links_.capacity(); ++i) { links_[i].clear(); } // Build the cellList, associate Molecule with ClusterLink. // Iterate over molecules of species speciesId_ System::MoleculeIterator molIter; Molecule::AtomIterator atomIter; system().begin(speciesId_, molIter); for ( ; molIter.notEnd(); ++molIter) { // Associate this Molecule with a ClusterLink links_[molIter->id()].setMolecule(*molIter.get()); // Add atoms of type = atomTypeId_ to the CellList for (molIter->begin(atomIter); atomIter.notEnd(); ++atomIter) { if (atomIter->typeId() == atomTypeId_) { system().boundary().shift(atomIter->position()); cellList_.addAtom(*atomIter); } } } // Identify all clusters Cluster* clusterPtr; ClusterLink* linkPtr; int clusterId = 0; system().begin(speciesId_, molIter); for ( ; molIter.notEnd(); ++molIter) { // Find the link with same index as this molecule linkPtr = &(links_[molIter->id()]); assert (&(linkPtr->molecule()) == molIter.get()); // If this link is not in a cluster, begin a new cluster if (linkPtr->clusterId() == -1) { // Add a new empty cluster to clusters_ array clusters_.resize(clusterId+1); clusterPtr = &clusters_[clusterId]; clusterPtr->clear(); clusterPtr->setId(clusterId); // Identify molecules in this cluster clusterPtr->addLink(*linkPtr); workStack_.push(*linkPtr); while (workStack_.size() > 0) { processNextMolecule(*clusterPtr); } clusterId++; } } // Validity check - throws exception on failure. isValid(); }
void run(std::istream& in) { vector<string> tokens; string line; map<string,auto_vector<KnownGene> >::iterator rchrom; while(getline(in,line,'\n')) { if(AbstractApplication::stopping()) break; if(line.empty() || line[0]=='#') continue; WHERE(line); tokenizer.split(line,tokens); if(chromCol>=(int)tokens.size()) { cerr << "Column CHROM out of range in "<< line << endl; continue; } if((rchrom=chrom2genes.find(tokens[chromCol]))==chrom2genes.end()) { continue; } if(posCol>=(int)tokens.size()) { cerr << "Column POS out of range in "<< line << endl; continue; } if(sampleCol!=-1 && sampleCol>=(int)tokens.size()) { cerr << "Column SAMPLE out of range in "<< line << endl; continue; } if(colorCol!=-1 && colorCol>=(int)tokens.size()) { cerr << "Column COLOR out of range in "<< line << endl; continue; } char* p2; int pos=(int)strtol(tokens[posCol].c_str(),&p2,10); if(pos <0 || *p2!=0) { cerr << "Bad POS "<< tokens[posCol] << " in "<<line << endl; continue; } WHERE(line); if(cluster.chromEnd <=pos) { print(); cluster.clear(); auto_vector<KnownGene>& v= rchrom->second; size_t i=0; while(i< v.size()) { KnownGene* g=v.at(i); WHERE((g==NULL)); if(cluster.genes.empty()) { if(g->txEnd <=pos || g->txStart> pos ) { i++; continue; } cluster.chromStart= g->txStart; cluster.chromEnd= g->txEnd; cluster.genes.push_back(v.release(i)); } else { if(!(g->txStart>cluster.chromEnd || g->txEnd<= cluster.chromStart)) { cluster.chromStart=min(cluster.chromStart,g->txStart); cluster.chromEnd=max(cluster.chromEnd,g->txEnd); cluster.genes.push_back(v.release(i)); } else { ++i; } } } } if(!(cluster.chromStart<=pos && pos<cluster.chromEnd)) { continue; } cluster.positions.insert(pos); if(sampleCol!=-1) { SampleData data; data.pos=pos; if(colorCol!=-1) { Color color(tokens[colorCol].c_str()); data.rgb=color.asInt(); } else { Color color(0.0f); data.rgb=color.asInt(); } cluster.sample2positions[ tokens[sampleCol] ].insert(data); } } print(); }
void print() { if(cluster.positions.empty()) { cluster.clear(); return; } ++count_pages_printed; cout << "\n%%Page: " << count_pages_printed << " "<<count_pages_printed << "\n"; WHERE(cluster.genes.size()); double fHeight=20; float midy=fHeight/2.0f; double cdsHeight=fHeight*0.4; double exonHeight=fHeight*0.9; cout << "2 " << (pageHeight()-10 )<<" moveto (" << cluster.genes.back()->chrom << ":" << cluster.chromStart << "-" << cluster.chromEnd << ") show\n" ; cout << "1 0 0 setrgbcolor\n"; cout << "0.3 setlinewidth\n"; for(set<int32_t>::iterator r=cluster.positions.begin(); r!=cluster.positions.end(); ++r) { cout << "newpath "<< toPixel(*r) << " 0 moveto 0 "<< pageHeight() << " rlineto stroke\n"; cout << toPixel(*r) << " " << (pageHeight()-5) <<" moveto -90 rotate (" << (*r) << ") show 90 rotate\n"; } for(size_t i=0;i< cluster.genes.size();++i) { KnownGene* g=cluster.genes.at(i); cout << "gsave\n"; cout <<"0 "<< pageHeight()-margin_top-(fHeight*i)<<" translate\n"; double x1=toPixel(g->txStart); double x2=toPixel(g->txEnd); cout << "0 0 0 setrgbcolor\n"; NEWPATH; MOVETO(x1,midy); LINETO(x2,midy); STROKE; //draw ticks cout << "0.2 setlinewidth\n"; cout << "newpath\n"; cout << x1 <<" " << midy << " moveto\n"; cout << x1 << " " << x2 << (g->isForward()?" forticksF":" forticksR")<< endl; cout << "closepath stroke\n"; cout << "0.5 setlinewidth\n"; //draw txStart/txEnd cout << "0.1 0.1 0.5 setrgbcolor\n" "newpath\n" << toPixel(g->cdsStart) << " " << (midy-cdsHeight/2.0) <<" " << (toPixel(g->cdsEnd)-toPixel(g->cdsStart)) << " " << cdsHeight << " box closepath fill\n" ; //draw each exon for(int32_t j=0;j< g->countExons();++j) { cout << toPixel(g->exon(j)->start) << " " << (midy-exonHeight/2.0)<< " " << (toPixel(g->exon(j)->end)-toPixel(g->exon(j)->start)) << " " << exonHeight << " gradient\n" ; } //draw name cout << "0 0 0 setrgbcolor\n"; cout << "10 " << midy << " moveto (" << g->name << ") show\n"; cout << "grestore\n"; } if(sampleCol!=-1) { double y= pageHeight()-margin_top-(fHeight*(cluster.genes.size()+1)); for(map<string,set<SampleData>,SmartComparator >::iterator r=cluster.sample2positions.begin(); r!=cluster.sample2positions.end(); ++r) { cout << "0.2 setlinewidth\n"; cout << "0 0 0 setrgbcolor\n"; cout << "10 " << (y-midy+5) << " moveto (" << r->first << ") show\n"; cout << "newpath "<< margin_left << " "<< y << " moveto\n" << width()<< " " << 0 << " rlineto stroke\n"; for(set<SampleData>::iterator r2= r->second.begin(); r2!=r->second.end(); ++r2) { if(colorCol==-1) { cout << "0 setgray\n"; } else { Color c((*r2).rgb); cout << (int)c.r << " " << (int)c.g << " "<< (int)c.b << " setrgbcolor\n"; } cout << "0.8 setlinewidth\n"; cout << "newpath "<<toPixel((*r2).pos)<<" "<< y << " circle closepath stroke\n"; } y-=fHeight; } } cout << "showpage\n"; cluster.clear(); }
void ClusterBenchmark::testLookupPerformance() { // row x column const int scenarios[] = { #if 1 1000, 1000 // large #else 5, 5, // very small 30, 20, // fit to screen 100, 100, // medium 1000, 1000, // large 10000, 100, // typical data: more rows 10000, 2000, // and 20 times larger 100, 10000, // not really typical: more columns 8000, 8000 // hopelessly large #endif }; Cluster storage; Cell* cell = 0; for (uint sc = 0; sc < sizeof(scenarios) / sizeof(scenarios[0]) / 2; sc++) { int maxrow = scenarios[sc*2]; int maxcol = scenarios[sc*2+1]; storage.clear(); #if 0 for (int r = 0; r < maxrow; ++r) { for (int c = 0; c < maxcol; ++c) { storage.insert(cell, c, r); } } #else storage.insert(cell, 1, 1); storage.insert(cell, maxcol / 2, maxrow / 2); storage.insert(cell, maxcol / 3, maxrow / 3); storage.insert(cell, maxcol, maxrow); #endif // qDebug() << endl << qPrintable( storage.dump() ); QString prefix = QString("%1 x %2").arg(maxrow).arg(maxcol); qDebug() << "start measuring..." << prefix; Time::tval start = 0; Time::tval ticks = 0; Cell* v; int col = 0; int row = 0; int cols = 0; int rows = 0; long counter = 0; while (counter < Time::iterations) { col = 1 + rand() % maxcol; row = 1 + rand() % maxrow; cols = col + 1 * (rand() % 10); rows = row + rand() % 10; start = Time::stamp(); for (int r = row; r <= rows && counter < Time::iterations; ++r) { for (int c = col; c <= cols && counter < Time::iterations; c += 1) { v = storage.lookup(c, r); counter += 1; } } ticks += Time::elapsed(start); } qDebug() << qPrintable(Time::printAverage(ticks, counter, prefix)); } }
bool Soft_Cluster_Handler::EnforcedTransition(Cluster_List * clin) { #ifdef AHAmomcheck Vec4D checkbef(SumMomentum(clin)); #endif size_t size(0); std::vector<double> masses; std::vector<Vec4D> momenta; Cluster * cluster; for (Cluster_Iterator cit=clin->begin();cit!=clin->end();cit++) { cluster = (*cit); switch (cluster->size()) { case 1: masses.push_back((*cluster)[0].HadMass()); momenta.push_back(cluster->Momentum()); ++size; break; case 2: case 0: masses.push_back(sqrt(Max(cluster->GetTrip()->m_mom.Abs2(),0.))); masses.push_back(sqrt(Max(cluster->GetAnti()->m_mom.Abs2(),0.))); momenta.push_back(cluster->GetTrip()->m_mom); momenta.push_back(cluster->GetAnti()->m_mom); size+=2; default: break; } } if (!hadpars->AdjustMomenta(size,&momenta.front(),&masses.front())) { if (size>1 /*&& msg->LevelIsDebugging()*/) { msg_Tracking()<<"Error in "<<METHOD<<" ("<<size<<" clusters) : \n" <<" Could not adjust momenta for : \n"; int i(0); for (Cluster_Iterator cit=clin->begin();cit!=clin->end();cit++) { msg_Tracking()<<"Mass/Mom = "<<masses[i]<<"/"<<momenta[i]; if ((*cit)->size()==1) msg_Tracking()<<" ("<<((**cit)[0])<<" )"; msg_Tracking()<<" for \n"<<(**cit)<<"\n"; i++; } msg_Tracking()<<" Will possibly lead to retrying the event.\n"; } return false; } int pos(0); #ifdef AHAmomcheck Vec4D checkaft(SumMomentum(clin)); #endif for (Cluster_Iterator cit=clin->begin();cit!=clin->end();cit++) { cluster = (*cit); switch (cluster->size()) { case 1: cluster->SetFlav((*cluster)[0]); cluster->SetMomentum(momenta[pos]); break; case 2: #ifdef AHAmomcheck checkaft += momenta[pos]; #endif cluster->GetTrip()->m_mom=momenta[pos++]; cluster->GetAnti()->m_mom=momenta[pos]; cluster->Update(); if (cluster->Mass()<(*cluster)[0].HadMass()+(*cluster)[1].HadMass()) { cluster->clear(); } break; case 0: cluster->GetTrip()->m_mom=momenta[pos++]; cluster->GetAnti()->m_mom=momenta[pos]; cluster->Update(); break; default: break; } pos++; } #ifdef AHAmomcheck double Q2(dabs((checkbef-checkaft).Abs2())); if (Q2>1.e-12 || IsNan(Q2)) { msg_tracking()<<METHOD<<" yields a momentum violation for "<<size<<" : \n" <<" "<<checkbef<<" - "<<checkaft<<" --> " <<(checkbef-checkaft).Abs2()<<"("<<size<<").\n" <<(*clin)<<"\n"; } else msg_Tracking()<<METHOD<<" satisfied four-momentum conservation.\n"; #endif m_transitions += 1; return true; }
void ZimCreator::createClusters(ArticleSource& src, const std::string& tmpfname) { std::ofstream out(tmpfname.c_str()); Cluster cluster; cluster.setCompression(compression); DirentsType::size_type count = 0, progress = 0; for (DirentsType::iterator di = dirents.begin(); out && di != dirents.end(); ++di, ++count) { while (progress < count * 100 / dirents.size() + 1) { INFO(progress << "% ready"); progress += 10; } if (di->isRedirect()) continue; Blob blob = src.getData(di->getAid()); if (blob.size() > 0) isEmpty = false; if (di->isCompress()) { di->setCluster(clusterOffsets.size(), cluster.count()); cluster.addBlob(blob); if (cluster.size() >= minChunkSize * 1024) { log_info("compress cluster with " << cluster.count() << " articles, " << cluster.size() << " bytes; current title \"" << di->getTitle() << '\"'); clusterOffsets.push_back(out.tellp()); out << cluster; log_debug("cluster compressed"); cluster.clear(); cluster.setCompression(compression); } } else { if (cluster.count() > 0) { clusterOffsets.push_back(out.tellp()); cluster.setCompression(compression); out << cluster; cluster.clear(); cluster.setCompression(compression); } di->setCluster(clusterOffsets.size(), cluster.count()); clusterOffsets.push_back(out.tellp()); Cluster c; c.addBlob(blob); c.setCompression(zimcompNone); out << c; } } if (cluster.count() > 0) { clusterOffsets.push_back(out.tellp()); cluster.setCompression(compression); out << cluster; } if (!out) throw std::runtime_error("failed to write temporary cluster file"); clustersSize = out.tellp(); }