Setting up causal profiling with "coz"

This commit is contained in:
Richard Thier 2021-12-14 17:29:33 +01:00
parent 675b90c0d8
commit c4ed2994ea
3 changed files with 35 additions and 6 deletions

View File

@ -51,9 +51,9 @@ namespace MagyarSort {
void debugRadics(size_t *radics) { void debugRadics(size_t *radics) {
for(size_t j = 0; j < DIGITS; ++j) { for(size_t j = 0; j < DIGITS; ++j) {
printf("d%d: ", j); printf("d%zu: ", j);
for(size_t i = 0; i < DIGIT_RANGE; ++i) { for(size_t i = 0; i < DIGIT_RANGE; ++i) {
printf("%d,", radics[i + DIGIT_RANGE*j]); printf("%zu,", radics[i + DIGIT_RANGE*j]);
} }
printf("\n\n"); printf("\n\n");
} }

View File

@ -1,6 +1,9 @@
debug: test.cpp magyarsort.h debug: test.cpp magyarsort.h
g++ test.cpp -g -std=c++14 -o test.out g++ test.cpp -g -std=c++14 -o test.out
release_coz: test.cpp magyarsort.h
g++ test.cpp -g1 -gdwarf-2 -std=c++14 -O2 -ldl -o test.out
release_debug_sym: test.cpp magyarsort.h release_debug_sym: test.cpp magyarsort.h
g++ test.cpp -g -std=c++14 -O2 -o test.out g++ test.cpp -g -std=c++14 -O2 -o test.out

View File

@ -7,18 +7,22 @@
// Number of input elements to generate - unused when CREEL is defined! // Number of input elements to generate - unused when CREEL is defined!
//#define SORT_WIDTH 200000000 //#define SORT_WIDTH 200000000
#define SORT_WIDTH 400000 #define SORT_WIDTH 40000000
// Uncomment this to use nibbles as digits and not bytes - CREEL defines this anyways // Uncomment this to use nibbles as digits and not bytes - CREEL defines this anyways
//#define MAGYAR_SORT_NIBBLE //#define MAGYAR_SORT_NIBBLE
// Uncomment if you want to see output before / after sorts (debugging for example) // Uncomment if you want to see output before / after sorts (debugging for example)
//#define PRINT_OUTPUT //#define PRINT_OUTPUT
#define SKA_SORT //#define SKA_SORT
// Uncomment for perf / cachegring and similar runs! // Uncomment for perf / cachegring and similar runs!
#define MEASURE_ONLY #define MEASURE_ONLY
// Uncomment this for performance measuring with "coz"
// XXX: Beware that we will do this many times of sorts!
#define COZ_MEASURE 400
/* Includes */ /* Includes */
#include <cstring> #include <cstring>
@ -34,6 +38,10 @@
#include "ska_sort.hpp" #include "ska_sort.hpp"
#endif // SKA_SORT #endif // SKA_SORT
#ifdef COZ_MEASURE
#include "coz.h"
#endif // COZ_MEASURE
/* Input generation and prerequisites */ /* Input generation and prerequisites */
#ifdef CREEL #ifdef CREEL
@ -122,6 +130,20 @@ int main() {
MagyarSort::sort(arr1, in1.size()); MagyarSort::sort(arr1, in1.size());
auto ourEnd = std::chrono::high_resolution_clock::now(); auto ourEnd = std::chrono::high_resolution_clock::now();
#ifdef COZ_MEASURE
std::vector<uint32_t> in_coz_common = GenerateInput();;
for(int i = 0; i < COZ_MEASURE; ++i) {
std::vector<uint32_t> in_coz = in_coz_common; // cpy
uint32_t *arr_coz = &(in_coz[0]);
MagyarSort::sort(arr1, in1.size());
COZ_PROGRESS_NAMED("magyarsort_progress");
if((i % 128) == 0) { printf("%d / %d\n", i, COZ_MEASURE); }
}
#endif // COZ_MEASURE
#ifdef PRINT_OUTPUT #ifdef PRINT_OUTPUT
printf("Our: "); printf("Our: ");
MagyarSort::debugArr(arr1, in1.size()); MagyarSort::debugArr(arr1, in1.size());
@ -139,14 +161,18 @@ int main() {
printf("Results:\n\n"); printf("Results:\n\n");
printf("- Sorted %zu elements", in1.size()); printf("- Sorted %zu elements", in1.size());
#ifndef MEASURE_ONLY #ifndef MEASURE_ONLY
if(good) printf("- Same result as std::sort!\n"); if(good) printf("- Same result as known sort result!\n");
else printf("- Differs from std::sort! Error!\n"); else printf("- Differs from known sort result! Error!\n");
printf("\n"); printf("\n");
auto stdElapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(stdEnd - stdBegin); auto stdElapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(stdEnd - stdBegin);
#endif // !MEASURE_ONLY #endif // !MEASURE_ONLY
auto ourElapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(ourEnd - ourBegin); auto ourElapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(ourEnd - ourBegin);
#ifndef MEASURE_ONLY #ifndef MEASURE_ONLY
#ifdef SKA_SORT
printf("Time (ska sort): %.3f ms.\n", stdElapsed.count() * 1e-6);
#else
printf("Time (std sort): %.3f ms.\n", stdElapsed.count() * 1e-6); printf("Time (std sort): %.3f ms.\n", stdElapsed.count() * 1e-6);
#endif
#endif // !MEASURE_ONLY #endif // !MEASURE_ONLY
printf("Time (our sort): %.3f ms.\n", ourElapsed.count() * 1e-6); printf("Time (our sort): %.3f ms.\n", ourElapsed.count() * 1e-6);