Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Variadic Templates - parralel_invoke

2 views
Skip to first unread message

Kenshin

unread,
Nov 23, 2009, 6:33:20 AM11/23/09
to
Given the code below (excerpt from ppl.h in VS2010 Pro Beta2), how can
parallel_invoke be re-written to use variadic templates? Keep in mind
has to be called last, with the last element from the parameter pack.
I have provided an implementation, but I am not sure if this will
achieve the intended goal.

--------------------------------------------------------------------
Original code (taking 10 template parameters):
--------------------------------------------------------------------

template <typename _Function1, typename _Function2, typename
_Function3, typename _Function4, typename _Function5,
typename _Function6, typename _Function7, typename _Function8,
typename _Function9, typename _Function10>
void parallel_invoke(const _Function1& _Func1, const _Function2&
_Func2, const _Function3& _Func3, const _Function4& _Func4, const
_Function5& _Func5,
const _Function6& _Func6, const _Function7& _Func7, const
_Function8& _Func8, const _Function9& _Func9, const _Function10&
_Func10)
{
_Trace_ppl_function(PPLParallelInvokeEventGuid,
_TRACE_LEVEL_INFORMATION, CONCRT_EVENT_START);

structured_task_group _Task_group;

task_handle<_Function1> _Task_handle1(_Func1);
_Task_group.run(_Task_handle1);

task_handle<_Function2> _Task_handle2(_Func2);
_Task_group.run(_Task_handle2);

task_handle<_Function3> _Task_handle3(_Func3);
_Task_group.run(_Task_handle3);

task_handle<_Function4> _Task_handle4(_Func4);
_Task_group.run(_Task_handle4);

task_handle<_Function5> _Task_handle5(_Func5);
_Task_group.run(_Task_handle5);

task_handle<_Function6> _Task_handle6(_Func6);
_Task_group.run(_Task_handle6);

task_handle<_Function7> _Task_handle7(_Func7);
_Task_group.run(_Task_handle7);

task_handle<_Function8> _Task_handle8(_Func8);
_Task_group.run(_Task_handle8);

task_handle<_Function9> _Task_handle9(_Func9);
_Task_group.run(_Task_handle9);

task_handle<_Function10> _Task_handle10(_Func10);
_Task_group.run_and_wait(_Task_handle10);

_Trace_ppl_function(PPLParallelInvokeEventGuid,
_TRACE_LEVEL_INFORMATION, CONCRT_EVENT_END);
}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------
My Var-Temp Implementation:
---------------------------------------------------

template <typename _Function1, typename _Function2>
void parallel_invoke(const _Function1& _Func1, const _Function2&
_Func2)
{
_Trace_ppl_function(PPLParallelInvokeEventGuid,
_TRACE_LEVEL_INFORMATION, CONCRT_EVENT_START);

structured_task_group _Task_group;

task_handle<_Function1> _Task_handle1(_Func1);
_Task_group.run(_Task_handle1);

task_handle<_Function2> _Task_handle2(_Func2);
_Task_group.run_and_wait(_Task_handle2);

_Trace_ppl_function(PPLParallelInvokeEventGuid,
_TRACE_LEVEL_INFORMATION, CONCRT_EVENT_END);
}


template <typename _Function1, typename _Function2, typename...
_Function3>
void parallel_invoke(const _Function1& _Func1, const _Function2&
_Func2, const _Function3&... _Func3)
{
_Trace_ppl_function(PPLParallelInvokeEventGuid,
_TRACE_LEVEL_INFORMATION, CONCRT_EVENT_START);

structured_task_group _Task_group;

task_handle<_Function1> _Task_handle1(_Func1);
_Task_group.run(_Task_handle1);

parallel_invoke(_Func2, _Func3...);

_Trace_ppl_function(PPLParallelInvokeEventGuid,
_TRACE_LEVEL_INFORMATION, CONCRT_EVENT_END);
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

0 new messages