Benchmark works.

This commit is contained in:
Davi de Castro Reis 2011-02-15 20:46:05 -08:00
parent d0eb54d030
commit 4fc0c52c56
6 changed files with 58 additions and 27 deletions

View File

@ -9,7 +9,7 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#define DEBUG // #define DEBUG
#include "debug.h" #include "debug.h"
#define UNASSIGNED 3U #define UNASSIGNED 3U
#define NULL_EDGE 0xffffffff #define NULL_EDGE 0xffffffff
@ -115,10 +115,12 @@ static void bdz_dump_graph(bdz_graph3_t* graph3, cmph_uint32 nedges, cmph_uint32
graph3->edges[i].next_edges[1],graph3->edges[i].next_edges[2]); graph3->edges[i].next_edges[1],graph3->edges[i].next_edges[2]);
}; };
#ifdef DEBUG
for(i=0;i<nvertices;i++){ for(i=0;i<nvertices;i++){
printf("\nfirst for vertice %d %d ",i,graph3->first_edge[i]); printf("\nfirst for vertice %d %d ",i,graph3->first_edge[i]);
}; };
#endif
}; };
static void bdz_remove_edge(bdz_graph3_t * graph3, cmph_uint32 curr_edge) static void bdz_remove_edge(bdz_graph3_t * graph3, cmph_uint32 curr_edge)
@ -408,7 +410,7 @@ static int bdz_mapping(cmph_config_t *mph, bdz_graph3_t* graph3, bdz_queue_t que
h0 = hl[0] % bdz->r; h0 = hl[0] % bdz->r;
h1 = hl[1] % bdz->r + bdz->r; h1 = hl[1] % bdz->r + bdz->r;
h2 = hl[2] % bdz->r + (bdz->r << 1); h2 = hl[2] % bdz->r + (bdz->r << 1);
DEBUGP("Key: %s (%u %u %u)\n", key, h0, h1, h2); DEBUGP("Key: %.*s (%u %u %u)\n", keylen, key, h0, h1, h2);
mph->key_source->dispose(mph->key_source->data, key, keylen); mph->key_source->dispose(mph->key_source->data, key, keylen);
bdz_add_edge(graph3,h0,h1,h2); bdz_add_edge(graph3,h0,h1,h2);
} }

View File

