Skip to Content.
Sympa Menu

charm - Re: [charm] Design question

charm AT lists.cs.illinois.edu

Subject: Charm++ parallel programming system

List archive

Re: [charm] Design question


Chronological Thread 
  • From: "Mikida, Eric P" <mikida2 AT illinois.edu>
  • To: Robert Steinke <rsteinke AT uwyo.edu>
  • Cc: Charm Mailing List <charm AT cs.illinois.edu>
  • Subject: Re: [charm] Design question
  • Date: Tue, 11 Apr 2017 23:57:26 +0000
  • Accept-language: en-US

Hey Bob,

I’ve run into similar issues before regarding sending inherited types around
in Charm++. I’ll have to go back and see exactly how I’ve handled it in the
past and get back to you on that part. However, for the second question, like
you pointed out the issue is C++ typing issue.

One workaround for that would be to use the T* vector<T>::data(). You could
change receiveMessages signature to void receiveMessages(BaseMessageType**
msgs, int count). Then in the entry method, you would instead call
receiveMessages(messages.data(), messages.size()).

Eric

> On Apr 10, 2017, at 3:40 PM, Robert Steinke
> <rsteinke AT uwyo.edu>
> wrote:
>
> I have a general question about the design of some code I'm writing. I've
> got a situation with some Charm++ messages and some C++ inheritance.
> Basically, I just want to get anyone's impression if there's a better way
> to do it than what I'm currently doing.
>
> In my .ci file I have a chare array and some code like this:
>
>
> thisProxy[some other array element].sendNeighborAttributes(some data);
>
> ...
>
> when sendNeighborAttributes(const std::vector<NeighborMessage>& messages) {
> serial { receiveMessages(messages); }
> }
>
> ...
>
> thisProxy[some other array element].sendState(some data);
>
> ...
>
> when sendState(const std::vector<StateMessage>& messages) {
> serial { receiveMessages(messages); }
> }
>
> ...
>
> thisProxy[some other array element].sendWater(some data);
>
> ...
>
> when sendWater(const std::vector<WaterMessage>& messages) {
> serial { receiveMessages(messages); }
> }
>
>
> The thing is, NeighborMessage, StateMessage, and WaterMessage all inherit
> from a common base class. When I receive a message I do the same thing for
> all three. I hand the message to a contained class, and that class figures
> out polymorphically what to do with it. That's why I call the same
> receiveMessages function in all three cases. But I still have
> nearly-duplicated code in the .ci file.
>
> My first question is can I combine the three when clauses in the .ci file
> into one? I think I might need them to have separate signatures because it
> needs to pup a vector of WaterMessage, not a vector of the base class.
>
> My second question relates to the receiveMessages function. It looks like
> this:
>
> template <typename T> inline void receiveMessages(std::vector<T>& messages)
> {
> typename std::vector<T>::iterator it; // Loop iterator.
>
> // Loop over messages calling receiveMessage for each one.
> for (it = messages.begin(); it != messages.end(); ++it) {
> receiveMessage(*it);
> }
> }
>
> void receiveMessage(Message& message);
>
> The only way I could get it working was to make receiveMessages a template
> function. I'd rather have it be a polymorphic function taking the base
> class. Notice that once I have a single message instead of a vector of
> them I can call a polymorphic function on the single object. I guess
> std::vector<SubClass> isn't a subclass of std::vector<SuperClass>. I
> suppose this is really more of a C++ question than a Charm++ question, but
> is there any better way to do this?
>
> Thanks for any help. This is not urgent. I have code that works. I'm just
> trying to improve my Charm++-Fu
>
> Bob Steinke
>




Archive powered by MHonArc 2.6.19.

Top of Page