Skip to content

Commit

Permalink
Switch between compressed and uncompressed IBF
Browse files Browse the repository at this point in the history
  • Loading branch information
eaasna committed Sep 4, 2023
1 parent 1844930 commit 8260a3c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 24 deletions.
17 changes: 13 additions & 4 deletions include/valik/search/search_distributed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@ namespace valik::app
/**
* @brief Function that calls Valik prefiltering and launches parallel processes of Stellar search.
*
* @tparam index_t Type of IBF.
* @tparam compressed IBF layout type.
* @param arguments Command line arguments.
* @param time_statistics Run-time statistics.
* @param index Interleaved Bloom Filter.
* @return false if search failed.
*/
template <typename index_t>
bool search_distributed(search_arguments const & arguments, search_time_statistics & time_statistics, index_t const & index)
template <bool compressed>
bool search_distributed(search_arguments const & arguments, search_time_statistics & time_statistics)
{
using index_structure_t = std::conditional_t<compressed, index_structure::ibf_compressed, index_structure::ibf>;
auto index = valik_index<index_structure_t>{};

{
auto start = std::chrono::high_resolution_clock::now();
load_index(index, arguments.index_file);
auto end = std::chrono::high_resolution_clock::now();
time_statistics.index_io_time += std::chrono::duration_cast<std::chrono::duration<double>>(end - start).count();
}

std::optional<database_metadata> ref_meta;
if (!arguments.ref_meta_path.empty())
ref_meta = database_metadata(arguments.ref_meta_path, false);
Expand Down
18 changes: 14 additions & 4 deletions include/valik/search/search_local.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,25 @@ namespace valik::app
/**
* @brief Function that calls Valik prefiltering and launches parallel threads of Stellar search.
*
* @tparam index_t Type of IBF.
* @tparam compressed IBF layout type.
* @tparam is_split Split query sequences.
* @param arguments Command line arguments.
* @param time_statistics Run-time statistics.
* @param index Interleaved Bloom Filter.
* @return false if search failed.
*/
template <bool is_split, typename index_t>
bool search_local(search_arguments const & arguments, search_time_statistics & time_statistics, index_t const & index)
template <bool compressed, bool is_split>
bool search_local(search_arguments const & arguments, search_time_statistics & time_statistics)
{
using index_structure_t = std::conditional_t<compressed, index_structure::ibf_compressed, index_structure::ibf>;
auto index = valik_index<index_structure_t>{};

{
auto start = std::chrono::high_resolution_clock::now();
load_index(index, arguments.index_file);
auto end = std::chrono::high_resolution_clock::now();
time_statistics.index_io_time += std::chrono::duration_cast<std::chrono::duration<double>>(end - start).count();
}

std::optional<database_metadata> ref_meta;
if (!arguments.ref_meta_path.empty())
ref_meta = database_metadata(arguments.ref_meta_path, false);
Expand Down
40 changes: 24 additions & 16 deletions src/valik_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,42 @@ namespace valik::app
/**
* @brief Function that loads the index and launches local or distributed search.
*
* @tparam compressed Interleaved Bloom Filter layout type.
* @param arguments Command line arguments.
*/
void valik_search(search_arguments const & arguments)
{
search_time_statistics time_statistics{};

//!TODO: this switch doesn't work, make is_compressed template parameter
using index_structure_t = index_structure::ibf;
if (arguments.compressed)
using index_structure_t = index_structure::ibf_compressed;
auto index = valik_index<index_structure_t>{};
search_time_statistics time_statistics{};

bool failed;
if (arguments.distribute)
{
auto start = std::chrono::high_resolution_clock::now();
load_index(index, arguments.index_file);
auto end = std::chrono::high_resolution_clock::now();
time_statistics.index_io_time += std::chrono::duration_cast<std::chrono::duration<double>>(end - start).count();
if (arguments.compressed)
failed = search_distributed<true>(arguments, time_statistics);
else
failed = search_distributed<false>(arguments, time_statistics);
}

bool failed;
if (arguments.distribute)
failed = search_distributed(arguments, time_statistics, index);
// Shared memory execution
else
{
if (arguments.query_seg_path.empty())
failed = search_local<false>(arguments, time_statistics, index);
if (arguments.compressed)
{
if (arguments.query_seg_path.empty())
failed = search_local<true, false>(arguments, time_statistics);
// Split long query sequences
else
failed = search_local<true, true>(arguments, time_statistics);
}
else
failed = search_local<true>(arguments, time_statistics, index);
{
if (arguments.query_seg_path.empty())
failed = search_local<false, false>(arguments, time_statistics);
// Split long query sequences
else
failed = search_local<false, true>(arguments, time_statistics);
}
}

if (arguments.write_time)
Expand Down

0 comments on commit 8260a3c

Please sign in to comment.