@ -18,14 +18,26 @@ cmph_uint32* random_numbers_vector_new(cmph_uint32 size) {
while (GETBIT(dup, v % dup_bits)) { v = random(); } while (GETBIT(dup, v % dup_bits)) { v = random(); }
SETBIT(dup, v % dup_bits); SETBIT(dup, v % dup_bits);
vec[i] = v; vec[i] = v;
fprintf(stderr, "v[%u] = %u\n", i, vec[i]);
} }
free(dup); free(dup);
return vec; return vec;
} }
int cmph_uint32_cmp(const void *a, const void *b) {
return *(const cmph_uint32*)a - *(const cmph_uint32*)b;
}
char* create_lsmap_key(CMPH_ALGO algo, int iters) {
char mphf_name[128];
snprintf(mphf_name, 128, "%s:%u", cmph_names[algo], iters);
return strdup(mphf_name);
}
static cmph_uint32 g_numbers_len = 0; static cmph_uint32 g_numbers_len = 0;
static cmph_uint32 *g_numbers = NULL; static cmph_uint32 *g_numbers = NULL;
static lsmap_t *g_created_mphf = NULL; static lsmap_t *g_created_mphf = NULL;
static lsmap_t *g_expected_probes = NULL;
static lsmap_t *g_mphf_probes = NULL;
void bm_create(CMPH_ALGO algo, int iters) { void bm_create(CMPH_ALGO algo, int iters) {
cmph_uint32 i = 0; cmph_uint32 i = 0;
@ -51,11 +63,7 @@ void bm_create(CMPH_ALGO algo, int iters) {
} }
cmph_config_destroy(config); cmph_config_destroy(config);
cmph_io_struct_vector_adapter_destroy(source); cmph_io_struct_vector_adapter_destroy(source);
lsmap_append(g_created_mphf, create_lsmap_key(algo, iters), mphf);
char mphf_name[128];
snprintf(mphf_name, 128, "%s:%u", cmph_names[algo], iters);
lsmap_append(g_created_mphf, strdup(mphf_name), mphf);
} }
void bm_search(CMPH_ALGO algo, int iters) { void bm_search(CMPH_ALGO algo, int iters) {
@ -63,35 +71,52 @@ void bm_search(CMPH_ALGO algo, int iters) {
char mphf_name[128]; char mphf_name[128];
cmph_t* mphf = NULL; cmph_t* mphf = NULL;
snprintf(mphf_name, 128, "%s:%u", cmph_names[algo], iters); snprintf(mphf_name, 128, "%s:%u", cmph_names[algo], iters);
mphf = lsmap_search(g_created_mphf, mphf_name); mphf = lsmap_search(g_created_mphf, mphf_name);
cmph_uint32* count = (cmph_uint32*)malloc(sizeof(cmph_uint32)*iters);
cmph_uint32* hash_count = (cmph_uint32*)malloc(sizeof(cmph_uint32)*iters);
for (i = 0; i < iters * 100; ++i) { for (i = 0; i < iters * 100; ++i) {
cmph_uint32 pos = random() % iters; cmph_uint32 pos = random() % iters;
fprintf(stderr, "Looking for key %u at pos %u\n", g_numbers[pos], pos);
const char* buf = (const char*)(g_numbers + pos); const char* buf = (const char*)(g_numbers + pos);
cmph_uint32 h = cmph_search(mphf, buf, sizeof(cmph_uint32)); cmph_uint32 h = cmph_search(mphf, buf, sizeof(cmph_uint32));
fprintf(stderr, "Found h %u value %u\n", h, g_numbers[h]); ++count[pos];
if (h != pos) { ++hash_count[h];
fprintf(stderr, "Buggy mphf\n");
}
} }
// Verify correctness later.
lsmap_append(g_expected_probes, create_lsmap_key(algo, iters), count);
lsmap_append(g_mphf_probes, create_lsmap_key(algo, iters), hash_count);
} }
void verify() { }
#define DECLARE_ALGO(algo) \ #define DECLARE_ALGO(algo) \
void bm_create_ ## algo(int iters) { bm_create(algo, iters); } \ void bm_create_ ## algo(int iters) { bm_create(algo, iters); } \
void bm_search_ ## algo(int iters) { bm_search(algo, iters); } void bm_search_ ## algo(int iters) { bm_search(algo, iters); }
DECLARE_ALGO(CMPH_CHM);
DECLARE_ALGO(CMPH_BMZ);
DECLARE_ALGO(CMPH_BDZ); DECLARE_ALGO(CMPH_BDZ);
int main(int argc, char** argv) { int main(int argc, char** argv) {
g_numbers_len = 20; g_numbers_len = 1000 * 1000;
g_numbers = random_numbers_vector_new(g_numbers_len); g_numbers = random_numbers_vector_new(g_numbers_len);
g_created_mphf = lsmap_new(); g_created_mphf = lsmap_new();
g_expected_probes = lsmap_new();
g_mphf_probes = lsmap_new();
BM_REGISTER(bm_create_CMPH_BDZ, 20); BM_REGISTER(bm_create_CMPH_CHM, 1000 * 1000);
BM_REGISTER(bm_search_CMPH_BDZ, 20); BM_REGISTER(bm_search_CMPH_CHM, 1000 * 1000);
BM_REGISTER(bm_create_CMPH_BMZ, 1000 * 1000);
BM_REGISTER(bm_search_CMPH_BMZ, 1000 * 1000);
BM_REGISTER(bm_create_CMPH_BDZ, 1000 * 1000);
BM_REGISTER(bm_search_CMPH_BDZ, 1000 * 1000);
run_benchmarks(argc, argv); run_benchmarks(argc, argv);
verify();
free(g_numbers); free(g_numbers);
lsmap_foreach_key(g_created_mphf, free); lsmap_foreach_key(g_created_mphf, free);
lsmap_foreach_value(g_created_mphf, cmph_destroy); lsmap_foreach_value(g_created_mphf, cmph_destroy);

View File

@ -169,6 +169,12 @@ cmph_t *bmz_new(cmph_config_t *mph, double c)
{ {
return NULL; return NULL;
} }
#ifdef DEBUG
fprintf(stderr, "G: ");
for (i = 0; i < bmz->n; ++i) fprintf(stderr, "%u ", bmz->g[i]);
fprintf(stderr, "\n");
#endif
mphf = (cmph_t *)malloc(sizeof(cmph_t)); mphf = (cmph_t *)malloc(sizeof(cmph_t));
mphf->algo = mph->algo; mphf->algo = mph->algo;
bmzf = (bmz_data_t *)malloc(sizeof(bmz_data_t)); bmzf = (bmz_data_t *)malloc(sizeof(bmz_data_t));
@ -421,19 +427,18 @@ static int bmz_gen_edges(cmph_config_t *mph)
char *key = NULL; char *key = NULL;
mph->key_source->read(mph->key_source->data, &key, &keylen); mph->key_source->read(mph->key_source->data, &key, &keylen);
// if (key == NULL)fprintf(stderr, "key = %s -- read BMZ\n", key);
h1 = hash(bmz->hashes[0], key, keylen) % bmz->n; h1 = hash(bmz->hashes[0], key, keylen) % bmz->n;
h2 = hash(bmz->hashes[1], key, keylen) % bmz->n; h2 = hash(bmz->hashes[1], key, keylen) % bmz->n;
if (h1 == h2) if (++h2 >= bmz->n) h2 = 0; if (h1 == h2) if (++h2 >= bmz->n) h2 = 0;
DEBUGP("key: %.*s h1: %u h2: %u\n", keylen, key, h1, h2);
if (h1 == h2) if (h1 == h2)
{ {
if (mph->verbosity) fprintf(stderr, "Self loop for key %u\n", e); if (mph->verbosity) fprintf(stderr, "Self loop for key %u\n", e);
mph->key_source->dispose(mph->key_source->data, key, keylen); mph->key_source->dispose(mph->key_source->data, key, keylen);
return 0; return 0;
} }
//DEBUGP("Adding edge: %u -> %u for key %s\n", h1, h2, key); DEBUGP("Adding edge: %u -> %u for key %.*s\n", h1, h2, keylen, key);
mph->key_source->dispose(mph->key_source->data, key, keylen); mph->key_source->dispose(mph->key_source->data, key, keylen);
// fprintf(stderr, "key = %s -- dispose BMZ\n", key);
multiple_edges = graph_contains_edge(bmz->graph, h1, h2); multiple_edges = graph_contains_edge(bmz->graph, h1, h2);
if (mph->verbosity && multiple_edges) fprintf(stderr, "A non simple graph was generated\n"); if (mph->verbosity && multiple_edges) fprintf(stderr, "A non simple graph was generated\n");
if (multiple_edges) return 0; // checking multiple edge restriction. if (multiple_edges) return 0; // checking multiple edge restriction.
@ -524,9 +529,9 @@ cmph_uint32 bmz_search(cmph_t *mphf, const char *key, cmph_uint32 keylen)
bmz_data_t *bmz = mphf->data; bmz_data_t *bmz = mphf->data;
cmph_uint32 h1 = hash(bmz->hashes[0], key, keylen) % bmz->n; cmph_uint32 h1 = hash(bmz->hashes[0], key, keylen) % bmz->n;
cmph_uint32 h2 = hash(bmz->hashes[1], key, keylen) % bmz->n; cmph_uint32 h2 = hash(bmz->hashes[1], key, keylen) % bmz->n;
DEBUGP("key: %s h1: %u h2: %u\n", key, h1, h2); DEBUGP("key: %.*s h1: %u h2: %u\n", keylen, key, h1, h2);
if (h1 == h2 && ++h2 > bmz->n) h2 = 0; if (h1 == h2 && ++h2 > bmz->n) h2 = 0;
DEBUGP("key: %s g[h1]: %u g[h2]: %u edges: %u\n", key, bmz->g[h1], bmz->g[h2], bmz->m); DEBUGP("key: %.*s g[h1]: %u g[h2]: %u edges: %u\n", keylen, key, bmz->g[h1], bmz->g[h2], bmz->m);
return bmz->g[h1] + bmz->g[h2]; return bmz->g[h1] + bmz->g[h2];
} }
void bmz_destroy(cmph_t *mphf) void bmz_destroy(cmph_t *mphf)

View File

@ -112,7 +112,6 @@ void bm_end(const char* name) {
printf("Benchmark: %s\n", benchmark->name); printf("Benchmark: %s\n", benchmark->name);
printf("User time used : %ld.%06ld\n", utime.tv_sec, utime.tv_usec); printf("User time used : %ld.%06ld\n", utime.tv_sec, utime.tv_usec);
printf("System time used: %ld.%06ld\n", stime.tv_sec, stime.tv_usec); printf("System time used: %ld.%06ld\n", stime.tv_sec, stime.tv_usec);
printf("Wall time used : %ld.%06ld\n", stime.tv_sec, stime.tv_usec);
printf("\n"); printf("\n");
} }

View File

@ -176,7 +176,7 @@ static cmph_uint8 find_degree1_edge(graph_t *g, cmph_uint32 v, cmph_uint8 *delet
{ {
cmph_uint32 edge = g->first[v]; cmph_uint32 edge = g->first[v];
cmph_uint8 found = 0; cmph_uint8 found = 0;
DEBUGP("Checking degree of vertex %u\n", v); DEBUGP("Checking degree of vertex %u connected to edge %u\n", v, edge);
if (edge == EMPTY) return 0; if (edge == EMPTY) return 0;
else if (!(GETBIT(deleted, abs_edge(edge, 0)))) else if (!(GETBIT(deleted, abs_edge(edge, 0))))
{ {