Commit ee75773f authored by Damien Leroux's avatar Damien Leroux
Browse files

Fixed implementation of in-progress task registry.

parent 658c30c4
......@@ -403,10 +403,17 @@ __get_registry()
template <typename Ret, typename... Args>
computation_registry<value<Ret>, Ret (*) (Args...), value<typename clean_type<Args>::type>...>&
struct async_computation<Ret(Args...)>;
template <typename Ret, typename... Args>
computation_registry<std::shared_ptr<async_computation<Ret(Args...)>>,
Ret (*) (Args...),
value<typename clean_type<Args>::type>...>&
__get_in_progress_registry()
{
static computation_registry<value<Ret>, Ret (*) (Args...), value<typename clean_type<Args>::type>...> _reg_;
static computation_registry<std::shared_ptr<async_computation<Ret(Args...)>>,
Ret (*) (Args...),
value<typename clean_type<Args>::type>...> _reg_;
/*MSG_DEBUG("Registry at " << (&_reg_));*/
return _reg_;
}
......@@ -416,20 +423,26 @@ template <typename Ret, typename... Args>
std::mutex& __get_in_progress_mutex() { static std::mutex _; return _; }
template <typename Ret, typename... Args>
void unregister_task_in_progress(Ret (*f) (Args...), const clean_value_type<Args>&... x)
void
unregister_task_in_progress(Ret (*f) (Args...),
const value<typename clean_type<Args>::type>&... args)
{
__get_in_progress_mutex<Ret, Args...>().lock();
__get_registry<Ret, Args...>().remove(f, x...);
__get_in_progress_registry<Ret, Args...>().remove(f, args...);
__get_in_progress_mutex<Ret, Args...>().unlock();
}
template <typename Ret, typename... Args>
value<Ret> register_task_in_progress(Ret (&f) (Args...), const clean_value_type<Args>&... x, value<Ret>& v)
std::shared_ptr<async_computation<Ret(Args...)>>
register_task_in_progress(std::shared_ptr<async_computation<Ret(Args...)>> v,
Ret (*f) (Args...),
const value<typename clean_type<Args>::type>&... args)
{
__get_in_progress_mutex<Ret, Args...>().lock();
__get_registry<Ret, Args...>().get(&f, x...) = v;
__get_in_progress_registry<Ret, Args...>().get(f, args...) = v;
__get_in_progress_mutex<Ret, Args...>().unlock();
return v;
}
......@@ -444,9 +457,17 @@ template <typename Ret, typename... Args>
const value<typename clean_type<Args>::type>&... args)
: dependencies(args...)
, m_storage()
, m_future(active_settings->enqueue(_Sync, [=] (Args... args) { chrono_trace _(get_func_name(func)); Ret ret = func(args...); unregister_task_in_progress(func, args...); return ret; }, *args...))
, m_future(active_settings
->enqueue(_Sync,
[=] (Args... args)
{
chrono_trace _(get_func_name(func));
Ret ret = func(args...);
unregister_task_in_progress(func, args...);
return ret;
}, *args...))
, mutex()
{}
{ }
async_computation(CachingPolicy _Sync, std::function<Ret(Args...)>& func,
const value<typename clean_type<Args>::type>&... args)
......@@ -478,6 +499,42 @@ template <typename Ret, typename... Args>
std::mutex mutex;
};
template <typename Ret, typename... Args>
std::shared_ptr<async_computation<Ret(Args...)>>
make_async_computation(CachingPolicy& _Sync,
Ret (*func) (Args...),
const value<typename clean_type<Args>::type>&... args)
{
auto& r = __get_in_progress_registry<Ret, Args...>();
auto exists = r.find(func, args...);
if (exists) {
return *exists;
} else {
std::shared_ptr<async_computation<Ret(Args...)>>
ac(new async_computation<Ret(Args...)>(_Sync, func, args...));
return r.get(func, args...) = register_task_in_progress(ac, func, args...);
}
}
template <typename Ret, typename... Args>
std::shared_ptr<async_computation<Ret(Args...)>>
make_async_computation(CachingPolicy& _Sync,
Ret (*func) (Args...),
std::function<Ret(Args...)>& proxy,
const value<typename clean_type<Args>::type>&... args)
{
auto& r = __get_in_progress_registry<Ret, Args...>();
auto exists = r.find(func, args...);
if (exists) {
return *exists;
} else {
std::shared_ptr<async_computation<Ret(Args...)>>
ac(new async_computation<Ret(Args...)>(_Sync, proxy, args...));
return r.get(func, args...) = register_task_in_progress(ac, func, args...);
}
}
template <typename Ret, typename... Args>
struct cached_computation<Ret(Args...)> {
......@@ -592,21 +649,21 @@ template <typename Ret, typename... Args>
computed_value(CachingPolicy _Sync, Ret (*func) (Args...), const value<typename clean_type<Args>::type>&... args)
: m_hash(compute_hash(args...))
, m_task(_Sync, func, args...)
, m_task(make_async_computation<Ret, Args...>(_Sync, func, args...))
{}
virtual
value_type& operator * ()
override { return m_task.__get_noconst(); }
override { return m_task->__get_noconst(); }
virtual
value_type* operator -> ()
override { return &m_task.__get_noconst(); }
override { return &m_task->__get_noconst(); }
virtual
const value_type& operator * () const
override { return m_task.__get_const(); }
override { return m_task->__get_const(); }
virtual
const value_type* operator -> () const
override { return &m_task.__get_const(); }
override { return &m_task->__get_const(); }
virtual
size_t hash() const
......@@ -617,7 +674,7 @@ template <typename Ret, typename... Args>
/*protected:*/
size_t m_hash;
async_computation<Ret(Args...)> m_task;
std::shared_ptr<async_computation<Ret(Args...)>> m_task;
};
template <typename Ret, typename... Args>
......@@ -628,35 +685,35 @@ template <typename Ret, typename... Args>
cached_computed_value(CachingPolicy _Sync, Ret (*func) (Args...), const value<typename clean_type<Args>::type>&... args)
: m_comp(get_func_name(func), func, args...)
, m_comp_proxy([this](Args... x) { return m_comp(x...); })
, m_task(_Sync, m_comp_proxy, args...)
, m_task(make_async_computation<Ret, Args...>(_Sync, func, m_comp_proxy, args...))
{}
/*m_hash = m_comp.m_md5_hash.md5.context;*/
/*}*/
virtual
value_type& operator * ()
override { return m_task.__get_noconst(); }
override { return m_task->__get_noconst(); }
virtual
value_type* operator -> ()
override { return &m_task.__get_noconst(); }
override { return &m_task->__get_noconst(); }
virtual
const value_type& operator * () const
override { return m_task.__get_const(); }
override { return m_task->__get_const(); }
virtual
const value_type* operator -> () const
override { return &m_task.__get_const(); }
override { return &m_task->__get_const(); }
virtual
size_t hash() const override
/*override { return m_hash; }*/
{
(void)m_task.__get_const();
(void)m_task->__get_const();
return m_comp.m_md5_hash.md5.context;
}
virtual
md5_digest& md5(md5_digest& md) const override
{
(void)m_task.__get_const();
(void)m_task->__get_const();
return md.blend(m_comp.m_md5_hash.md5.context);
}
/*override { return md; }*/
......@@ -664,7 +721,7 @@ template <typename Ret, typename... Args>
/*protected:*/
cached_computation<Ret(Args...)> m_comp;
std::function<Ret(Args...)> m_comp_proxy;
async_computation<Ret(Args...)> m_task;
std::shared_ptr<async_computation<Ret(Args...)>> m_task;
/*size_t m_hash;*/
};
......@@ -803,14 +860,14 @@ struct with_mem_cache_traits {
return_type
create(CachingPolicy _Sync, Ret (&f) (Args...), const clean_value_type<Args>&... x)
{
static std::mutex _;
std::unique_lock<std::mutex> lock_guard(_);
/*static std::mutex _;*/
/*std::unique_lock<std::mutex> lock_guard(_);*/
value<Ret>* ret_in_progress = __get_in_progress_registry<Ret, Args...>().find(&f, x...);
/*value<Ret>* ret_in_progress = __get_in_progress_registry<Ret, Args...>().find(&f, x...);*/
if (ret_in_progress) {
return *ret_in_progress;
}
/*if (ret_in_progress) {*/
/*return *ret_in_progress;*/
/*}*/
/*MSG_DEBUG("new value with mem cache");*/
return_type ret = __get_registry<Ret, Args...>().get(&f, x...);
......@@ -830,11 +887,11 @@ struct without_mem_cache_traits {
return_type
create(CachingPolicy _Sync, Ret (&f) (Args...), const clean_value_type<Args>&... x)
{
value<Ret>* ret_in_progress = __get_in_progress_registry<Ret, Args...>().find(&f, x...);
/*value<Ret>* ret_in_progress = __get_in_progress_registry<Ret, Args...>().find(&f, x...);*/
if (ret_in_progress) {
return *ret_in_progress;
}
/*if (ret_in_progress) {*/
/*return *ret_in_progress;*/
/*}*/
/*MSG_DEBUG("new value without mem cache");*/
return_type ret = new _Maker(_Sync, f, x...);
......
......@@ -21,15 +21,15 @@ INPUT_SRC=read_mark.cc read_map.cc design.cc read_trait.cc read_settings.cc pedi
MAIN_SRC=static_data.cc main.cc
COMPUTATIONS_SRC=basic_data.cc probabilities.cc model.cc frontends.cc
SRC=malloc.cc $(addprefix input/,$(INPUT_SRC)) $(addprefix computations/,$(COMPUTATIONS_SRC)) $(MAIN_SRC)
#SRC=$(addprefix input/,$(INPUT_SRC)) $(addprefix computations/,$(COMPUTATIONS_SRC)) $(MAIN_SRC)
#SRC=malloc.cc $(addprefix input/,$(INPUT_SRC)) $(addprefix computations/,$(COMPUTATIONS_SRC)) $(MAIN_SRC)
SRC=$(addprefix input/,$(INPUT_SRC)) $(addprefix computations/,$(COMPUTATIONS_SRC)) $(MAIN_SRC)
OBJ=$(subst .cc,.o,$(SRC))
DEP=$(subst .cc,.d,$(SRC))
COV_OBJ=$(subst .cc,.cov.o,$(SRC))
DEBUG_OPTS=-ggdb
#OPT_OPTS=-O3 -DEIGEN_NO_DEBUG -DNDEBUG
#DEBUG_OPTS=-ggdb
OPT_OPTS=-O3 -DEIGEN_NO_DEBUG -DNDEBUG
#OPT_OPTS=-O -DEIGEN_NO_DEBUG -DNDEBUG
#DEBUG_OPTS=-Winvalid-pch -ggdb #-H
......
......@@ -237,6 +237,7 @@ compute_state_to_parental_origin_haplo(const context_key& ck, const locus_key& l
stpom_data sd;
/*MSG_DEBUG("Computing stfopom order=" << lk->depth() << " gen@" << gen);*/
/*MSG_DEBUG_INDENT;*/
/*MSG_DEBUG((*gen));*/
if (!(lk && lk->locus != locus_key_struc::no_locus)) {
std::set<char> parents;
const std::vector<allele_pair>& ap_labels = gen->get_unique_labels();
......@@ -260,6 +261,8 @@ compute_state_to_parental_origin_haplo(const context_key& ck, const locus_key& l
sd.haplo1(parent_index[ap_labels[i].first.ancestor], i) = 1;
sd.haplo2(parent_index[ap_labels[i].second.ancestor], i) = 1;
}
/*MSG_DEBUG("prout");*/
/*MSG_DEBUG(sd);*/
} else {
value<stpom_data> first = get_stpom_data(ck, NULL);
value<stpom_data> pred = get_stpom_data(ck, lk->parent);
......
......@@ -401,11 +401,11 @@ assemble_parental_origins_multipop(
return pop.observed_traits.front().values.size();
};
static
std::function<std::vector<std::vector<char>>(const population&)>
get_labels = [&](const population& pop)
std::function<std::vector<std::vector<char>>(const population&)>
get_labels = [=](const population& pop)
{
context_key ck(new context_key_struc(&pop, *chr));
context_key ck(new context_key_struc(&pop, *chr, std::vector<double>()));
/*MSG_DEBUG(ck);*/
return make_value<Mem>(compute_state_to_parental_origin,
value<context_key>{ck},
lk)->row_labels;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment