-
Notifications
You must be signed in to change notification settings - Fork 8
executor api
Teo Lemane edited this page Jul 29, 2021
·
1 revision
kmtricks provides an implementation selector for functor. It allows to select the best implementation according to k-mer size at runtime.
#define KMER_LIST 32, 64, 96, 128
#define KMER_N 4 // size of KMER_LIST
#include <kmtricks/public.hpp>
using namespace km;
template<size_t KSIZE>
struct MyFunctor
{
void operator()(int an_int, float a_float, const std::string& a_string)
{
std::cout << "Use " << Kmer<KSIZE>::name() << std::endl;
}
};
int main(int argc, char* argv[])
{
uint32_t kmer_size = 20;
// first param is the k-mer size for the executor, others are MyFunctor::operator() parameters
const_loop_executor<0, KMER_N>::exec<MyFunctor>(kmer_size, 0, 0.0, ""); // print "Use Kmer<32> - uint64_t"
kmer_size = 40;
const_loop_executor<0, KMER_N>::exec<MyFunctor>(kmer_size, 0, 0.0, ""); // print "Use Kmer<64> - __uint128_t" if available, else "Use Kmer<64> - uint64_t[2]"
kmer_size = 80;
const_loop_executor<0, KMER_N>::exec<MyFunctor>(kmer_size, 0, 0.0, ""); // print "Use Kmer<96> - uint64_t[3]"
kmer_size = 150;
const_loop_executor<0, KMER_N>::exec<MyFunctor>(kmer_size, 0, 0.0, ""); // throw, needs to increase KMER_LIST
return 0;
}