Skip to Content.
Sympa Menu

charm - [charm] Design question

charm AT lists.cs.illinois.edu

Subject: Charm++ parallel programming system

List archive

[charm] Design question


Chronological Thread 
  • From: Robert Steinke <rsteinke AT uwyo.edu>
  • To: Charm Mailing List <charm AT cs.illinois.edu>
  • Subject: [charm] Design question
  • Date: Mon, 10 Apr 2017 14:40:22 -0600
  • Authentication-results: cs.illinois.edu; dkim=none (message not signed) header.d=none;cs.illinois.edu; dmarc=none action=none header.from=uwyo.edu;
  • Spamdiagnosticmetadata: NSPM
  • Spamdiagnosticoutput: 1:99

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