Nektar++
library/UnitTests/LibUtilities/VmathTimer/main.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: main.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
38
41
42using namespace Nektar;
43
44int main(int argc, char const *argv[])
45{
46
49 LIKWID_MARKER_REGISTER("GathrArray");
50 LIKWID_MARKER_REGISTER("GathrScalar");
51 LIKWID_MARKER_REGISTER("GathrSimd");
52
53 size_t nPts;
54 [[maybe_unused]] int count = 0;
55 [[maybe_unused]] double time = 0.0;
56
57 if (argc < 2)
58 {
59 nPts = 100;
60 }
61 else
62 {
63 nPts = std::stoi(argv[1]);
64 }
65
66 std::cout << "number of points\t" << nPts << '\n';
67
68 // number of experiments
69 constexpr size_t experiments = 1 << 18;
70 {
71 // data should be randomized
72 Array<OneD, NekDouble> data{nPts * 10, 0.0};
73 Array<OneD, NekDouble> dataTrace{nPts, 0.0};
74 size_t zero = 0;
75 Array<OneD, size_t> indexTrace{nPts, zero};
76
77 // inizialize index (should be randomized)
78 for (size_t i = 0; i < nPts; ++i)
79 {
80 indexTrace[i] = i;
81 }
82
83 LIKWID_MARKER_START("GathrArray");
84 for (size_t j = 0; j < experiments; ++j)
85 {
86 // time
87 Vmath::Gathr(nPts, data, indexTrace, dataTrace);
88 }
89 LIKWID_MARKER_STOP("GathrArray");
90 // get likwid events
91 constexpr short CPU_CLK_UNHALTED_REF_id = 2;
92 int nevents{20};
93 std::vector<double> events(nevents);
94 //
95 LIKWID_MARKER_GET("GathrArray", &nevents, events.data(), &time, &count);
96 // print out CPE
97 double cpeGathrArray =
98 events[CPU_CLK_UNHALTED_REF_id] / nPts / experiments;
99 std::cout << "GathrArray likwid CPE\t" << cpeGathrArray << '\n';
100 std::cout << dataTrace[0] << std::endl;
101 }
102
103 {
104 // data should be randomized
105 Array<OneD, NekDouble> data{nPts * 10, 0.0};
106 Array<OneD, NekDouble> dataTrace{nPts, 0.0};
107 size_t zero = 0;
108 Array<OneD, size_t> indexTrace{nPts, zero};
109
110 // inizialize index (should be randomized)
111 for (size_t i = 0; i < nPts; ++i)
112 {
113 indexTrace[i] = i;
114 }
115
116 LIKWID_MARKER_START("GathrSimd");
117 for (size_t j = 0; j < experiments; ++j)
118 {
119 // time
120 Vmath::SIMD::Gathr(nPts, data.data(), indexTrace.data(),
121 dataTrace.data());
122 }
123 LIKWID_MARKER_STOP("GathrSimd");
124 // get likwid events
125 constexpr short CPU_CLK_UNHALTED_REF_id = 2;
126 int nevents{20};
127 std::vector<double> events(nevents);
128 //
129 LIKWID_MARKER_GET("GathrSimd", &nevents, events.data(), &time, &count);
130 // print out CPE
131 double cpeGathrSimd =
132 events[CPU_CLK_UNHALTED_REF_id] / nPts / experiments;
133 std::cout << "GathrSimd likwid CPE\t" << cpeGathrSimd << '\n';
134 std::cout << dataTrace[0] << std::endl;
135 }
136
137 {
138 // data should be randomized
139 Array<OneD, NekDouble> data{nPts * 10, 0.0};
140 Array<OneD, NekDouble> dataTrace{nPts, 0.0};
141 size_t zero = 0;
142 Array<OneD, size_t> indexTrace{nPts, zero};
143
144 // inizialize index (should be randomized)
145 for (size_t i = 0; i < nPts; ++i)
146 {
147 indexTrace[i] = i;
148 }
149
150 LIKWID_MARKER_START("GathrScalar");
151 for (size_t j = 0; j < experiments; ++j)
152 {
153 // time
154 Vmath::Gathr(nPts, data.data(), indexTrace.data(),
155 dataTrace.data());
156 }
157 LIKWID_MARKER_STOP("GathrScalar");
158 // get likwid events
159 constexpr short CPU_CLK_UNHALTED_REF_id = 2;
160 int nevents{20};
161 std::vector<double> events(nevents);
162 //
163 LIKWID_MARKER_GET("GathrScalar", &nevents, events.data(), &time,
164 &count);
165 // print out CPE
166 double cpeGathrScalar =
167 events[CPU_CLK_UNHALTED_REF_id] / nPts / experiments;
168 std::cout << "GathrScalar likwid CPE\t" << cpeGathrScalar << '\n';
169 std::cout << dataTrace[0] << std::endl;
170 }
171
173}
#define LIKWID_MARKER_THREADINIT
Definition: Likwid.hpp:43
#define LIKWID_MARKER_START(regionTag)
Definition: Likwid.hpp:46
#define LIKWID_MARKER_CLOSE
Definition: Likwid.hpp:48
#define LIKWID_MARKER_INIT
Definition: Likwid.hpp:42
#define LIKWID_MARKER_REGISTER(regionTag)
Definition: Likwid.hpp:45
#define LIKWID_MARKER_STOP(regionTag)
Definition: Likwid.hpp:47
#define LIKWID_MARKER_GET(regionTag, nevents, events, time, count)
Definition: Likwid.hpp:49
int main(int argc, char const *argv[])
void Gathr(const I n, const T *x, const I *y, T *z)
Gather vector z[i] = x[y[i]].
Definition: VmathSIMD.hpp:472
void Gathr(I n, const T *x, const I *y, T *z)
Gather vector z[i] = x[y[i]].
Definition: Vmath.hpp:507