Giter VIP home page Giter VIP logo

Comments (10)

SheldonZhong avatar SheldonZhong commented on May 28, 2024

Code to reproduce:

#include <iostream>
#include <fstream>
#include <chrono>
#include <random>
#include <string>
#include "tbb/tbb.h"

using namespace std;

#include "masstree.h"

void run(char **argv) {
    std::cout << "Simple Example of P-Masstree" << std::endl;

    uint64_t n = std::atoll(argv[1]);
    char **keys = new char*[n]();

    ifstream keyf(argv[3]);
    if (!keyf.is_open()) {
        cout << "unable to open file" << endl;
        keyf.close();
        exit(1);
    }

    string line;
    int i;
    for (i = 0; getline(keyf, line) && (i < n); i++) {
        keys[i] = new char[line.length() + 1]();
        strcpy(keys[i], line.c_str());
    }
    n = i;
    keyf.close();

    for (int j = 0; j < i; j++) {
      char **p = &keys[j];
      printf("%s\n", *p);
    }

    int num_thread = atoi(argv[2]);
    tbb::task_scheduler_init init(num_thread);

    printf("operation,n,ops/s\n");
    masstree::leafnode *init_root = new masstree::leafnode(0);
    masstree::masstree *tree = new masstree::masstree(init_root);

    {
        // Build tree
        auto starttime = std::chrono::system_clock::now();
        tbb::parallel_for(tbb::blocked_range<uint64_t>(0, n), [&](const tbb::blocked_range<uint64_t> &range) {
            for (uint64_t i = range.begin(); i != range.end(); i++) {
                tree->put(keys[i], (uint64_t)(keys[i]));
            }
        });
        auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
                std::chrono::system_clock::now() - starttime);
        printf("Throughput: insert,%ld,%f ops/us\n", n, (n * 1.0) / duration.count());
        printf("Elapsed time: insert,%ld,%f sec\n", n, duration.count() / 1000000.0);
    }

    {
        // Lookup
        auto starttime = std::chrono::system_clock::now();
        tbb::parallel_for(tbb::blocked_range<uint64_t>(0, n), [&](const tbb::blocked_range<uint64_t> &range) {
            for (uint64_t i = range.begin(); i != range.end(); i++) {
                char **ret = reinterpret_cast<char **> (tree->get(keys[i]));
                if (!ret) {
                    cout << "empty value read expected:" << keys[i] << endl;
                    throw;
                }
                if (strcmp(*ret, keys[i])) {
                    std::cout << "wrong value read: " << *ret << " expected:" << keys[i] << std::endl;
                }
            }
        });
        auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
                std::chrono::system_clock::now() - starttime);
        printf("Throughput: lookup,%ld,%f ops/us\n", n, (n * 1.0) / duration.count());
        printf("Elapsed time: lookup,%ld,%f sec\n", n, duration.count() / 1000000.0);
    }

    for (int i = 0; i < n; i++)
        free(keys[i]);
}

int main(int argc, char **argv) {
    if (argc != 4) {
        printf("usage: %s [n] [nthreads] [file]\nn: number of keys (integer)\nnthreads: number of threads (integer)\n", argv[0]);
        printf("file: file to read key from\n");
        return 1;
    }

    run(argv);
    return 0;
}

Prepare a text file call test.txt with the content

abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxy

Then in your console

./example.out 2 1 ./test.txt 

would throw an error.

from recipe.

SeKwonLee avatar SeKwonLee commented on May 28, 2024

Thanks for your feedback.
Let me address it soon.

from recipe.

SeKwonLee avatar SeKwonLee commented on May 28, 2024

Hi Sheldon,

I have fixed the bug and pushed the updates to repo. Could you do git pull once? The problem happened due to incorrect pointer tracing while calling clflush by iterating newly allocated nodes when new trie layers are increased over two. For more details about it, please refer to last commit.

Thanks for your feedback again.

from recipe.

SheldonZhong avatar SheldonZhong commented on May 28, 2024

It is also not working correctly with the test case, name it test.txt:

abcdefghijklmno
abcdefghijklmnop
abcdefghijklmnopq
abcdefghijklmnopqr
abcdefghijklmnopqrs
abcdefghijklmnopqrst
abcdefghijklmnopqrstu
abcdefghijklmnopqrstuvw
abcdefghijklmnopqrstuvwx
abcdefghijklmnopqrstuvwxy
abcdefghijklmnopqrstuvwxyz

run it

./example.out 10 1 ./test.txt

from recipe.

SeKwonLee avatar SeKwonLee commented on May 28, 2024

Could you check that again? It works fine.

Simple Example of P-Masstree
abcdefghijklmno
abcdefghijklmnop
abcdefghijklmnopq
abcdefghijklmnopqr
abcdefghijklmnopqrs
abcdefghijklmnopqrst
abcdefghijklmnopqrstu
abcdefghijklmnopqrstuvw
abcdefghijklmnopqrstuvwx
abcdefghijklmnopqrstuvwxy
operation,n,ops/s
Throughput: insert,10,0.051813 ops/us
Elapsed time: insert,10,0.000193 sec
Throughput: lookup,10,0.416667 ops/us
Elapsed time: lookup,10,0.000024 sec

from recipe.

SheldonZhong avatar SheldonZhong commented on May 28, 2024

No, it's not working correctly.

$ ./example.out 10 1 ./test2.txt
Simple Example of P-Masstree
abcdefghijklmno
abcdefghijklmnop
abcdefghijklmnopq
abcdefghijklmnopqr
abcdefghijklmnopqrs
abcdefghijklmnopqrst
abcdefghijklmnopqrstu
abcdefghijklmnopqrstuvw
abcdefghijklmnopqrstuvwx
abcdefghijklmnopqrstuvwxy
operation,n,ops/s
Throughput: insert,10,0.175439 ops/us
Elapsed time: insert,10,0.000057 sec
empty value read expected:abcdefghijklmnopqrstuvwx
terminate called without an active exception
Aborted (core dumped)

from recipe.

SeKwonLee avatar SeKwonLee commented on May 28, 2024

Hm... I could not find the error on my machine.
I used your provided example source code with same keys.
Did that error happen randomly?

from recipe.

SheldonZhong avatar SheldonZhong commented on May 28, 2024

No, it happens every time.
I compile your program using a Makefile

example.out:example.cpp masstree.h
	g++ -Wall -march=native -std=gnu++14 -g -o $@ $< -ltbb

I don't know whether it relates to the compiler.

from recipe.

SeKwonLee avatar SeKwonLee commented on May 28, 2024

I also reproduced the same error you found when using Makefile instead of the provided cmake.

I have fixed the bug made by the code lines parsing strings to integer array. Please do git pull once.

For more details of the updates, please refer to last commit.

Thanks for reporting the error. It's worth reporting improving the maturity of our masstree implementation.

from recipe.

SheldonZhong avatar SheldonZhong commented on May 28, 2024

Seems like all the cases I could cover so far are resolved. Thank you for your effort.

from recipe.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.