unum-cloud / usearch

Fast Open-Source Search & Clustering engine × for Vectors & 🔜 Strings × in C++, C, Python, JavaScript, Rust, Java, Objective-C, Swift, C#, GoLang, and Wolfram 🔍
https://unum-cloud.github.io/usearch/
Apache License 2.0
2.28k stars 143 forks source link

Bug: what(): No available threads to lock. Aborted (core dumped) #488

Closed ucasfl closed 2 months ago

ucasfl commented 2 months ago

Describe the bug

When run a simple case of save and load index to make a search, the following error occured:

terminate called after throwing an instance of 'std::runtime_error'
  what():  No available threads to lock
Aborted (core dumped)

The code is below:

#include <usearch/index.hpp>
#include <usearch/index_dense.hpp>

#include <iostream>

using namespace unum::usearch;

int main(int argc, char ** argv)
{
    metric_punned_t metric(3, metric_kind_t::l2sq_k, scalar_kind_t::f32_k);

    // If you plan to store more than 4 Billion entries - use `index_dense_big_t`.
    // Or directly instantiate the template variant you need - `index_dense_gt<vector_key_t, internal_id_t>`.
    index_dense_t index = index_dense_t::make(metric);
    float vec[3] = {0.1, 0.3, 0.2};

    index.reserve(10); // Pre-allocate memory for 10 vectors
    index.add(42, &vec[0]); // Pass a key and a vector
    float vec_double[3] = {0.1, 0.3, 0.2};

    index.add(43, &vec_double[0]);

    index.save("index.usearch");

    auto result = index_dense_t::make(metric);
    if (!result)
        std::cout << "make error: " << (result.error.what()) << std::endl;

    auto & index1 = result.index;
    auto result = index1.load("./index.usearch"); // Memory-mapping from disk
    if (!result)
        std::cout << "load error: " << (result.error.what()) << std::endl;

    auto results = index1.search(&vec[0], 5); // Pass a query and limit number of results

    for (std::size_t i = 0; i != results.size(); ++i)
                // You can access the following properties of every match:
                // results[i].element.key, results[i].element.vector, results[i].distance;
                std::printf("Found matching key: %zu\n", results[i].member.key);
    return 0;
}

Steps to reproduce

Just run the code above.

Expected behavior

works well.

USearch version

master

Operating System

Ubuntu 20.04

Hardware architecture

x86

Which interface are you using?

C++ implementation

Contact Details

No response

Are you open to being tagged as a contributor?

Is there an existing issue for this?

Code of Conduct

ucasfl commented 2 months ago

@ashvardanian Hi, could you please take a look at this? Thanks.

ashvardanian commented 2 months ago

Oh, that's easy. Please reserve the number of threads after you reload 🤗 I will think of a better workflow for v3, but it's not coming this month.

ucasfl commented 2 months ago

Oh, that's easy. Please reserve the number of threads after you reload 🤗 I will think of a better workflow for v3, but it's not coming this month.

@ashvardanian I don't understand what the mean of reserve the number of threads, because the reserve method says Increases the capacity() of the index to allow adding more vectors .

ashvardanian commented 2 months ago

https://github.com/unum-cloud/usearch/blob/b9a9758a06e1d9365c54118868bf27ac042d4ffc/include/usearch/index_dense.hpp#L911