charm AT lists.siebelschool.illinois.edu
Subject: Charm++ parallel programming system
List archive
Re: [charm] What if CkReductionTarget's argument is a type that is template argument?
Chronological Thread
- From: Jozsef Bakosi <jbakosi AT gmail.com>
- To: "charm AT cs.uiuc.edu" <charm AT cs.uiuc.edu>
- Subject: Re: [charm] What if CkReductionTarget's argument is a type that is template argument?
- Date: Fri, 1 May 2015 08:14:50 -0600
- List-archive: <http://lists.cs.uiuc.edu/pipermail/charm/>
- List-id: CHARM parallel programming system <charm.cs.uiuc.edu>
Here is a solution using overloads on the template argument, in case someone is interested. (Code below not tested.)
In .h file:
-----------------------
template< class Host >
class A : public CBase_A< Host > {
public:
// Constructor stores host proxy
A( Host& host ) : m_host( host ) {}
// Function that wants to contribute to a reduction to Host::init()
void fun() { contributeTo( m_host ); }
private:
Host m_host;
// C++11 typedef so that the compiler can find CBase_A< Host >::contribute()
using Group = CBase_A< Host >;
// Overload for Host = HostA
void contributeTo( const CProxy_HostA& ) {
Group::contribute( CkCallback(CkIndex_HostA::redn_wrapper_init(NULL), m_host) );
}
// Overload for Host = HostB
void contributeTo( const CProxy_HostB& ) {
Group::contribute( CkCallback(CkIndex_HostB::redn_wrapper_init(NULL), m_host) );
}
};
In A's .ci file:
-----------------------
chare A< CProxy_HostA >;
chare A< CProxy_HostB >;
template< class Host >
group A {
entry A( Host& host );
}
In HostA's .ci file:
-----------------------
chare HostA {
entry HostA();
entry [reductiontarget] void init();
}
In HostB's .ci file:
-----------------------
chare HostB {
entry HostB();
entry [reductiontarget] void init();
}
The advantage is simpler client-code, e.g., HostA and HostB, now requires no explicit book-keeping with counters, etc. But more importantly, a reduction (instead of a direct call to the host) could better utilize the communication network as computational nodes can send their aggregated contribution to other nodes on a network instead of all chares sending their (smaller) contributions to the same host, e.g., tree-reduction vs. direct sends.
The disadvantage is that changes to macro Charm++s' CkReductionTarget() will break the code above and thus needs to be maintained with Charm++ upgrades.
J
On Fri, Apr 17, 2015 at 3:18 PM, Jozsef Bakosi <jbakosi AT gmail.com> wrote:
Hi folks,How can I create a callback to a driver whose type is a template argument?In essence, I want to add a line CkReduction(...) in my class that is templated on the type to which I want to call back.I see that CkReductionTarget is a macro:CkReductionTarget(me, method) CkIndex_##me::redn_wrapper_##method(NULL)which creates "CkIndex_<DRIVER>" from the first argument '<DRIVER>'. This requires hardcoding the specialized <DRIVER>'s name to the call, which will fail for a different template argument. I cannot pass the template argument to the macro since preprocessing happens earlier than type resolution and the string of the template argument will be substituted instead of the type specialized.I could use template metaprogramming to get the CkIndex_<DRIVER> type from type <DRIVER> at compile time and so I could generate what the macro generates, but I don't know what "redn_wrapper_" stands for.Does someone have an idea how to resolve this?Thanks,Jozsef
- Re: [charm] What if CkReductionTarget's argument is a type that is template argument?, Jozsef Bakosi, 05/01/2015
Archive powered by MHonArc 2.6.16.