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 int count = 0;
55 double time = 0.0;
56
57#ifndef NEKTAR_USE_LIKWID
58 boost::ignore_unused(count, time);
59#endif
60
61 if (argc < 2)
62 {
63 nPts = 100;
64 }
65 else
66 {
67 nPts = std::stoi(argv[1]);
68 }
69
70 std::cout << "number of points\t" << nPts << '\n';
71
72 // number of experiments
73 constexpr size_t experiments = 1 << 18;
74 {
75 // data should be randomized
76 Array<OneD, NekDouble> data{nPts * 10, 0.0};
77 Array<OneD, NekDouble> dataTrace{nPts, 0.0};
78 size_t zero = 0;
79 Array<OneD, size_t> indexTrace{nPts, zero};
80
81 // inizialize index (should be randomized)
82 for (size_t i = 0; i < nPts; ++i)
83 {
84 indexTrace[i] = i;
85 }
86
87 LIKWID_MARKER_START("GathrArray");
88 for (size_t j = 0; j < experiments; ++j)
89 {
90 // time
91 Vmath::Gathr(nPts, data, indexTrace, dataTrace);
92 }
93 LIKWID_MARKER_STOP("GathrArray");
94 // get likwid events
95 constexpr short CPU_CLK_UNHALTED_REF_id = 2;
96 int nevents{20};
97 std::vector<double> events(nevents);
98 //
99 LIKWID_MARKER_GET("GathrArray", &nevents, events.data(), &time, &count);
100 // print out CPE
101 double cpeGathrArray =
102 events[CPU_CLK_UNHALTED_REF_id] / nPts / experiments;
103 std::cout << "GathrArray likwid CPE\t" << cpeGathrArray << '\n';
104 std::cout << dataTrace[0] << std::endl;
105 }
106
107 {
108 // data should be randomized
109 Array<OneD, NekDouble> data{nPts * 10, 0.0};
110 Array<OneD, NekDouble> dataTrace{nPts, 0.0};
111 size_t zero = 0;
112 Array<OneD, size_t> indexTrace{nPts, zero};
113
114 // inizialize index (should be randomized)
115 for (size_t i = 0; i < nPts; ++i)
116 {
117 indexTrace[i] = i;
118 }
119
120 LIKWID_MARKER_START("GathrSimd");
121 for (size_t j = 0; j < experiments; ++j)
122 {
123 // time
124 Vmath::SIMD::Gathr(nPts, data.data(), indexTrace.data(),
125 dataTrace.data());
126 }
127 LIKWID_MARKER_STOP("GathrSimd");
128 // get likwid events
129 constexpr short CPU_CLK_UNHALTED_REF_id = 2;
130 int nevents{20};
131 std::vector<double> events(nevents);
132 //
133 LIKWID_MARKER_GET("GathrSimd", &nevents, events.data(), &time, &count);
134 // print out CPE
135 double cpeGathrSimd =
136 events[CPU_CLK_UNHALTED_REF_id] / nPts / experiments;
137 std::cout << "GathrSimd likwid CPE\t" << cpeGathrSimd << '\n';
138 std::cout << dataTrace[0] << std::endl;
139 }
140
141 {
142 // data should be randomized
143 Array<OneD, NekDouble> data{nPts * 10, 0.0};
144 Array<OneD, NekDouble> dataTrace{nPts, 0.0};
145 size_t zero = 0;
146 Array<OneD, size_t> indexTrace{nPts, zero};
147
148 // inizialize index (should be randomized)
149 for (size_t i = 0; i < nPts; ++i)
150 {
151 indexTrace[i] = i;
152 }
153
154 LIKWID_MARKER_START("GathrScalar");
155 for (size_t j = 0; j < experiments; ++j)
156 {
157 // time
158 Vmath::Gathr(nPts, data.data(), indexTrace.data(),
159 dataTrace.data());
160 }
161 LIKWID_MARKER_STOP("GathrScalar");
162 // get likwid events
163 constexpr short CPU_CLK_UNHALTED_REF_id = 2;
164 int nevents{20};
165 std::vector<double> events(nevents);
166 //
167 LIKWID_MARKER_GET("GathrScalar", &nevents, events.data(), &time,
168 &count);
169 // print out CPE
170 double cpeGathrScalar =
171 events[CPU_CLK_UNHALTED_REF_id] / nPts / experiments;
172 std::cout << "GathrScalar likwid CPE\t" << cpeGathrScalar << '\n';
173 std::cout << dataTrace[0] << std::endl;
174 }
175
177}
#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:474
void Gathr(int n, const T *sign, const T *x, const int *y, T *z)
Gather vector z[i] = sign[i]*x[y[i]].
Definition: Vmath.cpp:800

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.