diff --git a/src/bdz.c b/src/bdz.c index e129c51..6b3f80e 100755 --- a/src/bdz.c +++ b/src/bdz.c @@ -9,7 +9,7 @@ #include #include #include -#define DEBUG +// #define DEBUG #include "debug.h" #define UNASSIGNED 3U #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]); }; + #ifdef DEBUG for(i=0;ifirst_edge[i]); }; + #endif }; 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; h1 = hl[1] % bdz->r + bdz->r; 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); bdz_add_edge(graph3,h0,h1,h2); } diff --git a/src/bm_numbers.c b/src/bm_numbers.c index 4d464c0..2e86de4 100644 --- a/src/bm_numbers.c +++ b/src/bm_numbers.c @@ -18,14 +18,26 @@ cmph_uint32* random_numbers_vector_new(cmph_uint32 size) { while (GETBIT(dup, v % dup_bits)) { v = random(); } SETBIT(dup, v % dup_bits); vec[i] = v; - fprintf(stderr, "v[%u] = %u\n", i, vec[i]); } free(dup); 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 = 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) { cmph_uint32 i = 0; @@ -51,11 +63,7 @@ void bm_create(CMPH_ALGO algo, int iters) { } cmph_config_destroy(config); cmph_io_struct_vector_adapter_destroy(source); - - - char mphf_name[128]; - snprintf(mphf_name, 128, "%s:%u", cmph_names[algo], iters); - lsmap_append(g_created_mphf, strdup(mphf_name), mphf); + lsmap_append(g_created_mphf, create_lsmap_key(algo, iters), mphf); } void bm_search(CMPH_ALGO algo, int iters) { @@ -63,35 +71,52 @@ void bm_search(CMPH_ALGO algo, int iters) { char mphf_name[128]; cmph_t* mphf = NULL; + snprintf(mphf_name, 128, "%s:%u", cmph_names[algo], iters); 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) { 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); cmph_uint32 h = cmph_search(mphf, buf, sizeof(cmph_uint32)); - fprintf(stderr, "Found h %u value %u\n", h, g_numbers[h]); - if (h != pos) { - fprintf(stderr, "Buggy mphf\n"); - } + ++count[pos]; + ++hash_count[h]; } + + // 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) \ void bm_create_ ## algo(int iters) { bm_create(algo, iters); } \ void bm_search_ ## algo(int iters) { bm_search(algo, iters); } +DECLARE_ALGO(CMPH_CHM); +DECLARE_ALGO(CMPH_BMZ); DECLARE_ALGO(CMPH_BDZ); 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_created_mphf = lsmap_new(); + g_expected_probes = lsmap_new(); + g_mphf_probes = lsmap_new(); - BM_REGISTER(bm_create_CMPH_BDZ, 20); - BM_REGISTER(bm_search_CMPH_BDZ, 20); + BM_REGISTER(bm_create_CMPH_CHM, 1000 * 1000); + 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); + verify(); free(g_numbers); lsmap_foreach_key(g_created_mphf, free); lsmap_foreach_value(g_created_mphf, cmph_destroy); diff --git a/src/bmz.c b/src/bmz.c index 51798a1..002f8dc 100644 --- a/src/bmz.c +++ b/src/bmz.c @@ -12,7 +12,7 @@ #include #include -//#define DEBUG +// #define DEBUG #include "debug.h" static int bmz_gen_edges(cmph_config_t *mph); @@ -162,13 +162,19 @@ cmph_t *bmz_new(cmph_config_t *mph, double c) } free(used_edges); free(visited); - }while(restart_mapping && iterations_map > 0); + } while(restart_mapping && iterations_map > 0); graph_destroy(bmz->graph); bmz->graph = NULL; if (iterations_map == 0) { 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->algo = mph->algo; 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; 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; h2 = hash(bmz->hashes[1], key, keylen) % bmz->n; 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 (mph->verbosity) fprintf(stderr, "Self loop for key %u\n", e); mph->key_source->dispose(mph->key_source->data, key, keylen); 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); -// fprintf(stderr, "key = %s -- dispose BMZ\n", key); multiple_edges = graph_contains_edge(bmz->graph, h1, h2); if (mph->verbosity && multiple_edges) fprintf(stderr, "A non simple graph was generated\n"); 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; cmph_uint32 h1 = hash(bmz->hashes[0], 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; - 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]; } void bmz_destroy(cmph_t *mphf) diff --git a/src/cmph.c b/src/cmph.c index cba735f..b0c33bf 100644 --- a/src/cmph.c +++ b/src/cmph.c @@ -13,7 +13,7 @@ #include #include #include -//#define DEBUG +// #define DEBUG #include "debug.h" const char *cmph_names[] = {"bmz", "bmz8", "chm", "brz", "fch", "bdz", "bdz_ph", "chd_ph", "chd", NULL }; diff --git a/src/cmph_benchmark.c b/src/cmph_benchmark.c index 073f937..f7177a3 100644 --- a/src/cmph_benchmark.c +++ b/src/cmph_benchmark.c @@ -112,7 +112,6 @@ void bm_end(const char* name) { printf("Benchmark: %s\n", benchmark->name); 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("Wall time used : %ld.%06ld\n", stime.tv_sec, stime.tv_usec); printf("\n"); } diff --git a/src/graph.c b/src/graph.c index c29fd8b..2e9ddb7 100644 --- a/src/graph.c +++ b/src/graph.c @@ -8,7 +8,7 @@ #include "vstack.h" #include "bitbool.h" -//#define DEBUG +// #define DEBUG #include "debug.h" /* static const cmph_uint8 bitmask[8] = { 1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7 }; */ @@ -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_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; else if (!(GETBIT(deleted, abs_edge(edge, 0)))) {