Nektar++
Functions
library/UnitTests/LibUtilities/VmathTimer/main.cpp File Reference
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/BasicUtils/VmathArray.hpp>
#include <LibUtilities/SimdLib/tinysimd.hpp>
#include <LibUtilities/BasicUtils/Likwid.hpp>
#include <LibUtilities/BasicUtils/Timer.h>

Go to the source code of this file.

Functions

int main (int argc, char const *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char const *  argv[] 
)

Definition at line 44 of file library/UnitTests/LibUtilities/VmathTimer/main.cpp.

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

References Vmath::SIMD::Gathr(), Vmath::Gathr(), LIKWID_MARKER_CLOSE, LIKWID_MARKER_GET, LIKWID_MARKER_INIT, LIKWID_MARKER_REGISTER, LIKWID_MARKER_START, LIKWID_MARKER_STOP, and LIKWID_MARKER_THREADINIT.