14 #include <Vc/Allocator>
43 #define VSUM(v) v.x() + v.y()
45 #define VSUM(v) v.X() + v.Y()
49 #elif DIM_3 // 3 Dimensions
63 #define VSUM(v) v.x() + v.y() + v.z()
65 #define VSUM(v) v.X() + v.Y() + v.Z()
68 #else // default is 4D
85 #define VSUM(v) v.x() + v.y() + v.z()
88 #define VSUM(v) v.X() + v.Y() + v.Z()
103 const int NLOOP = 5000000;
109 template<
class Vector>
126 void MathFunction_sin();
127 void MathFunction_exp();
128 void MathFunction_log();
129 void MathFunction_atan();
130 void MathFunction_atan2();
138 void PrintResult(Double_type s);
142 std::vector<Vector> vlist;
143 std::vector<Vector> vlist2;
144 std::vector<Double_type> scale;
145 std::vector <std::vector <double > > vcoords;
151 template <
class Vector,
class Vector_V,
int Size>
156 for (
int i = 0; i <
Size; ++i) {
157 vlist[i].GetCoordinates(coord);
158 for (
int j = 0; j < dim; ++j)
159 vcoord[j][i] = coord[j];
161 vret.SetCootdinates(vcoord);
179 template<
class Vector>
180 TestVector<Vector>::TestVector() :
196 for (
int i = 0; i<
N; ++i) {
198 Double_type x = r.Uniform(-1,1);
199 Double_type y = r.Uniform(-1,1);
200 Double_type z = r.Uniform(-1,1);
201 Double_type t = r.Uniform(2,10);
202 Double_type s = r.Uniform(0,1);
203 coord[0] =
x; coord[1] =
y; coord[2] =
z; coord[3] =
t;
204 vcoords[i] = std::vector<double>(coord,coord+4);
212 x[j] = r.Uniform(-1,1);
213 y[j] = r.Uniform(-1,1);
214 z[j] = r.Uniform(-1,1);
215 t[j] = r.Uniform(2,10);
216 s[j] = r.Uniform(0,1);
217 coord[0] = x[j]; coord[1] = y[j]; coord[2] = z[j]; coord[3] = t[j];
218 vcoords[i*Vc::double_v::Size+j] = std::vector<double>(coord,coord+4);
223 vlist[i] = Vector( x, y );
225 vlist[i] = Vector( x, y, z);
227 vlist[i] = Vector( x, y, z, t);
232 std::cout <<
"test using " <<
typeid(vlist[0]).
name() << std::endl;
233 std::cout <<
"Vector used " << vlist[0] << std::endl;
234 std::cout <<
"Vector used " << vlist[1] << std::endl;
237 for (
int i = 0; i<
N; ++i) {
239 vlist2[i] = (i < N-1) ? vlist[i+1] : vlist[0];
241 Double_type x1 = vlist[i].X();
242 Double_type y1 = vlist[i].Y();
243 Double_type z1 = vlist[i].Z();
244 Double_type t1 = vlist[i].E();
245 Double_type x2 = (i< N-1) ? vlist[i+1].
X() : vlist[0].X();
246 Double_type y2 = (i< N-1) ? vlist[i+1].
Y() : vlist[0].Y();
247 Double_type z2 = (i< N-1) ? vlist[i+1].
Z() : vlist[0].Z();
248 Double_type t2 = (i< N-1) ? vlist[i+1].
E() : vlist[0].E();
254 for (j = 0; j< Vc::double_v::Size-1; ++j) {
260 j = Vc::double_v::Size-1;
265 vlist2[i] = Vector( x, y, z, t);
272 template<
class Vector>
273 void TestVector<Vector>::PrintResult(Double_type s)
277 std::cout <<
"value " << s << std::endl << std::endl;
283 std::cout <<
"value " << s2 << std::endl << std::endl;
287 template<
class Vector>
288 void TestVector<Vector>::Read()
298 for (
int i = 0; i<
N; ++i) {
299 Vector v3 = vlist[i];
307 std::cout <<
"Time for read v3 :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
313 template<
class Vector>
321 for (
int i = 0; i<
N; ++i) {
322 Vector v3 = vlist[i] + vlist2[i];
330 std::cout <<
"Time for v3 = v1 + v2 :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
335 template<
class Vector>
336 void TestVector<Vector>::Add2()
345 for (
int i = 0; i<
N; ++i) {
354 std::cout <<
"Time for v2 += v1 :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
359 template<
class Vector>
360 void TestVector<Vector>::Sub()
367 for (
int i = 0; i<
N; ++i) {
368 Vector v3 = vlist[i] - vlist2[i];
373 std::cout <<
"Time for v3 = v1 - v2 :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
378 template<
class Vector>
379 void TestVector<Vector>::Sub2()
387 for (
int i = 0; i<
N; ++i) {
393 std::cout <<
"Time for v2 -= v1 :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
399 template<
class Vector>
400 void TestVector<Vector>::Scale()
407 for (
int i = 0; i<
N; ++i) {
408 Vector v3 = scale[i]*vlist[i];
413 std::cout <<
"Time for v2 = A * v1 :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
418 template<
class Vector>
419 void TestVector<Vector>::Scale2()
427 for (
int i = 0; i<
N; ++i) {
434 std::cout <<
"Time for v *= a :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
439 template<
class Vector>
440 void TestVector<Vector>::Divide()
447 for (
int i = 0; i<
N; ++i) {
448 Vector v3 = vlist[i]/scale[i];
453 std::cout <<
"Time for v2 = v1 / a :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
458 template<
class Vector>
459 void TestVector<Vector>::Divide2()
467 for (
int i = 0; i<
N; ++i) {
474 std::cout <<
"Time for v /= a :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
480 template<
class Vector>
481 void TestVector<Vector>::Operations()
491 const int n =
sqrt(N)+0.5;
494 for (
int i = 0; i<
n; ++i) {
495 for (
int j = 0; j< i; ++j) {
509 const int nn =
sqrt(vcoords.size()) + 0.5;
510 int ncomb = nn*(nn-1)/2;
511 std::vector<double> vc1x(ncomb+4);
512 std::vector<double> vc2x(ncomb+4);
513 std::vector<double> vc1y(ncomb+4);
514 std::vector<double> vc2y(ncomb+4);
515 std::vector<double> vc1z(ncomb+4);
516 std::vector<double> vc2z(ncomb+4);
517 std::vector<double> vc1t(ncomb+4);
518 std::vector<double> vc2t(ncomb+4);
522 for (
int i = 0; i< nn; ++i) {
523 std::copy(vcoords[i].begin(), vcoords[i].end(),c1);
525 for (
int j = 0; j< i; ++j) {
526 std::copy(vcoords[j].begin(), vcoords[j].end(),c2);
540 Vector
v1; Vector v2;
541 for (
int i = 0; i< ncomb2; ++i) {
549 v1.SetCoordinates( cv);
557 v2.SetCoordinates( cv2);
566 std::cout <<
"Time for Operation :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
573 template<
class Vector>
574 void TestVector<Vector>::Operations()
586 const int n =
sqrt(N)+0.5;
589 const int nn =
sqrt(vcoords.size()) + 0.5;
590 int ncomb = nn*(nn-1)/2;
591 std::vector<double> vc1x(ncomb+4);
592 std::vector<double> vc2x(ncomb+4);
593 std::vector<double> vc1y(ncomb+4);
594 std::vector<double> vc2y(ncomb+4);
595 std::vector<double> vc1z(ncomb+4);
596 std::vector<double> vc2z(ncomb+4);
597 std::vector<double> vc1t(ncomb+4);
598 std::vector<double> vc2t(ncomb+4);
602 for (
int i = 0; i< nn; ++i) {
603 std::copy(vcoords[i].begin(), vcoords[i].end(),c1);
605 for (
int j = 0; j< i; ++j) {
606 std::copy(vcoords[j].begin(), vcoords[j].end(),c2);
623 for (
int i = 0; i<
n; ++i) {
624 for (
int j = 0; j< i; ++j) {
639 if (ncomb%Vc::double_v::Size != 0) ncomb2 += 1;
640 Vector
v1; Vector v2;
641 for (
int i = 0; i< ncomb2; ++i) {
649 v1.SetCoordinates( cv);
657 v2.SetCoordinates( cv2);
672 std::cout <<
"Time for Operation :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
679 template<
class Vector>
680 void TestVector<Vector>::Boost()
689 for (
int i = 0; i<
N; ++i) {
697 std::cout <<
"Time for Boost :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
704 template<
class Vector>
705 void TestVector<Vector>::MathFunction_exp()
712 for (
int l = 0;
l<NLOOP/10; ++
l) {
713 for (
int i = 0; i<
N; ++i) {
719 std::cout <<
"Time for Exp Function :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
721 fTime[fTest++] = w.
CpuTime()*TSCALE*10;
726 template<
class Vector>
727 void TestVector<Vector>::MathFunction_log()
734 for (
int l = 0;
l<NLOOP/10; ++
l) {
735 for (
int i = 0; i<
N; ++i) {
741 std::cout <<
"Time for Log Function :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
743 fTime[fTest++] = w.
CpuTime()*TSCALE*10;
746 template<
class Vector>
747 void TestVector<Vector>::MathFunction_sin()
754 for (
int l = 0;
l<NLOOP/100; ++
l) {
755 for (
int i = 0; i<
N; ++i) {
761 std::cout <<
"Time for Sin Function :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
763 fTime[fTest++] = w.
CpuTime()*TSCALE*100;
766 template<
class Vector>
767 void TestVector<Vector>::MathFunction_atan()
774 for (
int l = 0;
l<NLOOP/100; ++
l) {
775 for (
int i = 0; i<
N; ++i) {
781 std::cout <<
"Time for Atan Function :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
783 fTime[fTest++] = w.
CpuTime()*TSCALE*100;
786 template<
class Vector>
787 void TestVector<Vector>::MathFunction_atan2()
794 for (
int l = 0;
l<NLOOP/100; ++
l) {
795 for (
int i = 0; i<
N; ++i) {
801 std::cout <<
"Time for Atan2 Function :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
803 fTime[fTest++] = w.
CpuTime()*TSCALE*100;
806 #ifdef HAS_VDT // use VDT
807 template<
class Vector>
808 void TestVector<Vector>::MathFunction()
818 for (
int i = 0; i<
N; ++i) {
823 vdt::fast_atanv(N,x,r);
824 for (
int i = 0; i<
N; ++i) {
831 std::cout <<
"Time for MathFUnction(VDT) :\t" << w.
RealTime() <<
"\t" << w.
CpuTime() << std::endl;
838 template<
class Vector>
839 void TestVector<Vector>::PrintSummary()
841 std::cout <<
"\nResults for " <<
typeid(vlist[0]).
name() << std::endl;
842 std::cout <<
" v3 = v1+v2"
858 for (
int i = 3; i < fTest; ++i) {
859 std::cout << std::setw(8) << fTime[i] <<
" ";
861 std::cout << std::endl << std::endl;
865 TestVector<VecType>
t;
868 std::cout <<
"testing using Vc: Vc size is " << Vc::double_v::Size <<
" Looping on " << N <<
" vectors" << std::endl;
869 std::cout <<
"Implementation type: " <<
VC_IMPL << std::endl;
871 std::cout <<
"testing using standard double's. Looping on " << N <<
" vectors" << std::endl;
895 t.MathFunction_log();
896 t.MathFunction_exp();
897 t.MathFunction_sin();
898 t.MathFunction_atan();
899 t.MathFunction_atan2();
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
TMatrixT< Element > & Add(TMatrixT< Element > &target, Element scalar, const TMatrixT< Element > &source)
Modify addition: target += scalar * source.
Random number generator class based on the maximally quidistributed combined Tausworthe generator by ...
LVector boostX(const LVector &v, T beta)
Boost a generic Lorentz Vector class along the X direction with a factor beta The only requirement on...
Class describing a generic position vector (point) in 3 dimensions.
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
static Vc_ALWAYS_INLINE Vector< T > abs(const Vector< T > &x)
Vector1::Scalar InvariantMass(const Vector1 &v1, const Vector2 &v2)
return the invariant mass of two LorentzVector The only requirement on the LorentzVector is that they...
void MakeVcVector(const Vector *vlist, Vector_V &vret)
Vector< double > double_v
VECTOR_NAMESPACE::double_v double_v
Class describing a generic position vector (point) in 2 dimensions.
double atan2(double, double)
ROOT::Math::XYZTVector VecType
std::complex< float_v > Z
Class describing a generic displacement vector in 2 dimensions.