本文整理汇总了C++中Stopwatch::Elapsed方法的典型用法代码示例。如果您正苦于以下问题:C++ Stopwatch::Elapsed方法的具体用法?C++ Stopwatch::Elapsed怎么用?C++ Stopwatch::Elapsed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch::Elapsed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: benchNoCachingNoVector
int benchNoCachingNoVector(Vector3D<Precision> const &point, Vector3D<Precision> const &dir,
std::vector<Vector3D<Precision>> const &corners
#ifdef SORTHITBOXES
,
Container_t &hitlist
#endif
)
{
#ifdef INNERTIMER
Stopwatch timer;
timer.Start();
#endif
int vecsize = corners.size() / 2;
int hitcount = 0;
for (auto box = 0; box < vecsize; ++box) {
double distance = BoxImplementation<translation::kIdentity, rotation::kIdentity>::Intersect(
&corners[2 * box], point, dir, 0, vecgeom::kInfLength);
if (distance < vecgeom::kInfLength) {
hitcount++;
#ifdef SORTHITBOXES
hitlist.push_back(BoxIdDistancePair_t(box, distance));
#endif
}
}
#ifdef INNERTIMER
timer.Stop();
std::cerr << "# ORDINARY hitting " << hitcount << "\n";
std::cerr << "# ORDINARY timer " << timer.Elapsed() << "\n";
#endif
return hitcount;
}
示例2: accum
__attribute__((noinline)) void benchNavigatorNoReloc(VNavigator const *se, SOA3D<Precision> const &points,
SOA3D<Precision> const &dirs, NavStatePool const &inpool,
NavStatePool &outpool)
{
Precision *steps = new Precision[points.size()];
Precision *safeties;
if (WithSafety) safeties = new Precision[points.size()];
Stopwatch timer;
size_t hittargetchecksum = 0L;
timer.Start();
for (decltype(points.size()) i = 0; i < points.size(); ++i) {
if (WithSafety) {
steps[i] = se->ComputeStepAndSafety(points[i], dirs[i], vecgeom::kInfLength, *inpool[i], true, safeties[i]);
} else {
steps[i] = se->ComputeStep(points[i], dirs[i], vecgeom::kInfLength, *inpool[i], *outpool[i]);
}
}
timer.Stop();
std::cerr << timer.Elapsed() << "\n";
double accum(0.), saccum(0.);
for (decltype(points.size()) i = 0; i < points.size(); ++i) {
accum += steps[i];
if (WithSafety) {
saccum += safeties[i];
}
if (outpool[i]->Top()) hittargetchecksum += (size_t)outpool[i]->Top()->id();
}
delete[] steps;
std::cerr << "accum " << se->GetName() << " " << accum << " target checksum " << hittargetchecksum << "\n";
if (WithSafety) {
std::cerr << "saccum " << se->GetName() << " " << saccum << "\n";
}
}
示例3: Execute
void StorageDeleteFileChunkJob::Execute()
{
Stopwatch sw;
Buffer filename;
Log_Message("Deleting file chunk %U from disk", chunk->GetChunkID());
sw.Start();
filename.Write(chunk->GetFilename());
delete chunk;
chunk = NULL;
StorageFileDeleter::Delete(filename.GetBuffer());
sw.Stop();
Log_Debug("Deleted, elapsed: %U", (uint64_t) sw.Elapsed());
}
示例4: TestTree
void TestTree(T _tree, DArray<ktype_t> *dataset, unsigned long _size)
{
console->Write("%10lu ", _size);
// fill tree
Stopwatch sw;
sw.Start();
for (size_t i = 0; i < _size; i++) {
ktype_t item = dataset->get(i);
_tree->insert(item, item);
}
sw.Stop();
console->Write("%9.5lfs ", sw.Elapsed());
DArray<ktype_t> searchItems;
// create valid item list
searchItems.empty();
while (searchItems.used() < MaxSearches) {
unsigned long idx = RandomNumber() % _size;
searchItems.insert(dataset->get(idx));
}
// successful searches
sw.Start();
for (size_t i = 0; i < MaxSearches; i++) {
_tree->find(searchItems[i], 0);
}
sw.Stop();
console->Write("%9.5lfs ", sw.Elapsed());
// create mixed item list
searchItems.empty();
while (searchItems.used() < MaxSearches) {
unsigned long idx;
idx = RandomNumber() % _size;
searchItems.insert(dataset->get(idx));
idx = _size + (RandomNumber() % _size);
searchItems.insert(dataset->get(idx));
}
// mixed success searches
sw.Start();
for (size_t i = 0; i < MaxSearches; i++) {
_tree->find(searchItems[i], 0);
}
sw.Stop();
console->Write("%9.5lfs ", sw.Elapsed());
// create invalid item list
searchItems.empty();
while (searchItems.used() < MaxSearches) {
unsigned long idx = _size + (RandomNumber() % _size);
searchItems.insert(dataset->get(idx));
}
// invalid searches
sw.Start();
for (size_t i = 0; i < MaxSearches; i++) {
_tree->find(searchItems[i], 0);
}
sw.Stop();
console->Write("%9.5lfs ", sw.Elapsed());
// empty tree
sw.Start();
_tree->empty();
sw.Stop();
console->WriteLine("%9.5lfs", sw.Elapsed());
}
示例5: main
int main(int argc, char * *argv)
{
console = new Console();
/* Begin your application here. */
SeedRandom();
Stopwatch sw;
size_t sizes [] = { 100000, 1000000, 2000000,
3000000, 4000000, 5000000,
0 };
size_t biggest = 0;
// Locate the last element in the sizes list.
for (size_t *p = sizes; *p != 0; p++) {
biggest = max(biggest, *p);
}
DArray<ktype_t> *dataset = new DArray<ktype_t>(biggest*2);
console->Write("Building data set of %lu items... ", biggest * 2);
sw.Start();
size_t i = 0;
while (dataset->used() < biggest * 2) {
dataset->insert(i++);
}
shuffleElements(dataset);
sw.Stop();
console->WriteLine("%8.5lfs", sw.Elapsed());
console->WriteLine();
console->WriteLine("Testing AVLTree...");
console->WriteLine("%10s %10s %10s %10s %10s %10s", "size", "add", "srch+", "srch", "srch-", "empty");
AVLTree<ktype_t, char> *avltree = new AVLTree<ktype_t, char>();
for (size_t *p = sizes; *p != 0; p++) {
TestTree<AVLTree<ktype_t, char> *> (avltree, dataset, *p);
}
console->WriteLine("AVLTree tests complete.");
delete avltree;
avltree = NULL;
console->WriteLine();
console->WriteLine("Testing RedBlackTree...");
console->WriteLine("%10s %10s %10s %10s %10s %10s", "size", "add", "srch+", "srch", "srch-", "empty");
RedBlackTree<ktype_t, char> *rbtree = new RedBlackTree<ktype_t, char>();
for (size_t *p = sizes; *p != 0; p++) {
TestTree<RedBlackTree<ktype_t, char> *> (rbtree, dataset, *p);
}
console->WriteLine("RedBlackTree tests complete.");
delete rbtree;
rbtree = NULL;
console->WriteLine();
console->WriteLine("Testing SplayTree...");
console->WriteLine("%10s %10s %10s %10s %10s %10s", "size", "add", "srch+", "srch", "srch-", "empty");
SplayTree<ktype_t, char> *splaytree = new SplayTree<ktype_t, char>();
for (size_t *p = sizes; *p != 0; p++) {
TestTree<SplayTree<ktype_t, char> *> (splaytree, dataset, *p);
}
console->WriteLine("SplayTree tests complete.");
delete splaytree;
splaytree = NULL;
#ifdef ENABLE_STLTREE
console->WriteLine();
console->WriteLine("Testing STLTree...");
console->WriteLine("%10s %10s %10s %10s %10s %10s", "size", "add", "srch+", "srch", "srch-", "empty");
STLTree<ktype_t, char> *stltree = new STLTree<ktype_t, char>();
for (size_t *p = sizes; *p != 0; p++) {
TestTree<STLTree<ktype_t, char> *> (stltree, dataset, *p);
}
console->WriteLine("STLTree tests complete.");
delete stltree;
stltree = NULL;
#endif
delete dataset;
console->WriteLine();
/* End your application here. */
#ifdef TARGET_OS_WINDOWS
system("pause");
#endif
delete console;
return 0;
}
示例6: main
//.........这里部分代码省略.........
// init data for image
int data_size_x= (axis1_end-axis1_start)/pixel_axis;
int data_size_y= (axis2_end-axis2_start)/pixel_axis;
int *volume_result= (int*) new int[data_size_y * data_size_x*3];
#ifdef VECGEOM_GEANT4
int *volume_result_Geant4= (int*) new int[data_size_y * data_size_x*3];
#endif
int *volume_result_VecGeom= (int*) new int[data_size_y * data_size_x*3];
int *volume_result_VecGeomABB= (int*) new int[data_size_y * data_size_x*3];
Stopwatch timer;
timer.Start();
#ifdef CALLGRIND
CALLGRIND_START_INSTRUMENTATION;
#endif
XRayWithROOT( axis,
Vector3D<Precision>(origin[0],origin[1],origin[2]),
Vector3D<Precision>(dx,dy,dz),
dir,
axis1_start, axis1_end,
axis2_start, axis2_end,
data_size_x, data_size_y,
pixel_axis,
volume_result );
#ifdef CALLGRIND
CALLGRIND_STOP_INSTRUMENTATION;
CALLGRIND_DUMP_STATS;
#endif
timer.Stop();
std::cout << std::endl;
std::cout << " ROOT Elapsed time : "<< timer.Elapsed() << std::endl;
// Make bitmap file; generate filename
std::stringstream imagenamebase;
imagenamebase << "volumeImage_" << testvolume;
if(axis==1) imagenamebase << "x";
if(axis==2) imagenamebase << "y";
if(axis==3) imagenamebase << "z";
if(voxelize) imagenamebase << "_VOXELIZED_";
std::stringstream ROOTimage;
ROOTimage << imagenamebase.str();
ROOTimage << "_ROOT.bmp";
make_bmp(volume_result, ROOTimage.str().c_str(), data_size_x, data_size_y);
make_bmp(volume_result, "foo.bmp", data_size_x, data_size_y, false);
#ifdef VECGEOM_GEANT4
G4VPhysicalVolume * world = SetupGeant4Geometry( testvolume, Vector3D<Precision>( std::abs(origin[0]) + dx,
std::abs(origin[1]) + dy,
std::abs(origin[2]) + dz ) );
G4GeoManager::Instance().LoadG4Geometry( world );
timer.Start();
XRayWithGeant4( world, axis,
Vector3D<Precision>(origin[0],origin[1],origin[2]),
Vector3D<Precision>(dx,dy,dz),
dir,
axis1_start, axis1_end,
axis2_start, axis2_end,
data_size_x, data_size_y,
pixel_axis,
volume_result_Geant4 );
示例7: RunTestcase
void RunTestcase(T _tree, unsigned long _size, bool _ordered_insert)
{
console->Write("%10lu ", _size);
unsigned long realsize = _size * 2;
ktype_t *elems = NULL;
if (!_ordered_insert) {
elems = new ktype_t[_size + 1];
for (size_t i = 1; i < _size + 1; i++) {
elems[i] = 2*i;
}
elems[_size] = 0;
shuffleElements(elems, _size);
}
// fill tree
Stopwatch sw;
sw.Start();
if (_ordered_insert) {
for (size_t i = 0; i < _size; i++) {
_tree->insert(2 * i, 1);
}
} else {
for (ktype_t *p = elems; *p; p++) {
_tree->insert(*p, 1);
}
}
sw.Stop();
console->Write("%9.5lfs ", sw.Elapsed());
delete [] elems;
elems = NULL;
// successful searches
sw.Start();
for (size_t i = 0; i < _size; i++) {
_tree->find((2 * RandomNumber()) % realsize, 0);
}
sw.Stop();
console->Write("%9.5lfs ", sw.Elapsed());
// mixed success searches
sw.Start();
for (size_t i = 0; i < _size; i++) {
_tree->find(RandomNumber() % realsize, 0);
}
sw.Stop();
console->Write("%9.5lfs ", sw.Elapsed());
// invalid searches
sw.Start();
for (size_t i = 0; i < _size; i++) {
_tree->find((1 + 2 * RandomNumber()) % realsize, 0);
}
sw.Stop();
console->Write("%9.5lfs ", sw.Elapsed());
// empty tree
sw.Start();
_tree->empty();
sw.Stop();
console->WriteLine("%9.5lfs", sw.Elapsed());
}
示例8: main
//.........这里部分代码省略.........
std::cout<< "BoundingBoxDY: "<< dy<< std::endl;
std::cout<< "BoundingBoxDZ: "<< dz<< std::endl;
std::cout<< std::endl;
std::cout<< "BoundingBoxOriginX: "<< origin[0]<< std::endl;
std::cout<< "BoundingBoxOriginY: "<< origin[1]<< std::endl;
std::cout<< "BoundingBoxOriginZ: "<< origin[2]<< std::endl<< std::endl;
Vector3D<Precision> p;
// Vector3D<Precision> dir( std::cos(directionphi)*std::sin(directiontheta), std::sin(directionphi)*std::sin(directiontheta), std::cos(directiontheta) );
//
Vector3D<Precision> dir( -0.00366952650659481318523580384294 , 0.00101412421199570282163981982393 , 0.999991248519344400058628252737 );
//Vector3D<Precision> dir( 1 , 0. , 0. );
dir.FixZeroes();
// init data for image
int data_size_x= 1;//(axis1_end-axis1_start)/pixel_axis;
int data_size_y= 1;//(axis2_end-axis2_start)/pixel_axis;
int *volume_result= (int*) new int[data_size_y * data_size_x*3];
Stopwatch timer;
timer.Start();
XRayWithROOT( axis,
Vector3D<Precision>(origin[0],origin[1],origin[2]),
Vector3D<Precision>(dx,dy,dz),
dir,
axis1_start, axis1_end,
axis2_start, axis2_end,
data_size_x, data_size_y,
pixel_axis,
volume_result );
timer.Stop();
std::cout << std::endl;
std::cout << " ROOT Elapsed time : "<< timer.Elapsed() << std::endl;
#ifdef VECGEOM_GEANT4
G4VPhysicalVolume * world = SetupGeant4Geometry( testvolume, Vector3D<Precision>( std::abs(origin[0]) + dx,
std::abs(origin[1]) + dy,
std::abs(origin[2]) + dz ) );
G4GeoManager::Instance().LoadG4Geometry( world );
timer.Start();
XRayWithGeant4( world, axis,
Vector3D<Precision>(origin[0],origin[1],origin[2]),
Vector3D<Precision>(dx,dy,dz),
dir,
axis1_start, axis1_end,
axis2_start, axis2_end,
data_size_x, data_size_y,
pixel_axis,
volume_result );
timer.Stop();
std::cout << " Geant4 Elapsed time : "<< timer.Elapsed() << std::endl;
#endif
// convert current gGeoManager to a VecGeom geometry
RootGeoManager::Instance().LoadRootGeometry();
std::cout << "Detector loaded " << "\n";
timer.Start();
XRayWithVecGeom( axis,
Vector3D<Precision>(origin[0],origin[1],origin[2]),
Vector3D<Precision>(dx,dy,dz),
dir,
axis1_start, axis1_end,
axis2_start, axis2_end,
data_size_x, data_size_y,
pixel_axis,
volume_result );
timer.Stop();
std::cout << " VecGeom Elapsed time : "<< timer.Elapsed() << std::endl;
// use the vector interface
timer.Start();
XRayWithVecGeom_VecNav( axis,
Vector3D<Precision>(origin[0],origin[1],origin[2]),
Vector3D<Precision>(dx,dy,dz),
dir,
axis1_start, axis1_end,
axis2_start, axis2_end,
data_size_x, data_size_y,
pixel_axis,
volume_result );
timer.Stop();
std::cout << std::endl;
std::cout << " VecGeom Vector Interface Elapsed time : "<< timer.Elapsed() << std::endl;
delete[] volume_result;
}
return 0;
}
示例9: otimizar
void SimplexSolver::otimizar(FObjetivo* func){
//instanciar quadro com funcao objetivo
this->quadro = new Quadro(func);
//atribuir valores iniciais para controle de linha e coluna permissiveis
this->linhaPerm = -1;
this->colunaPerm = -1;
//limpar historico
this->historico.clear();
//definir status inicial do algoritmo
this->status = PrimeiraEtapa;
this->swNormalizacao.Start();
this->quadro->buildQuadro();
this->swNormalizacao.Stop();
int qtdIteracoes = 1;
//alocar vetores auxiliares da linha e coluna permissiveis
this->vec_colunaPerm = new float[this->quadro->totalLinhas];
this->vec_linhaPerm = new float[this->quadro->totalColunas];
cout << endl;
//mostrar quadro atualizado
//this->quadro->toString();
Stopwatch swPrimeiraEtapa;
Stopwatch swSegundaEtapa;
Stopwatch swAlgTroca;
double tempoTotalPrimeiraEtapa = 0, tempoTotalSegundaEtapa = 0, tempoTotalTroca = 0;
int auxLinhaPerm = 0, auxColunaPerm = 0;
try
{
this->swOtimizacao.Start();
this->swSegPorIteracao.Start();
while (this->status != SolucaoOtima &&
this->status != SolucaoIlimitada &&
this->status != SolucaoImpossivel)
{
//this->historico.push_back(this->status);
//this->quadro->toString();
switch (this->status)
{
case PrimeiraEtapa:
swPrimeiraEtapa.Start();
this->status = this->algoritmoPrimeiraEtapa();
swPrimeiraEtapa.Stop();
break;
case SegundaEtapa:
swSegundaEtapa.Start();
this->status = this->algoritmoSegundaEtapa();
swSegundaEtapa.Stop();
break;
case AlgoritmoTroca:
//gravar linha e coluna permitidas encontradas
auxLinhaPerm = this->linhaPerm;
auxColunaPerm = this->colunaPerm;
swAlgTroca.Start();
this->status = this->algoritmoTroca();
swAlgTroca.Stop();
this->swSegPorIteracao.Stop();
tempoTotalPrimeiraEtapa += swPrimeiraEtapa.Elapsed();
tempoTotalSegundaEtapa += swSegundaEtapa.Elapsed();
tempoTotalTroca += swAlgTroca.Elapsed();
if (qtdIteracoes % 10 == 0){
//logar tempos
cout << "==================================" << endl;
//logar linha e coluna permitidas encontradas
cout << "Linha:\t" << this->linhaPerm;
cout << "\tColuna:\t" << this->colunaPerm;
cout << "\tIteracao\t" << qtdIteracoes << endl;
cout << "Primeira etapa:\t\t" << swPrimeiraEtapa.Elapsed() << endl;
cout << "Segunda etapa:\t\t" << swSegundaEtapa.Elapsed() << endl;
cout << "Algoritmo Troca:\t" << swAlgTroca.Elapsed() << endl;
cout << "Total:\t\t\t" << this->swSegPorIteracao.Elapsed() << endl;
cout << "Media parcial:\t\t" << this->swOtimizacao.Parcial() / qtdIteracoes << endl;
cout << "==================================" << endl;
}
//reiniciar tempo de iteracao
this->swSegPorIteracao.Start();
qtdIteracoes++;
break;
}
//.........这里部分代码省略.........
示例10: BenchmarkDArray
void BenchmarkDArray(Sorter<char *> &sorter)
{
DArray<char *> data, rdata;
Stopwatch sw;
char buffer[512], format[64];
sprintf(format, "%s", "%4.3lfs");
FileReader file;
file.SetLineEndings(CC_LN_LF);
file.Open("dataset");
if (file.IsOpen()) {
data.setStepDouble();
rdata.setStepDouble();
console->Write("Loading... ");
sw.Start();
/* Load the file into the data DArray */
while (file.ReadLine(buffer, sizeof(buffer)) >= 0)
data.insert(cc_strdup(buffer));
sw.Stop();
console->WriteLine(format, sw.Elapsed());
file.Close();
console->WriteLine("Loaded %d items.", data.used());
console->Write("Random: ");
sw.Start();
data.sort(sorter);
sw.Stop();
console->WriteLine(format, sw.Elapsed());
/* Create a reverse-sorted DArray */
for (long i = (long)data.size(); i >= 0; i--) {
if (data.valid(i)) {
rdata.insert(data.get(i));
}
}
console->Write("Pre-sorted: ");
sw.Start();
data.sort(sorter);
sw.Stop();
console->WriteLine(format, sw.Elapsed());
console->Write("Reverse-sorted: ");
sw.Start();
rdata.sort(sorter);
sw.Stop();
console->WriteLine(format, sw.Elapsed());
for (size_t i = 0; i < data.size(); i++) {
if (data.valid(i)) {
free(data.get(i));
data.remove(i);
}
}
data.empty();
rdata.empty();
} else {
console->WriteLine("Dataset not found.");
}
}
示例11: main
//.........这里部分代码省略.........
case 'c':
mpsReader = new MPSReader(diretorio + "\\50Var_60Rest.mps");
break;
case 'd':
mpsReader = new MPSReader(diretorio + "\\500Var_500Rest.mps");
break;
case 'e':
mpsReader = new MPSReader(diretorio + "\\100Var_100Rest.mps");
break;
case 'f':
mpsReader = new MPSReader(diretorio + "\\1000Var_1000Rest.mps");
break;
case 'g':
mpsReader = new MPSReader(diretorio + "\\250Var_250Rest.mps");
break;
case 'h':
mpsReader = new MPSReader(diretorio + "\\350Var_350Rest.mps");
break;
case 'i':
mpsReader = new MPSReader(diretorio + "\\750Var_750Rest.mps");
break;
case 'j':
mpsReader = new MPSReader(diretorio + "\\2000Var_2000Rest.mps");
break;
case 'k':
mpsReader = new MPSReader(diretorio + "\\3000Var_3000Rest.mps");
break;
case 'l':
mpsReader = new MPSReader(diretorio + "\\4000Var_4000Rest.mps");
break;
case 'm':
mpsReader = new MPSReader(diretorio + "\\5000Var_5000Rest.mps");
break;
}
Stopwatch swLeitura;
mpsReader->VetorRHSPossuiNome = true;
swLeitura.Start();
funcao = mpsReader->LerFuncaoObjetivo();
swLeitura.Stop();
cout << "Quantidade de variaveis: " << funcao->Variaveis.size() << endl;
cout << "Quantidade de restricoes: " << funcao->Restricoes.size() << endl;
cout << endl;
cout << "Selecione a direcao da otimizacao: " << endl;
cout << endl;
cout << "1 - Minimizar" << endl;
cout << "2 - Maximizar" << endl;
cout << endl;
getchar();
char otimizacao = getchar();
switch (otimizacao) {
case '1':
//Minimizar
funcao->DirecaoOtimizacao = Minimizar;
break;
case '2':
//Maximizar
funcao->DirecaoOtimizacao = Maximizar;
break;
}
//Normalizar funcao
SimplexSolver solver;
cout << "Otimizando funcao objetivo...";
solver.otimizar(funcao);
cout << "Otimizado!" << endl;
cout << "Tempo leitura: " << swLeitura.Elapsed() << "s" << endl;
cout << "Tempo normalizacao: " << solver.tempoNormalizacao() << "s" << endl;
cout << "Tempo otimizacao: " << solver.tempoOtimizacao() << "s" << endl;
cout << "Valor custo: " << solver.valorCusto() << endl;
cout << "Status final: " << solver.statusFinal() << endl;
cout << endl << "Fim do programa. Digite qualquer tecla para sair..." << endl;
getchar();
getchar();
return 0;
}
示例12: benchCachingAndVector
int benchCachingAndVector(Vector3D<Precision> const &point, Vector3D<Precision> const &dir,
Vector3D<kVc::precision_v> const *corners, int vecsize
#ifdef SORTHITBOXES
,
Container_t &hitlist
#endif
)
{
#ifdef INNERTIMER
Stopwatch timer;
timer.Start();
#endif
Vector3D<Precision> invdir(1. / dir.x(), 1. / dir.y(), 1. / dir.z());
int hitcount = 0;
int sign[3];
sign[0] = invdir.x() < 0;
sign[1] = invdir.y() < 0;
sign[2] = invdir.z() < 0;
for (auto box = 0; box < vecsize; ++box) {
kVc::precision_v distance =
BoxImplementation<translation::kIdentity, rotation::kIdentity>::IntersectCachedKernel2<kVc>(
&corners[2 * box], point, invdir, sign[0], sign[1], sign[2], 0, vecgeom::kInfLength);
kVc::bool_v hit = distance < vecgeom::kInfLength;
// std::cerr << hit << "\n";
// this is Vc specific
hitcount += hit.count();
#ifdef SORTHITBOXES
// a little tricky: need to iterate over the mask
for (auto i = 0; i < kVc::precision_v::Size; ++i) {
if (hit[i])
// which box id??
hitlist.push_back(BoxIdDistancePair_t(box * kVc::precision_v::Size + i, distance[i]));
}
#endif
}
// interpret as binary number and do a switch statement
// do a big switch statement here
// switch( size[0] + size[1] + size[2] ){
// case 0: {
// for( auto box = 0; box < vecsize; ++box ){
// kVc::precision_v distance = BoxImplementation<translation::kIdentity,
// rotation::kIdentity>::IntersectCachedKernel<kVc,0,0,0>(
// &corners[2*box],
// point,
// invdir,
// 0, vecgeom::kInfLength );
// kVc::bool_v hit = distance < vecgeom::kInfLength;
// //std::cerr << hit << "\n";
// hitcount += hit.count();
// } break; }
// case 3: {
// for( auto box = 0; box < vecsize; ++box ){
// kVc::precision_v distance = BoxImplementation<translation::kIdentity,
// rotation::kIdentity>::IntersectCachedKernel<kVc,1,1,1>(
// &corners[2*box],
// point,
// invdir,
// 0, vecgeom::kInfLength );
// kVc::bool_v hit = distance < vecgeom::kInfLength;
// //std::cerr << hit << "\n";
// hitcount += hit.count();
// } break; }
// default : std::cerr << "DEFAULT CALLED\n";
// }
#ifdef INNERTIMER
timer.Stop();
std::cerr << "# VECTOR hitting " << hitcount << "\n";
std::cerr << "# VECTOR timer " << timer.Elapsed() << "\n";
#endif
return hitcount;
}
示例13: benchCachingNoVector
int benchCachingNoVector(Vector3D<Precision> const &point, Vector3D<Precision> const &dir,
std::vector<Vector3D<Precision>> const &corners
#ifdef SORTHITBOXES
,
Container_t &hitlist
#endif
)
{
#ifdef INNERTIMER
Stopwatch timer;
timer.Start();
#endif
Vector3D<Precision> invdir(1. / dir.x(), 1. / dir.y(), 1. / dir.z());
int vecsize = corners.size() / 2;
int hitcount = 0;
int sign[3];
sign[0] = invdir.x() < 0;
sign[1] = invdir.y() < 0;
sign[2] = invdir.z() < 0;
// interpret as binary number and do a switch statement
// do a big switch statement here
// int code = 2 << size[0] + 2 << size[1] + 2 << size[2];
for (auto box = 0; box < vecsize; ++box) {
double distance = BoxImplementation<translation::kIdentity, rotation::kIdentity>::IntersectCachedKernel2<kScalar>(
&corners[2 * box], point, invdir, sign[0], sign[1], sign[2], 0, vecgeom::kInfLength);
if (distance < vecgeom::kInfLength) {
hitcount++;
#ifdef SORTHITBOXES
hitlist.push_back(BoxIdDistancePair_t(box, distance));
#endif
}
}
// switch( size[0] + size[1] + size[2] ){
// case 0: {
// for( auto box = 0; box < vecsize; ++box ){
// double distance = BoxImplementation<translation::kIdentity,
// rotation::kIdentity>::IntersectCachedKernel<kScalar,0,0,0>(
// &corners[2*box],
// point,
// invdir,
// 0, vecgeom::kInfLength );
// if( distance < vecgeom::kInfLength ) hitcount++;
// } break; }
// case 3: {
// for( auto box = 0; box < vecsize; ++box ){
// double distance = BoxImplementation<translation::kIdentity,
// rotation::kIdentity>::IntersectCachedKernel<kScalar,1,1,1>(
// &corners[2*box],
// point,
// invdir,
// 0, vecgeom::kInfLength );
// if( distance < vecgeom::kInfLength ) hitcount++;
// } break; }
// default : std::cerr << "DEFAULT CALLED\n";
// }
#ifdef INNERTIMER
timer.Stop();
std::cerr << "# CACHED hitting " << hitcount << "\n";
std::cerr << "# CACHED timer " << timer.Elapsed() << "\n";
#endif
return hitcount;
}
示例14: XRayWithVecGeom
void XRayWithVecGeom(int axis,
Vector3D<Precision> origin,
Vector3D<Precision> bbox,
Vector3D<Precision> dir,
double axis1_start, double axis1_end,
double axis2_start, double axis2_end,
int data_size_x,
int data_size_y,
double pixel_axis,
int * image) {
Stopwatch internaltimer;
NavigationState * newnavstate = NavigationState::MakeInstance( GeoManager::Instance().getMaxDepth() );
NavigationState * curnavstate = NavigationState::MakeInstance( GeoManager::Instance().getMaxDepth() );
int counter = 0;
// std::cout << pixel_count_1 << " " << pixel_count_2 << "\n";
internaltimer.Start();
// set start point of XRay
Vector3D<Precision> p(0,0,0);
SimpleNavigator nav;
curnavstate->Clear();
nav.LocatePoint( GeoManager::Instance().GetWorld(), p, *curnavstate, true );
#ifdef VECGEOM_DISTANCE_DEBUG
gGeoManager->GetCurrentNavigator()->FindNode( p.x(), p.y(), p.z() );
#endif
double distancetravelled=0.;
int crossedvolumecount=0;
if(VERBOSE) {
std::cout << " StartPoint(" << p[0] << ", " << p[1] << ", " << p[2] << ")";
std::cout << " Direction <" << dir[0] << ", " << dir[1] << ", " << dir[2] << ">"<< std::endl;
}
while( ! curnavstate->IsOutside() ) {
double step = 0;
newnavstate->Clear();
double safety=nav.GetSafety( p, *curnavstate );
nav.FindNextBoundaryAndStep( p,
dir,
*curnavstate,
*newnavstate,
1e20, step);
distancetravelled+=step;
if(VERBOSE) {
if( newnavstate->Top() != NULL )
std::cout << " *VG " << counter++ << " * point" << p << " goes to " << " VolumeName: " << newnavstate->Top()->GetLabel();
else
std::cout << " NULL: ";
std::cout << " step[" << step << "]";
std::cout << " safety[" << safety << "]";
std::cout << " boundary[" << newnavstate->IsOnBoundary() << "]\n";
}
// here we have to propagate particle ourselves and adjust navigation state
p = p + dir*(step + 1E-6);
newnavstate->CopyTo(curnavstate);
// Increase passed_volume
// TODO: correct counting of travel in "world" bounding box
if(step>0) crossedvolumecount++;
} // end while
if(VERBOSE) {
std::cout << " PassedVolume:" << "<"<< crossedvolumecount << " ";
std::cout << " Distance: " << distancetravelled<< std::endl;
}
internaltimer.Stop();
std::cout << "VecGeom time " << internaltimer.Elapsed() << "\n";
NavigationState::ReleaseInstance( curnavstate );
NavigationState::ReleaseInstance( newnavstate );
} // end XRayWithVecGeom
示例15:
__attribute__((noinline)) void benchmarkG4Navigator(SOA3D<Precision> const &points, SOA3D<Precision> const &dirs)
{
G4VPhysicalVolume *world(vecgeom::G4GeoManager::Instance().GetG4GeometryFromROOT());
if (world != nullptr) G4GeoManager::Instance().LoadG4Geometry(world);
// Note: Vector3D's are expressed in cm, while G4ThreeVectors are expressed in mm
const Precision cm = 10.; // cm --> mm conversion
G4Navigator &g4nav = *(G4GeoManager::Instance().GetNavigator());
// G4TouchableHistory **g4history = new G4TouchableHistory *[nPoints];
Precision *steps = new Precision[points.size()];
// get a time estimate to just to locate points
// (The reason is that the G4Navigator has a huge internal state and it is not foreseen to do
// multi-track processing with a basked of G4TouchableHistories as states)
Stopwatch timer;
timer.Start();
for (decltype(points.size()) i = 0; i < points.size(); ++i) {
G4ThreeVector g4pos(points[i].x() * cm, points[i].y() * cm, points[i].z() * cm);
G4ThreeVector g4dir(dirs[i].x(), dirs[i].y(), dirs[i].z());
// false --> locate from top
g4nav.LocateGlobalPointAndSetup(g4pos, &g4dir, false);
}
Precision timeForLocate = (Precision)timer.Stop();
#ifdef CALLGRIND_ENABLED
CALLGRIND_START_INSTRUMENTATION;
#endif
timer.Start();
for (decltype(points.size()) i = 0; i < points.size(); ++i) {
G4ThreeVector g4pos(points[i].x() * cm, points[i].y() * cm, points[i].z() * cm);
G4ThreeVector g4dir(dirs[i].x(), dirs[i].y(), dirs[i].z());
G4double maxStep = kInfLength;
// false --> locate from top
G4VPhysicalVolume const *vol = g4nav.LocateGlobalPointAndSetup(g4pos, &g4dir, false);
(void)vol;
G4double safety = 0.0;
steps[i] = g4nav.ComputeStep(g4pos, g4dir, maxStep, safety);
G4ThreeVector nextPos = g4pos + (steps[i] + 1.0e-6) * g4dir;
// TODO: save touchable history array - returnable? symmetrize with ROOT/VECGEOM benchmark
g4nav.SetGeometricallyLimitedStep();
volatile G4VPhysicalVolume const *nextvol = g4nav.LocateGlobalPointAndSetup(nextPos);
(void)nextvol;
}
timer.Stop();
std::cerr << (Precision)timer.Elapsed() - timeForLocate << "\n";
#ifdef CALLGRIND_ENABLED
CALLGRIND_STOP_INSTRUMENTATION;
CALLGRIND_DUMP_STATS;
#endif
// cleanup
// delete[] g4history;
//_mm_free(maxSteps);
double accum{0.};
size_t hittargetchecksum{0L};
for (decltype(points.size()) i = 0; i < points.size(); ++i) {
accum += steps[i];
if (WithSafety) {
// saccum += safeties[i];
}
// target checksum via the table held from RootGeoManager
// hittargetchecksum +=
// (size_t)RootGeoManager::Instance().Lookup(outstates[i]->GetNode(outstates[i]->GetLevel()))->id();
}
std::cerr << "accum G4 " << accum / cm << " target checksum " << hittargetchecksum << "\n";
}