diff options
| author | KunoiSayami <[email protected]> | 2022-06-30 02:20:09 +0800 |
|---|---|---|
| committer | KunoiSayami <[email protected]> | 2022-06-30 02:20:09 +0800 |
| commit | 0b2735596e8969c08797f18977c626f423b3ab6d (patch) | |
| tree | 71e79ae308ec6b0e4f29597e715e48f1d7c17f04 /main.cu | |
| parent | e686acb51a836cca58f2043c404ac8d42d12fe5f (diff) | |
refactor(script): Optimize cdf calculator
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'main.cu')
| -rw-r--r-- | main.cu | 33 |
1 files changed, 30 insertions, 3 deletions
@@ -69,6 +69,7 @@ Conference on Parallel and Distributed Systems, December 2012. #include <cstdio> #include <cstdlib> #include <random> +#include <set> #if __WORDSIZE == 64 typedef unsigned long long LL; @@ -601,9 +602,6 @@ LL RandomLevel(std::mt19937 &randomEngine, double p) { } std::vector<LL> storage; -#ifdef MEASURE_TIME -std::vector<int> SpendTimeVec; -#endif unsigned trailing_zeroes(size_t index) { unsigned bits = 0; @@ -648,6 +646,35 @@ __global__ void copy_function(int *spend_time) { memcpy(spend_time, l->spend_time, sizeof(int) * NUM_ITEMS); } +std::vector<double> population; +std::vector<double> sample; + +void initialize(const std::vector<double> &input_population, + const std::vector<double> &input_sample) { + population = input_population; + std::sort(population.begin(), population.end()); + sample = input_sample; + std::sort(sample.begin(), sample.end()); +} + +double sample_cdf(double x) { + auto it = lower_bound(sample.begin(), sample.end(), x); + if (it == sample.end()) { + return 1; + } + if (it == sample.begin()) { + return 0; + } + auto it_prev = it - 1; + return (double(it_prev - sample.begin()) + + double(x - *it_prev) / (*it - *it_prev)) / + double(sample.size() - 1); +} + +int infer_offset(double x) { + return int(sample_cdf(x) * double(population.size())); +} + int main(int argc, char **argv) { if (argc != 3) { printf("Need two arguments: percent add ops and percent delete ops (e.g., " |
