projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'evelu-peak' of https://github.com/ErwanAliasr1/fio
[fio.git]
/
lib
/
zipf.c
diff --git
a/lib/zipf.c
b/lib/zipf.c
index 41e20554b3d019885ed76c9fbe9b66183c4100cf..14d7928f664a0dfadf8d005e5c87414407cc91fa 100644
(file)
--- a/
lib/zipf.c
+++ b/
lib/zipf.c
@@
-1,21
+1,14
@@
#include <math.h>
#include <string.h>
#include <math.h>
#include <string.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include "ieee754.h"
-#include "../log.h"
#include "zipf.h"
#include "../minmax.h"
#include "../hash.h"
#include "zipf.h"
#include "../minmax.h"
#include "../hash.h"
-#define ZIPF_MAX_GEN 10000000
+#define ZIPF_MAX_GEN 10000000
UL
static void zipf_update(struct zipf_state *zs)
{
static void zipf_update(struct zipf_state *zs)
{
- u
nsigned long
to_gen;
+ u
int64_t
to_gen;
unsigned int i;
/*
unsigned int i;
/*
@@
-23,26
+16,28
@@
static void zipf_update(struct zipf_state *zs)
* 10M max, that should be doable in 1-2s on even slow machines.
* Precision will take a slight hit, but nothing major.
*/
* 10M max, that should be doable in 1-2s on even slow machines.
* Precision will take a slight hit, but nothing major.
*/
- to_gen = min(zs->nranges, ZIPF_MAX_GEN);
+ to_gen = min(zs->nranges,
(uint64_t)
ZIPF_MAX_GEN);
for (i = 0; i < to_gen; i++)
zs->zetan += pow(1.0 / (double) (i + 1), zs->theta);
}
for (i = 0; i < to_gen; i++)
zs->zetan += pow(1.0 / (double) (i + 1), zs->theta);
}
-static void shared_rand_init(struct zipf_state *zs, u
nsigned long
nranges,
- unsigned int seed)
+static void shared_rand_init(struct zipf_state *zs, u
int64_t
nranges,
+
double center,
unsigned int seed)
{
memset(zs, 0, sizeof(*zs));
zs->nranges = nranges;
{
memset(zs, 0, sizeof(*zs));
zs->nranges = nranges;
- init_rand_seed(&zs->rand, seed);
+ init_rand_seed(&zs->rand, seed
, 0
);
zs->rand_off = __rand(&zs->rand);
zs->rand_off = __rand(&zs->rand);
+ if (center != -1)
+ zs->rand_off = nranges * center;
}
}
-void zipf_init(struct zipf_state *zs, u
nsigned long
nranges, double theta,
- unsigned int seed)
+void zipf_init(struct zipf_state *zs, u
int64_t
nranges, double theta,
+
double center,
unsigned int seed)
{
{
- shared_rand_init(zs, nranges, seed);
+ shared_rand_init(zs, nranges,
center,
seed);
zs->theta = theta;
zs->zeta2 = pow(1.0, zs->theta) + pow(0.5, zs->theta);
zs->theta = theta;
zs->zeta2 = pow(1.0, zs->theta) + pow(0.5, zs->theta);
@@
-50,7
+45,7
@@
void zipf_init(struct zipf_state *zs, unsigned long nranges, double theta,
zipf_update(zs);
}
zipf_update(zs);
}
-u
nsigned long long
zipf_next(struct zipf_state *zs)
+u
int64_t
zipf_next(struct zipf_state *zs)
{
double alpha, eta, rand_uni, rand_z;
unsigned long long n = zs->nranges;
{
double alpha, eta, rand_uni, rand_z;
unsigned long long n = zs->nranges;
@@
-59,7
+54,7
@@
unsigned long long zipf_next(struct zipf_state *zs)
alpha = 1.0 / (1.0 - zs->theta);
eta = (1.0 - pow(2.0 / n, 1.0 - zs->theta)) / (1.0 - zs->zeta2 / zs->zetan);
alpha = 1.0 / (1.0 - zs->theta);
eta = (1.0 - pow(2.0 / n, 1.0 - zs->theta)) / (1.0 - zs->zeta2 / zs->zetan);
- rand_uni = (double) __rand(&zs->rand) / (double) FRAND_MAX;
+ rand_uni = (double) __rand(&zs->rand) / (double) FRAND
32
_MAX;
rand_z = rand_uni * zs->zetan;
if (rand_z < 1.0)
rand_z = rand_uni * zs->zetan;
if (rand_z < 1.0)
@@
-69,20
+64,35
@@
unsigned long long zipf_next(struct zipf_state *zs)
else
val = 1 + (unsigned long long)(n * pow(eta*rand_uni - eta + 1.0, alpha));
else
val = 1 + (unsigned long long)(n * pow(eta*rand_uni - eta + 1.0, alpha));
- return (__hash_long(val - 1) + zs->rand_off) % zs->nranges;
+ val--;
+
+ if (!zs->disable_hash)
+ val = __hash_u64(val);
+
+ return (val + zs->rand_off) % zs->nranges;
}
}
-void pareto_init(struct zipf_state *zs, u
nsigned long
nranges, double h,
- unsigned int seed)
+void pareto_init(struct zipf_state *zs, u
int64_t
nranges, double h,
+
double center,
unsigned int seed)
{
{
- shared_rand_init(zs, nranges, seed);
+ shared_rand_init(zs, nranges,
center,
seed);
zs->pareto_pow = log(h) / log(1.0 - h);
}
zs->pareto_pow = log(h) / log(1.0 - h);
}
-u
nsigned long long
pareto_next(struct zipf_state *zs)
+u
int64_t
pareto_next(struct zipf_state *zs)
{
{
- double rand = (double) __rand(&zs->rand) / (double) FRAND_MAX;
- unsigned long long n = zs->nranges - 1;
+ double rand = (double) __rand(&zs->rand) / (double) FRAND32_MAX;
+ unsigned long long n;
+
+ n = (zs->nranges - 1) * pow(rand, zs->pareto_pow);
+
+ if (!zs->disable_hash)
+ n = __hash_u64(n);
- return (__hash_long(n * pow(rand, zs->pareto_pow)) + zs->rand_off) % zs->nranges;
+ return (n + zs->rand_off) % zs->nranges;
+}
+
+void zipf_disable_hash(struct zipf_state *zs)
+{
+ zs->disable_hash = true;
}
}