Skip to Content.
Sympa Menu

charm - Re: [charm] PUP and enum types

charm AT lists.cs.illinois.edu

Subject: Charm++ parallel programming system

List archive

Re: [charm] PUP and enum types


Chronological Thread 
  • From: Sam White <white67 AT illinois.edu>
  • To: Jonah Miller <jonah.maxwell.miller AT gmail.com>
  • Cc: "charm AT cs.uiuc.edu" <charm AT cs.uiuc.edu>
  • Subject: Re: [charm] PUP and enum types
  • Date: Wed, 8 Jul 2015 22:24:48 -0700
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/charm/>
  • List-id: CHARM parallel programming system <charm.cs.uiuc.edu>

This should work:

inline void operator|(PUP::er &p, enum_type &s) {
     pup_bytes(&p, (void *)&s, sizeof(enum_type));
}

Also, if you are never passing a variable of this enum type to a parameter marshalled entry method and don't need a PUP method directly for it, and instead are only passing this enum type around as a member in a larger struct/class, then you can just use the pup_bytes() call above directly in that larger struct/class's PUP method.

-Sam

On Wed, Jul 8, 2015 at 9:31 PM, Jonah Miller <jonah.maxwell.miller AT gmail.com> wrote:
Hi Sam,

Thanks for your reply. This helps a lot. Since enum types can't have
methods, I will need to overload the pipe operator, but a naive
implementation results in compile time errors. Can you instruct me in
the best way to overload the pipe operator for PUP? Here is my current
attempt:

#ifndef INCLUDED_SIDES_HPP
#define INCLUDED_SIDES_HPP

#include <pup.h>

enum class Side{LEFT, RIGHT};

PUP::er& operator|(PUP::er& p, Side& s) {
   pup_bytes(&p, (void*)&s, sizeof(Side));
}

#endif // INCLUDED_SIDES_HPP

and this raises an error at linking time that says I've over-defined the
| operator:

~/programming/charm-functional-wavetoy/Sides.hpp:14: multiple definition
of `operator|(PUP::er&, Side&)'
wavetoy_unit_tests.o:/home/jmiller/programming/charm-functional-wavetoy/Sides.hpp:14:
first defined here
unittests.o: In function `operator|(PUP::er&, Side&)':
~/programming/charm-functional-wavetoy/Sides.hpp:14: multiple definition
of `operator|(PUP::er&, Side&)'
wavetoy_unit_tests.o:~/programming/charm-functional-wavetoy/Sides.hpp:14: first
defined here
collect2: error: ld returned 1 exit status

This is strange, because the compiler is pointing to the same file in
both cases, which is protected by include guards. Thanks for your help!

Best,
Jonah


On 15-07-08 11:59 AM, White, Samuel T wrote:
> Hi Jonah,
>
> The most portable way to PUP an enumerated type is to use the pup_bytes() interface, as in:
>
> void pup(PUP::er &p) {
>      pup_bytes(&p, (void *)&enum_var, sizeof(enum_type));
> }
>
> -Sam
> ________________________________________
> From: charm-bounces AT cs.uiuc.edu [charm-bounces AT cs.uiuc.edu] on behalf of Jonah Miller [jonah.maxwell.miller AT gmail.com]
> Sent: Saturday, July 04, 2015 4:58 PM
> To: charm AT cs.uiuc.edu
> Subject: [charm] PUP and enum types
>
> Hi Everyone,
>
> I have a quick question about the PUP framework. What is the proper way
> to pack or unpack enumerations? Under the hood, enumerations are
> integers, so it seems like they should be pup-able. But I wondered if
> there was a straightforward or "correct" way to do it.
>
> Thanks in advance for your help.
>
> Best,
> Jonah Miller
> _______________________________________________
> charm mailing list
> charm AT cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/charm





Archive powered by MHonArc 2.6.16.

Top of Page