Exemple #1
0
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;
}
__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";
  }
}
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());
}
Exemple #4
0
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());
}
Exemple #5
0
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;
}
//////////////////////////////////
// main function
int main(int argc, char * argv[])
{
  int axis= 0;

  double axis1_start= 0.;
  double axis1_end= 0.;

  double axis2_start= 0.;
  double axis2_end= 0.;

  double pixel_width= 0;
  double pixel_axis= 1.;

  if( argc < 5 )
  {
    std::cerr<< std::endl;
    std::cerr<< "Need to give rootfile, volumename, axis and number of axis"<< std::endl;
    std::cerr<< "USAGE : ./XRayBenchmarkFromROOTFile [rootfile] [VolumeName] [ViewDirection(Axis)]"
             << "[PixelWidth(OutputImageSize)] [--usolids|--vecgeom(Default:usolids)] [--novoxel(Default:voxel)]"
             << std::endl;
    std::cerr<< "  ex) ./XRayBenchmarkFromROOTFile cms2015.root BSCTrap y 95"<< std::endl;
    std::cerr<< "      ./XRayBenchmarkFromROOTFile cms2015.root PLT z 500 --vecgeom --novoxel"<< std::endl<< std::endl;
    return 1;
  }

  TGeoManager::Import( argv[1] );
  std::string testvolume( argv[2] );

  if( strcmp(argv[3], "x")==0 )
    axis= 1;
  else if( strcmp(argv[3], "y")==0 )
    axis= 2;
  else if( strcmp(argv[3], "z")==0 )
    axis= 3;
  else
  {
    std::cerr<< "Incorrect axis"<< std::endl<< std::endl;
    return 1;
  }

  pixel_width= atof(argv[4]);

  for(auto i= 5; i< argc; i++)
  {
    if( ! strcmp(argv[i], "--usolids") )
      usolids= true;
    if( ! strcmp(argv[i], "--vecgeom") )
      usolids= false;
    if( ! strcmp(argv[i], "--novoxel") )
      voxelize = false;
  }

  int found = 0;
  TGeoVolume * foundvolume = NULL;
  // now try to find shape with logical volume name given on the command line
  TObjArray *vlist = gGeoManager->GetListOfVolumes( );
  for( auto i = 0; i < vlist->GetEntries(); ++i )
  {
    TGeoVolume * vol = reinterpret_cast<TGeoVolume*>(vlist->At( i ));
    std::string fullname(vol->GetName());
    
    std::size_t founds = fullname.compare(testvolume);
    if ( founds==0 ){
      found++;
      foundvolume = vol;

      std::cerr << "("<< i<< ")found matching volume " << foundvolume->GetName()
        << " of type " << foundvolume->GetShape()->ClassName() << "\n";
    }
  }

  std::cerr << "volume found " << found << " times \n\n";

  // if volume not found take world
  if( ! foundvolume ) {
      std::cerr << "specified volume not found; xraying complete detector\n";
      foundvolume = gGeoManager->GetTopVolume();
  }

  if( foundvolume ) {
    foundvolume->GetShape()->InspectShape();
    std::cerr << "volume capacity " 
          << foundvolume->GetShape()->Capacity() << "\n";

    // get bounding box to generate x-ray start positions
    double dx = ((TGeoBBox*)foundvolume->GetShape())->GetDX()*1.05;
    double dy = ((TGeoBBox*)foundvolume->GetShape())->GetDY()*1.05;
    double dz = ((TGeoBBox*)foundvolume->GetShape())->GetDZ()*1.05;
    double origin[3]= {0., };
    origin[0]= ((TGeoBBox*)foundvolume->GetShape())->GetOrigin()[0];
    origin[1]= ((TGeoBBox*)foundvolume->GetShape())->GetOrigin()[1];
    origin[2]= ((TGeoBBox*)foundvolume->GetShape())->GetOrigin()[2];
    
    TGeoMaterial * matVacuum = new TGeoMaterial("Vacuum",0,0,0);
    TGeoMedium * vac = new TGeoMedium("Vacuum",1,matVacuum);

    TGeoVolume* boundingbox= gGeoManager->MakeBox("BoundingBox", vac,
            std::abs(origin[0]) + dx,
            std::abs(origin[1]) + dy,
            std::abs(origin[2]) + dz );

    // TGeoManager * geom = boundingbox->GetGeoManager();
    std::cout << gGeoManager->CountNodes() << "\n";

    if(! voxelize ) DeleteROOTVoxels();

    gGeoManager = 0;

    TGeoManager * mgr2 = new TGeoManager();

//    delete gGeoManager;
//    gGeoManager = new TGeoManager();
    boundingbox->AddNode( foundvolume, 1);
    mgr2->SetTopVolume( boundingbox );
    mgr2->CloseGeometry();
    gGeoManager = mgr2;
    gGeoManager->Export("DebugGeom.root");

    mgr2->GetTopNode()->GetMatrix()->Print();

    std::cout << gGeoManager->CountNodes() << "\n";
    //delete world->GetVoxels();
    //world->SetVoxelFinder(0);
    
    std::cout<< std::endl;
    std::cout<< "BoundingBoxDX: "<< dx<< std::endl;
    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;
    
    if(axis== 1)
    {
      dir.Set(1., 0., 0.);
      //Transformation3D trans( 0, 0, 0, 5, 5, 5);
      //trans.Print();
     // dir = trans.TransformDirection( Vector3D<Precision> (1,0,0));

      axis1_start= origin[1]- dy;
      axis1_end= origin[1]+ dy;
      axis2_start= origin[2]- dz;
      axis2_end= origin[2]+ dz;
      pixel_axis= (dy*2)/pixel_width;
    }
    else if(axis== 2)
    {
      dir.Set(0., 1., 0.);
      //vecgeom::Transformation3D trans( 0, 0, 0, 5, 5, 5);
      //dir = trans.TransformDirection(dir);
      axis1_start= origin[0]- dx;
      axis1_end= origin[0]+ dx;
      axis2_start= origin[2]- dz;
      axis2_end= origin[2]+ dz;
      pixel_axis= (dx*2)/pixel_width;
    }
    else if(axis== 3)
    {
      dir.Set(0., 0., 1.);
      //vecgeom::Transformation3D trans( 0, 0, 0, 5, 5, 5);
      //dir = trans.TransformDirection(dir);
      axis1_start= origin[0]- dx;
      axis1_end= origin[0]+ dx;
      axis2_start= origin[1]- dy;
      axis2_end= origin[1]+ dy;
      pixel_axis= (dx*2)/pixel_width;
    }

    // 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 );
    timer.Stop();

    std::stringstream G4image;
    G4image << imagenamebase.str();
    G4image << "_Geant4.bmp";
    make_bmp(volume_result_Geant4, G4image.str().c_str(), data_size_x, data_size_y);
    std::cout << std::endl;
    std::cout << " Geant4 Elapsed time : "<< timer.Elapsed() << std::endl;
    make_diff_bmp(volume_result, volume_result_Geant4, "diffROOTGeant4.bmp", data_size_x, data_size_y);
#endif

    // convert current gGeoManager to a VecGeom geometry
    RootGeoManager::Instance().LoadRootGeometry();
    std::cout << "Detector loaded " << "\n";
    ABBoxManager::Instance().InitABBoxesForCompleteGeometry();
    std::cout << "voxelized " << "\n";
    timer.Start();
#ifdef CALLGRIND
    CALLGRIND_START_INSTRUMENTATION;
#endif
    XRayWithVecGeom<SimpleNavigator>( 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_VecGeom );
#ifdef CALLGRIND
    CALLGRIND_START_INSTRUMENTATION;
    CALLGRIND_DUMP_STATS;
#endif
    timer.Stop();

    std::stringstream VecGeomimage;
    VecGeomimage << imagenamebase.str();
    VecGeomimage << "_VecGeom.bmp";
    make_bmp(volume_result_VecGeom, VecGeomimage.str().c_str(), data_size_x, data_size_y);

    make_diff_bmp(volume_result, volume_result_VecGeom, "diffROOTVecGeom.bmp", data_size_x, data_size_y);

    std::cout << std::endl;
    std::cout << " VecGeom Elapsed time : "<< timer.Elapsed() << std::endl;

    timer.Start();
#ifdef CALLGRIND
    CALLGRIND_START_INSTRUMENTATION;
#endif
    XRayWithVecGeom<ABBoxNavigator>( 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_VecGeomABB );
#ifdef CALLGRIND
    CALLGRIND_STOP_INSTRUMENTATION;
    CALLGRIND_DUMP_STATS;
#endif
    timer.Stop();

    std::stringstream VecGeomABBimage;
    VecGeomABBimage << imagenamebase.str();
    VecGeomABBimage << "_VecGeomABB.bmp";
    make_bmp(volume_result_VecGeomABB, VecGeomABBimage.str().c_str(), data_size_x, data_size_y);

    make_diff_bmp(volume_result_VecGeom, volume_result_VecGeomABB, "diffVecGeomSimplevsABB.bmp", data_size_x, data_size_y);
    make_diff_bmp(volume_result, volume_result_VecGeomABB, "diffROOTVecGeomABB.bmp", data_size_x, data_size_y);


    std::cout << std::endl;
    std::cout << " VecGeom ABB Elapsed time : "<< timer.Elapsed() << std::endl;

    return 0;

    // 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;

    std::stringstream VecGeomimagevec;
    VecGeomimagevec << imagenamebase.str();
    VecGeomimagevec << "_VecGeomVecNav.bmp";
    make_bmp(volume_result, VecGeomimagevec.str().c_str(), data_size_x, data_size_y);



    delete[] volume_result;
  }
  return 0;
}
Exemple #7
0
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());
}
Exemple #8
0
//////////////////////////////////
// main function
int main(int argc, char * argv[])
{
  int axis= 0;

  double axis1_start= 0.;
  double axis1_end= 0.;

  double axis2_start= 0.;
  double axis2_end= 0.;

  double pixel_axis= 1.;

  if( argc < 5 )
  {
    std::cerr<< std::endl;
    std::cerr<< "Need to give rootfile, volumename, direction phi and direction theta (in degrees)"<< std::endl;
    return 1;
  }

  TGeoManager::Import( argv[1] );
  std::string testvolume( argv[2] );

  //double directionphi   = atof(argv[3])*vecgeom::kDegToRad;
  //double directiontheta = atof(argv[4])*vecgeom::kDegToRad;

  for(auto i= 5; i< argc; i++)
  {
    if( ! strcmp(argv[i], "--usolids") )
      usolids= true;
    if( ! strcmp(argv[i], "--vecgeom") )
      usolids= false;
    if( ! strcmp(argv[i], "--novoxel") )
      voxelize = false;
  }

  int found = 0;
  TGeoVolume * foundvolume = NULL;
  // now try to find shape with logical volume name given on the command line
  TObjArray *vlist = gGeoManager->GetListOfVolumes( );
  for( auto i = 0; i < vlist->GetEntries(); ++i )
  {
    TGeoVolume * vol = reinterpret_cast<TGeoVolume*>(vlist->At( i ));
    std::string fullname(vol->GetName());
    
    std::size_t founds = fullname.compare(testvolume);
    if ( founds==0 ){
      found++;
      foundvolume = vol;

      std::cerr << "("<< i<< ")found matching volume " << foundvolume->GetName()
        << " of type " << foundvolume->GetShape()->ClassName() << "\n";
    }
  }

  std::cerr << "volume found " << found << " times \n\n";

  // if volume not found take world
  if( ! foundvolume ) {
      std::cerr << "specified volume not found; xraying complete detector\n";
      foundvolume = gGeoManager->GetTopVolume();
  }

  if( foundvolume ) {
    foundvolume->GetShape()->InspectShape();
    std::cerr << "volume capacity " 
          << foundvolume->GetShape()->Capacity() << "\n";

    // get bounding box to generate x-ray start positions
    double dx = ((TGeoBBox*)foundvolume->GetShape())->GetDX()*1.5;
    double dy = ((TGeoBBox*)foundvolume->GetShape())->GetDY()*1.5;
    double dz = ((TGeoBBox*)foundvolume->GetShape())->GetDZ()*1.5;
    double origin[3]= {0., };
    origin[0]= ((TGeoBBox*)foundvolume->GetShape())->GetOrigin()[0];
    origin[1]= ((TGeoBBox*)foundvolume->GetShape())->GetOrigin()[1];
    origin[2]= ((TGeoBBox*)foundvolume->GetShape())->GetOrigin()[2];
    
    TGeoMaterial * matVacuum = new TGeoMaterial("Vacuum",0,0,0);
    TGeoMedium * vac = new TGeoMedium("Vacuum",1,matVacuum);

    TGeoVolume* boundingbox= gGeoManager->MakeBox("BoundingBox", vac,
            std::abs(origin[0]) + dx,
            std::abs(origin[1]) + dy,
            std::abs(origin[2]) + dz );

    // TGeoManager * geom = boundingbox->GetGeoManager();
    std::cout << gGeoManager->CountNodes() << "\n";

    if(! voxelize ) DeleteROOTVoxels();

//    TGeoManager * mg1 = gGeoManager;
    gGeoManager = 0;

    TGeoManager * mgr2 = new TGeoManager();

//    delete gGeoManager;
//    gGeoManager = new TGeoManager();
    boundingbox->AddNode( foundvolume, 1);
    mgr2->SetTopVolume( boundingbox );
    mgr2->CloseGeometry();
    gGeoManager = mgr2;
    gGeoManager->Export("DebugGeom.root");

    mgr2->GetTopNode()->GetMatrix()->Print();

    std::cout << gGeoManager->CountNodes() << "\n";
    //delete world->GetVoxels();
    //world->SetVoxelFinder(0);
    
    std::cout<< std::endl;
    std::cout<< "BoundingBoxDX: "<< dx<< std::endl;
    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;
}
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;
      }

    }

    //parar timer
    this->swOtimizacao.Stop();

    //guardar ultimo status
    //this->historico.push_back(this->status);

    //logada final
    //logar tempos
    cout << "==================================" << endl;
    //logar linha e coluna permitidas encontradas
    cout << "Iteracao\t" << qtdIteracoes << endl;
    cout << "Media Primeira etapa:\t" << tempoTotalPrimeiraEtapa / qtdIteracoes << endl;
    cout << "Media Segunda etapa:\t" << tempoTotalSegundaEtapa / qtdIteracoes << endl;
    cout << "Media Algoritmo Troca:\t" << tempoTotalTroca / qtdIteracoes << endl;
    cout << "Media Seg/Iteracao:\t" << this->swOtimizacao.Elapsed() / qtdIteracoes << endl;
    cout << "==================================" << endl;

  }
  catch (exception e)
  {
    cout << endl << "Ocorreu um erro no algoritmo! " << e.what() << endl;
  }

}
Exemple #10
0
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.");
	}
}
Exemple #11
0
int main(int argc, char **argv) {

  /*ExecuteCuda();*/

  MPSReader* mpsReader;

  FObjetivo* funcao;
  //funcao.DirecaoOtimizacao = Minimizar;
  //funcao.addVariavel("x1", 6);
  //funcao.addVariavel("x2", 12);

  //funcao.addRestricao("Rest_1");
  //funcao.addVariavelRestricao("Rest_1", "x1", 0.6);
  //funcao.addVariavelRestricao("Rest_1", "x2", 1);
  //funcao.setDesigualdadeRestricao("Rest_1", MenorOuIgual);
  //funcao.setTermoLivreRestricao("Rest_1", 600);


  cout << "========================================" << endl;
  cout << "===========GPU Simplex Solver===========" << endl;
  cout << "========================================" << endl;
  cout << endl;

  cout << "Selecione o tipo de teste: " << endl;
  cout << endl;
  cout << "1 - DFL001 (Grande)" << endl;
  cout << "2 - KEN - 07 (Medio)" << endl;
  cout << "3 - AFIRO (Pequeno)" << endl;
  cout << "4 - Teste (Pequeno)" << endl;
  cout << "5 - Petr (Pequeno)" << endl;
  cout << "6 - ADLITTLE (Pequeno)" << endl;
  cout << "7 - SHARE2B (Pequeno)" << endl;
  cout << "8 - ISRAEL (Medio)" << endl;
  cout << "9 - CAPRI (Medio)" << endl;
  cout << "a - PILOT (Medio)" << endl;
  cout << endl;

  char x = getchar();

  cout << endl;
  cout << "Leitura da funcao objetivo iniciada..." << endl;

  string diretorio = "C:\\Users\\Shirugaron\\Source\\Repos\\cuda-simplex\\NetLib.Problemas";

  switch (x) {
  case '1':
    //Problema grande
    mpsReader = new MPSReader(diretorio + "\\DFL001.mps");
    break;

  case '2':
    //Problema medio
    mpsReader = new MPSReader(diretorio + "\\KEN-07.mps");
    break;

  case '3':
    //Problema pequeno
    mpsReader = new MPSReader(diretorio + "\\AFIRO.mps");
    break;

  case '4':
    //Problema teste
    mpsReader = new MPSReader(diretorio + "\\MPS_Test.txt");
    break;

  case '5':
    //Problema teste
    mpsReader = new MPSReader(diretorio + "\\MPS_Petr_Exemplo.txt");
    /*DESCRICAO ======================
    Neste exemplo, as condicoes de sinal das variaveis do Petr sao transformados em
    outras restricoes.
    **/

    break;

  case '6':
    mpsReader = new MPSReader(diretorio + "\\ADLITTLE.mps");
    break;

  case '7':
    mpsReader = new MPSReader(diretorio + "\\SHARE2B.mps");
    break;

  case '8':
    mpsReader = new MPSReader(diretorio + "\\ISRAEL.mps");
    break;

  case '9':
    mpsReader = new MPSReader(diretorio + "\\CAPRI.mps");
    break;

  case 'a':
    mpsReader = new MPSReader(diretorio + "\\PILOT.mps");
    break;

  case 'b':
    mpsReader = new MPSReader(diretorio + "\\2Var_3Rest.mps");
    break;

  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;
}
Exemple #12
0
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;
}
Exemple #13
0
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;
}
__attribute__((noinline)) void benchmarkROOTNavigator(SOA3D<Precision> const &points, SOA3D<Precision> const &dirs)
{

  TGeoNavigator *rootnav      = ::gGeoManager->GetCurrentNavigator();
  auto nPoints                = points.size();
  TGeoBranchArray **instates  = new TGeoBranchArray *[nPoints];
  TGeoBranchArray **outstates = new TGeoBranchArray *[nPoints];
  Precision *steps            = new Precision[points.size()];
  Precision *safeties;
  if (WithSafety) {
    safeties = new Precision[points.size()];
  }
  // we don't have the input state container in ROOT form
  // we generate them but do not take this into account for the timing measurement
  for (size_t i = 0; i < nPoints; ++i) {
    Vector3D<Precision> const &pos = points[i];
    rootnav->ResetState();
    rootnav->FindNode(pos.x(), pos.y(), pos.z());
    instates[i]  = TGeoBranchArray::MakeInstance(GeoManager::Instance().getMaxDepth());
    outstates[i] = TGeoBranchArray::MakeInstance(GeoManager::Instance().getMaxDepth());
    instates[i]->InitFromNavigator(rootnav);
  }
#ifdef CALLGRIND_ENABLED
  CALLGRIND_START_INSTRUMENTATION;
#endif
  Stopwatch timer;
  timer.Start();
  for (size_t i = 0; i < nPoints; ++i) {
    Vector3D<Precision> const &pos = points[i];
    Vector3D<Precision> const &dir = dirs[i];
    rootnav->ResetState();
    instates[i]->UpdateNavigator(rootnav);

    rootnav->SetCurrentPoint(pos.x(), pos.y(), pos.z());
    rootnav->SetCurrentDirection(dir.x(), dir.y(), dir.z());
    if (WithSafety) {
      safeties[i] = rootnav->Safety(true);
    }
    if (WithReloc) {
      volatile TGeoNode *node = rootnav->FindNextBoundaryAndStep(kInfLength);
      (void)node;
    } else {
      volatile TGeoNode *node = rootnav->FindNextBoundary(kInfLength);
      (void)node;
    }
    steps[i] = rootnav->GetStep();
    if (WithReloc) {
      // save output states ( for fair comparison with VecGeom )
      outstates[i]->InitFromNavigator(rootnav);
    }
  }
  timer.Stop();
#ifdef CALLGRIND_ENABLED
  CALLGRIND_STOP_INSTRUMENTATION;
  CALLGRIND_DUMP_STATS;
#endif
  std::cerr << timer.Elapsed() << "\n";
  double accum(0.);
  double saccum(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();
  }
  delete[] steps;
  if (WithSafety) {
    delete safeties;
  }

  // cleanup states
  for (decltype(points.size()) i = 0; i < points.size(); ++i) {
    delete instates[i];
    delete outstates[i];
  }
  delete[] instates;
  delete[] outstates;

  std::cerr << "accum  TGeo " << accum << " target checksum " << hittargetchecksum << "\n";
  if (WithSafety) {
    std::cerr << "safety accum  TGeo " << saccum << "\n";
  }
}
Exemple #15
0
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
__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";
}
Exemple #17
0
// stressing the vector interface of navigator
void XRayWithVecGeom_VecNav(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) {
    int counter=0;

    // we need N navstates ( where N should be a multiple of the SIMD width )
    unsigned int N = 8;
    NavigationState ** newnavstates = new NavigationState*[N];
    NavigationState ** curnavstates = new NavigationState*[N];
    for( unsigned int j=0;j<N;++j ){
        newnavstates[j] = NavigationState::MakeInstance( GeoManager::Instance().getMaxDepth() );
        curnavstates[j] = NavigationState::MakeInstance( GeoManager::Instance().getMaxDepth() );
    }

    SOA3D<Precision> points(N);
    SOA3D<Precision> dirs(N);
    SOA3D<Precision> workspaceforlocalpoints(N);
    SOA3D<Precision> workspaceforlocaldirs(N);

    // initialize dirs from dir
    for( unsigned int j=0; j<N; ++j )
        dirs.set(j, dir.x(), dir.y(),dir.z());

    double * steps    = new double[N];
    double * psteps   = new double[N];
    double * safeties = new double[N];
    int * nextnodeworkspace = new int[N]; // some workspace for the navigator; not important here
    // initialize physical steps to infinity
    for(unsigned int j=0;j<N;++j)
        psteps[j]=vecgeom::kInfinity;


    Stopwatch internaltimer;
    internaltimer.Start();
    SimpleNavigator nav;
    // initialize points and locate them is serialized
    for( unsigned int j=0; j<N; ++j ){
                  points.set( j, 0, 0, 0 );
                  curnavstates[j]->Clear();
                  nav.LocatePoint( GeoManager::Instance().GetWorld(), points[j], *curnavstates[j], true );
    }

    double distancetravelled=0.;
    int crossedvolumecount=0;
    if(VERBOSE) {
       std::cout << " StartPoint(" << points[0].x() << ", " << points[1].y() << ", " <<
                  points[2].z() << ")";
       std::cout << " Direction <" << dirs[0].x() << ", " << dirs[1].y() << ", " << dirs[2].z() << ">"<< std::endl;
    }

    // we do the while loop only over the first "particle index"
    // the rest of the particles should follow exactly the same path
    while( ! curnavstates[0]->IsOutside() ) {
        nav.FindNextBoundaryAndStep(
                points,
                dirs,
                workspaceforlocalpoints,
                workspaceforlocaldirs,
                curnavstates,
                newnavstates,
                psteps,
                safeties,
                steps,
                nextnodeworkspace);

        //std::cout << "step " << step << "\n";
        distancetravelled+=steps[0];

        // TODO: DO HERE AN ASSERTION THAT ALL STEPS AGREE

        if(VERBOSE) {
            if( newnavstates[0]->Top() != NULL )
              std::cout << " *VGV " << counter++ << " * point" << points[0] << " goes to " << " VolumeName: " << newnavstates[0]->Top()->GetLabel();
            else
              std::cout << "  NULL: ";

              std::cout << " step[" << steps[0] << "]";
              std::cout << " boundary[" << newnavstates[0]->IsOnBoundary() << "]\n";
        }

        // here we have to propagate particle ourselves and adjust navigation state
        // propagate points
        for(unsigned int j=0;j<N;++j){
            points.set(j, points[j] + dirs[j]*(steps[0] + 1E-6));
            newnavstates[j]->CopyTo(curnavstates[j]);
        }

        // Increase passed_volume
        // TODO: correct counting of travel in "world" bounding box
        if(steps[0]>0) crossedvolumecount++;
     } // end while


    internaltimer.Stop();
    std::cout << "VecGeom vec time (per track) " << internaltimer.Elapsed()/N << "\n";

    for( unsigned int j=0; j<N ; ++j ) {
        NavigationState::ReleaseInstance( curnavstates[j] );
        NavigationState::ReleaseInstance( newnavstates[j] );
    }
} // end XRayWithVecGeomVectorInterface
Exemple #18
0
void MessageConnection::OnRead()
{
    bool            yield, closed;
    unsigned        pos, msglength, nread, msgbegin, msgend, required;
    uint64_t        start;
    Stopwatch       sw;
    ReadBuffer      msg;

    if (!readActive)
    {
        if (resumeRead.IsActive())
            STOP_FAIL(1, "Program bug: resumeRead.IsActive() should be false.");
        EventLoop::Add(&resumeRead);
        return;
    }

    sw.Start();

    Log_Trace("Read buffer: %B", tcpread.buffer);

    tcpread.requested = IO_READ_ANY;
    pos = 0;
    start = NowClock();
    yield = false;

    while(true)
    {
        msglength = BufferToUInt64(tcpread.buffer->GetBuffer() + pos,
                                   tcpread.buffer->GetLength() - pos, &nread);

        if (msglength > tcpread.buffer->GetSize() - NumDigits(msglength) - 1)
        {
            Log_Trace();
            required = msglength + NumDigits(msglength) + 1;
            if (required > MESSAGING_MAX_SIZE)
            {
                Log_Trace();
                OnClose();
                return;
            }
            tcpread.buffer->Allocate(required);
            break;
        }

        if (nread == 0 || (unsigned) tcpread.buffer->GetLength() - pos <= nread)
            break;

        if (tcpread.buffer->GetCharAt(pos + nread) != ':')
        {
            Log_Trace("Message protocol error");
            OnClose();
            return;
        }

        msgbegin = pos + nread + 1;
        msgend = pos + nread + 1 + msglength;

        if ((unsigned) tcpread.buffer->GetLength() < msgend)
        {
            // read more
            //tcpread.requested = msgend - pos;
            break;
        }

        msg.SetBuffer(tcpread.buffer->GetBuffer() + msgbegin);
        msg.SetLength(msglength);
        closed = OnMessage(msg);
        if (closed)
            return;

        pos = msgend;

        // if the user called Close() in OnMessageRead()
        if (state != CONNECTED)
            return;

        if (tcpread.buffer->GetLength() == msgend)
            break;

        if (NowClock() - start >= YIELD_TIME || !readActive)
        {
            // let other code run every YIELD_TIME msec
            yield = true;
            if (resumeRead.IsActive())
                STOP_FAIL(1, "Program bug: resumeRead.IsActive() should be false.");
            EventLoop::Add(&resumeRead);
            break;
        }
    }

    if (pos > 0)
    {
        memmove(tcpread.buffer->GetBuffer(), tcpread.buffer->GetBuffer() + pos,
                tcpread.buffer->GetLength() - pos);
        tcpread.buffer->Shorten(pos);
    }

    if (state == CONNECTED
            && !tcpread.active && !yield)
        IOProcessor::Add(&tcpread);

    sw.Stop();
    Log_Trace("time spent in OnRead(): %U", sw.Elapsed());
}
Exemple #19
0
int main()
{
  // number of boxes
  int numberofboxes = N * N * N;

  int code = (2 << 1) + (2 << 0) + (2 << 1);
  std::cerr << code << "\n";

  // setup AOS form of boxes
  std::vector<Vector3D<Precision>> uppercorners(numberofboxes);
  std::vector<Vector3D<Precision>> lowercorners(numberofboxes);

  // setup same in mixed array of corners ... upper-lower-upper-lower ...
  std::vector<Vector3D<Precision>> corners(2 * numberofboxes);

  // setup SOA form of boxes -- the memory layout should probably rather be SOA6D
  Vector3D<kVc::precision_v> *VcCorners = new Vector3D<kVc::precision_v>[ 2 * numberofboxes / kVc::precision_v::Size ];

  int counter1 = 0;
  int counter2 = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < N; ++k) {
        lowercorners[counter1] = Vector3D<Precision>(i, j, k);
        uppercorners[counter1] = Vector3D<Precision>(i + delta, j + delta, k + delta);

        corners[counter2] = lowercorners[counter1];
        counter2++;
        corners[counter2] = uppercorners[counter1];
        counter2++;

        counter1++;
      }
    }
  }

  // print boxes
  for (int i = 0; i < numberofboxes; ++i) {
    // std::cerr << "# " << i << " lower " << lowercorners[i] << " " << uppercorners[i] << "\n";
  }

  // set up VcCorners
  counter2 = 0;
  for (int i = 0; i < numberofboxes; i += kVc::precision_v::Size) {
    Vector3D<kVc::precision_v> lower;
    Vector3D<kVc::precision_v> upper;
    // assign by components
    for (int k = 0; k < kVc::precision_v::Size; ++k) {
      lower.x()[k] = lowercorners[i + k].x();
      lower.y()[k] = lowercorners[i + k].y();
      lower.z()[k] = lowercorners[i + k].z();
      upper.x()[k] = uppercorners[i + k].x();
      upper.y()[k] = uppercorners[i + k].y();
      upper.z()[k] = uppercorners[i + k].z();
    }
    // std::cerr << lower << "\n";
    // std::cerr << upper << "\n";
    VcCorners[counter2++] = lower;
    VcCorners[counter2++] = upper;
  }
  std::cerr << "assigned " << counter2 << "Vc vectors\n";

  // constructing samples
  std::vector<Vector3D<Precision>> points(SZ);
  std::vector<Vector3D<Precision>> directions(SZ);
  for (int i = 0; i < SZ; ++i) {
    points[i]     = Vector3D<Precision>(N * delta + 0.1, N * delta + 0.1, N * delta + 0.1);
    directions[i] = volumeUtilities::SampleDirection();
  }

  Container_t hitlist;
  hitlist.resize(2 * N);

  Stopwatch timer;
  int hits                    = 0;
  double meanfurthestdistance = 0;

  timer.Start();
  for (int i = 0; i < SZ; ++i) {
#ifdef SORTHITBOXES
    hitlist.clear();
#endif
    hits += benchCachingNoVector(points[i], directions[i], corners
#ifdef SORTHITBOXES
                                 ,
                                 hitlist
#endif
                                 );
#ifdef SORTHITBOXES
    sort(hitlist, HitBoxComparatorFunctor());
    meanfurthestdistance += hitlist.back().second;
// std::cerr << hitlist << "\n";
#endif
  }
  timer.Stop();
  std::cerr << "Cached times and hit " << timer.Elapsed() << " " << hits << " " << meanfurthestdistance << "\n";

  hits                 = 0;
  meanfurthestdistance = 0.;
  timer.Start();
  for (int i = 0; i < SZ; ++i) {
    hitlist.clear();
    hits += benchNoCachingNoVector(points[i], directions[i], corners
#ifdef SORTHITBOXES
                                   ,
                                   hitlist
#endif
                                   );
#ifdef SORTHITBOXES
    sort(hitlist, HitBoxComparatorFunctor());
    meanfurthestdistance += hitlist.back().second;
#endif
  }
  timer.Stop();
  std::cerr << "Ordinary times and hit " << timer.Elapsed() << " " << hits << " " << meanfurthestdistance << "\n";

  hits                 = 0;
  meanfurthestdistance = 0.;
  timer.Start();
  for (int i = 0; i < SZ; ++i) {
#ifdef SORTHITBOXES
    hitlist.clear();
#endif
    hits += benchCachingAndVector(points[i], directions[i], VcCorners, numberofboxes / kVc::precision_v::Size
#ifdef SORTHITBOXES
                                  ,
                                  hitlist
#endif
                                  );
#ifdef SORTHITBOXES
    sort(hitlist, HitBoxComparatorFunctor());
    meanfurthestdistance += hitlist.back().second;
// std::cerr << "VECTORHITLIST" << hitlist << "\n";
#endif
  }
  timer.Stop();
  std::cerr << "Vector times and hit " << timer.Elapsed() << " " << hits << " " << meanfurthestdistance << "\n";

  return 0;
}