10
10
// expected results.
11
11
// --------------------------------------------------------------------------
12
12
#include " cl_processor.hpp"
13
+ #include " parallel_test.h"
13
14
#include " xpti/xpti_trace_framework.h"
14
15
15
16
#include < atomic>
@@ -125,6 +126,7 @@ void TestCorrectness::runStringTableTestThreads(
125
126
(double )(Strings.size () + LookupCount + DuplicateCount) /
126
127
(NumStrings * 3 ) * 100 ;
127
128
} else { // Multi-threaded run
129
+ BS::thread_pool tp (NumThreads);
128
130
std::vector<char *> Strings;
129
131
std::vector<xpti::string_id_t > IDs;
130
132
Strings.resize (NumStrings);
@@ -139,36 +141,39 @@ void TestCorrectness::runStringTableTestThreads(
139
141
140
142
{
141
143
int Count = 0 ;
142
- std::vector<int > MRange (NumStrings, 0 );
143
- std::for_each (MRange.begin (), MRange.end (),
144
- [&](int &n) { n += Count++; });
145
-
146
- std::for_each (
147
- std::execution::par, MRange.begin (), MRange.end (), [&](int &i) {
148
- char *TableStrRef = nullptr ;
149
- std::string StrName = " Function" + std::to_string (i);
150
- IDs[i] = xptiRegisterString (StrName.c_str (), &TableStrRef);
151
- Strings[i] = TableStrRef;
152
- });
153
-
154
- std::for_each (std::execution::par, MRange.begin (), MRange.end (),
155
- [&](int &i) {
156
- const char *TableStrRef = xptiLookupString (IDs[i]);
157
- if (TableStrRef == Strings[i])
158
- ++LookupCount;
159
- });
144
+
145
+ auto RegisterString = [&](int min, int max) {
146
+ for (int i = min; i < max; ++i) {
147
+ char *TableStrRef = nullptr ;
148
+ std::string StrName = " Function" + std::to_string (i);
149
+ IDs[i] = xptiRegisterString (StrName.c_str (), &TableStrRef);
150
+ Strings[i] = TableStrRef;
151
+ }
152
+ };
153
+ PARALLEL_FOR (tp, RegisterString, 0 , NumStrings);
154
+
155
+ auto LookupString = [&](int min, int max) {
156
+ for (int i = min; i < max; ++i) {
157
+ const char *TableStrRef = xptiLookupString (IDs[i]);
158
+ if (TableStrRef == Strings[i])
159
+ ++LookupCount;
160
+ }
161
+ };
162
+ PARALLEL_FOR (tp, LookupString, 0 , NumStrings);
160
163
ModelRow[(int )STColumns::Lookups] = LookupCount;
161
164
162
- std::for_each (std::execution::par, MRange.begin (), MRange.end (),
163
- [&](int &i) {
164
- char *TableStrRef = nullptr ;
165
- std::string StrName = " Function" + std::to_string (i);
166
- xpti::string_id_t id =
167
- xptiRegisterString (StrName.c_str (), &TableStrRef);
168
- if (StrName == TableStrRef && id == IDs[i] &&
169
- TableStrRef == Strings[i])
170
- ++DuplicateCount;
171
- });
165
+ auto CheckLookup = [&](int min, int max) {
166
+ for (int i = min; i < max; ++i) {
167
+ char *TableStrRef = nullptr ;
168
+ std::string StrName = " Function" + std::to_string (i);
169
+ xpti::string_id_t id =
170
+ xptiRegisterString (StrName.c_str (), &TableStrRef);
171
+ if (StrName == TableStrRef && id == IDs[i] &&
172
+ TableStrRef == Strings[i])
173
+ ++DuplicateCount;
174
+ }
175
+ };
176
+ PARALLEL_FOR (tp, CheckLookup, 0 , NumStrings);
172
177
ModelRow[(int )STColumns::DuplicateInserts] = DuplicateCount;
173
178
174
179
ModelRow[(int )STColumns::PassRate] =
@@ -266,10 +271,8 @@ void TestCorrectness::runTracepointTestThreads(int RunNo, int NumThreads,
266
271
(TracepointCount * 4 ) * 100 ;
267
272
} else {
268
273
274
+ BS::thread_pool tp (NumThreads);
269
275
int Count = 0 ;
270
- std::vector<size_t > MRange (TracepointCount, 0 );
271
- std::for_each (MRange.begin (), MRange.end (),
272
- [&](size_t &n) { n += Count++; });
273
276
274
277
std::vector<xpti::payload_t *> Payloads;
275
278
std::vector<int64_t > UIds;
@@ -285,51 +288,57 @@ void TestCorrectness::runTracepointTestThreads(int RunNo, int NumThreads,
285
288
std::atomic<int > LookupCount = {0 }, DuplicateCount = {0 },
286
289
PayloadCount = {0 };
287
290
288
- std::for_each (
289
- std::execution::par, MRange.begin (), MRange.end (), [&](size_t &i) {
290
- std::string fn = " Function" + std::to_string (i);
291
- xpti::payload_t P = xpti::payload_t (fn.c_str (), MSource, (int )i,
292
- (int )i % 80 , (void *)i);
293
- xpti::trace_event_data_t *Ev = xptiMakeEvent (
294
- fn.c_str (), &P, (uint16_t )xpti::trace_event_type_t ::algorithm,
295
- xpti::trace_activity_type_t ::active, &MInstanceID);
296
- if (Ev) {
297
- UIds[i] = Ev->unique_id ;
298
- Payloads[i] = Ev->reserved .payload ;
299
- Events[i] = Ev;
300
- }
301
- });
291
+ auto MakeEvent = [&](int min, int max) {
292
+ for (size_t i = min; i < max; ++i) {
293
+ std::string fn = " Function" + std::to_string (i);
294
+ xpti::payload_t P = xpti::payload_t (fn.c_str (), MSource, (int )i,
295
+ (int )i % 80 , (void *)i);
296
+ xpti::trace_event_data_t *Ev = xptiMakeEvent (
297
+ fn.c_str (), &P, (uint16_t )xpti::trace_event_type_t ::algorithm,
298
+ xpti::trace_activity_type_t ::active, &MInstanceID);
299
+ if (Ev) {
300
+ UIds[i] = Ev->unique_id ;
301
+ Payloads[i] = Ev->reserved .payload ;
302
+ Events[i] = Ev;
303
+ }
304
+ }
305
+ };
306
+ PARALLEL_FOR (tp, MakeEvent, 0 , TracepointCount);
302
307
ModelRow[(int )TPColumns::Insertions] = (long double )Events.size ();
303
308
304
- std::for_each (std::execution::par, MRange.begin (), MRange.end (),
305
- [&](size_t &i) {
306
- std::string fn = " Function" + std::to_string (i);
307
- const xpti::trace_event_data_t *Ev = xptiFindEvent (UIds[i]);
308
- if (Ev && Ev->unique_id == UIds[i])
309
- LookupCount++;
310
- });
309
+ auto EventLookup = [&](int min, int max) {
310
+ for (size_t i = min; i < max; ++i) {
311
+ std::string fn = " Function" + std::to_string (i);
312
+ const xpti::trace_event_data_t *Ev = xptiFindEvent (UIds[i]);
313
+ if (Ev && Ev->unique_id == UIds[i])
314
+ LookupCount++;
315
+ }
316
+ };
317
+ PARALLEL_FOR (tp, EventLookup, 0 , TracepointCount);
311
318
ModelRow[(int )TPColumns::Lookups] = LookupCount;
312
319
313
- std::for_each (
314
- std::execution::par, MRange.begin (), MRange.end (), [&](size_t &i) {
315
- std::string fn = " Function" + std::to_string (i);
316
- xpti::payload_t P = xpti::payload_t (fn.c_str (), MSource, (int )i,
317
- (int )i % 80 , (void *)i);
318
- xpti::trace_event_data_t *Ev = xptiMakeEvent (
319
- fn.c_str (), &P, (uint16_t )xpti::trace_event_type_t ::algorithm,
320
- xpti::trace_activity_type_t ::active, &MInstanceID);
321
- if (Ev) {
322
- if (Ev->unique_id == UIds[i]) {
323
- ++DuplicateCount;
324
- }
325
- xpti::payload_t *RP = Ev->reserved .payload ;
326
- if (Ev->unique_id == UIds[i] && RP &&
327
- std::string (RP->name ) == std::string (P.name ) &&
328
- std::string (RP->source_file ) == std::string (P.source_file ) &&
329
- RP->line_no == P.line_no && RP->column_no == P.column_no )
330
- ++PayloadCount;
320
+ auto CheckEvents = [&](int min, int max) {
321
+ for (size_t i = min; i < max; ++i) {
322
+ std::string fn = " Function" + std::to_string (i);
323
+ xpti::payload_t P = xpti::payload_t (fn.c_str (), MSource, (int )i,
324
+ (int )i % 80 , (void *)i);
325
+ xpti::trace_event_data_t *Ev = xptiMakeEvent (
326
+ fn.c_str (), &P, (uint16_t )xpti::trace_event_type_t ::algorithm,
327
+ xpti::trace_activity_type_t ::active, &MInstanceID);
328
+ if (Ev) {
329
+ if (Ev->unique_id == UIds[i]) {
330
+ ++DuplicateCount;
331
331
}
332
- });
332
+ xpti::payload_t *RP = Ev->reserved .payload ;
333
+ if (Ev->unique_id == UIds[i] && RP &&
334
+ std::string (RP->name ) == std::string (P.name ) &&
335
+ std::string (RP->source_file ) == std::string (P.source_file ) &&
336
+ RP->line_no == P.line_no && RP->column_no == P.column_no )
337
+ ++PayloadCount;
338
+ }
339
+ }
340
+ };
341
+ PARALLEL_FOR (tp, CheckEvents, 0 , TracepointCount);
333
342
ModelRow[(int )TPColumns::DuplicateInserts] = DuplicateCount;
334
343
ModelRow[(int )TPColumns::PayloadLookup] = PayloadCount;
335
344
ModelRow[(int )TPColumns::PassRate] =
@@ -426,60 +435,61 @@ void TestCorrectness::runNotificationTestThreads(
426
435
ModelRow[(int )NColumns::Notifications] = (long double )Acc;
427
436
ModelRow[(int )NColumns::PassRate] = (long double )(Acc) / (NotifyCount)*100 ;
428
437
} else {
438
+
439
+ BS::thread_pool tp (NumThreads);
429
440
std::atomic<int > NotifyCount = {0 };
430
441
431
442
int Count = 0 ;
432
- std::vector<size_t > MRange (CallbackCount, 0 );
433
- std::for_each (MRange.begin (), MRange.end (),
434
- [&](size_t &n) { n += Count++; });
435
-
436
- std::for_each (std::execution::par_unseq, MRange.begin (), MRange.end (),
437
- [&](size_t &i) {
438
- if (i >= TPCount)
439
- return ;
440
-
441
- size_t Index = (int )i;
442
- std::string fn = " Function" + std::to_string (i);
443
- xpti::payload_t P =
444
- xpti::payload_t (fn.c_str (), MSource, (int )Index,
445
- (int )Index % 80 , (void *)(i % 10 ));
446
- xpti::trace_event_data_t *Ev = xptiMakeEvent (
447
- fn.c_str (), &P,
448
- (uint16_t )xpti::trace_event_type_t ::algorithm,
449
- xpti::trace_activity_type_t ::active, &MInstanceID);
450
- if (Ev) {
451
- UIds[Index] = Ev->unique_id ;
452
- Payloads[Index] = Ev->reserved .payload ;
453
- Events[Index] = Ev;
454
- }
455
- ++NotifyCount;
456
- });
443
+
444
+ auto MakeEvents = [&](int min, int max) {
445
+ for (size_t i = min; i < max; ++i) {
446
+ if (i >= TPCount)
447
+ return ;
448
+
449
+ size_t Index = (int )i;
450
+ std::string fn = " Function" + std::to_string (i);
451
+ xpti::payload_t P = xpti::payload_t (fn.c_str (), MSource, (int )Index,
452
+ (int )Index % 80 , (void *)(i % 10 ));
453
+ xpti::trace_event_data_t *Ev = xptiMakeEvent (
454
+ fn.c_str (), &P, (uint16_t )xpti::trace_event_type_t ::algorithm,
455
+ xpti::trace_activity_type_t ::active, &MInstanceID);
456
+ if (Ev) {
457
+ UIds[Index] = Ev->unique_id ;
458
+ Payloads[Index] = Ev->reserved .payload ;
459
+ Events[Index] = Ev;
460
+ }
461
+ ++NotifyCount;
462
+ }
463
+ };
464
+ PARALLEL_FOR (tp, MakeEvents, 0 , CallbackCount);
457
465
458
466
std::string RowTitle = " Threads " + std::to_string (NumThreads);
459
467
auto &ModelRow = Model.addRow (RunNo, RowTitle);
460
468
ModelRow[(int )NColumns::Threads] = NumThreads;
461
469
462
- std::for_each (
463
- std::execution::par, MRange.begin (), MRange.end (), [&](size_t &i) {
464
- if (i < TPCount)
465
- return ;
466
-
467
- size_t Index = (int )i % TPCount;
468
- void *Address = (void *)(Index % 10 );
469
- std::string fn = " Function" + std::to_string (Index);
470
- xpti::payload_t P = xpti::payload_t (fn.c_str (), MSource, (int )Index,
471
- (int )Index % 80 , Address);
472
- xpti::trace_event_data_t *Ev = xptiMakeEvent (
473
- fn.c_str (), &P, (uint16_t )xpti::trace_event_type_t ::algorithm,
474
- xpti::trace_activity_type_t ::active, &MInstanceID);
475
- if (Ev && Ev->unique_id == UIds[Index]) {
476
- uint8_t TP = (Index % 10 ) + 1 ;
477
- uint16_t TPType = (uint16_t )(TP << 1 );
478
- xpti::framework::scoped_notify ev (" xpti" , TPType, nullptr , Ev,
479
- MInstanceID, nullptr );
480
- NotifyCount++;
481
- }
482
- });
470
+ auto NotifyCallbacks = [&](int min, int max) {
471
+ for (size_t i = min; i < max; ++i) {
472
+ if (i < TPCount)
473
+ return ;
474
+
475
+ size_t Index = (int )i % TPCount;
476
+ void *Address = (void *)(Index % 10 );
477
+ std::string fn = " Function" + std::to_string (Index);
478
+ xpti::payload_t P = xpti::payload_t (fn.c_str (), MSource, (int )Index,
479
+ (int )Index % 80 , Address);
480
+ xpti::trace_event_data_t *Ev = xptiMakeEvent (
481
+ fn.c_str (), &P, (uint16_t )xpti::trace_event_type_t ::algorithm,
482
+ xpti::trace_activity_type_t ::active, &MInstanceID);
483
+ if (Ev && Ev->unique_id == UIds[Index]) {
484
+ uint8_t TP = (Index % 10 ) + 1 ;
485
+ uint16_t TPType = (uint16_t )(TP << 1 );
486
+ xpti::framework::scoped_notify ev (" xpti" , TPType, nullptr , Ev,
487
+ MInstanceID, nullptr );
488
+ NotifyCount++;
489
+ }
490
+ }
491
+ };
492
+ PARALLEL_FOR (tp, NotifyCallbacks, 0 , CallbackCount);
483
493
484
494
uint64_t Acc = 0 ;
485
495
for (int i = 0 ; i < TPCount; ++i) {
0 commit comments