Skip to Content.
Sympa Menu

charm - Re: [charm] [ppl] Custom reduction type contributing a user-defined type

charm AT lists.cs.illinois.edu

Subject: Charm++ parallel programming system

List archive

Re: [charm] [ppl] Custom reduction type contributing a user-defined type


Chronological Thread 
  • From: Nikhil Jain <nikhil.jain AT acm.org>
  • To: Jozsef Bakosi <jbakosi AT gmail.com>, Orion Lawlor <lawlor AT alaska.edu>
  • Cc: "charm AT cs.uiuc.edu" <charm AT cs.uiuc.edu>
  • Subject: Re: [charm] [ppl] Custom reduction type contributing a user-defined type
  • Date: Mon, 20 Jul 2015 16:58:15 -0500
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/charm/>
  • List-id: CHARM parallel programming system <charm.cs.uiuc.edu>

Orion,

What you have said holds true for current versions of Charm++. I see
it as one of the implementation for doing what Joszef wants, i.e. to
serialize and deserialize non-POD at appropriate time to reduce them.

Initially, I din't realize that Joszef din't choose the pup-based
implementation path because its working was not obvious to him, and
the online documentation does not cover use of pup in that way. Thanks
for suggesting this route.

Joszef,

Please see attached an example on how pup can be used in this context.

--Nikhil


On Mon, Jul 20, 2015 at 4:17 PM, Tom Quinn
<trq AT astro.washington.edu>
wrote:
> You might want to look at some of the reducers in ChaNGa (Reductions.cpp).
> See, e.g. the "boxGrowth" reducer. For a really crazy example, look in
> salsa/ResolutionServer/Reductions.cpp. In there is a "pythonReduce" which
> serializes Python objects and implements the "Map/Reduce" paradigm in
> Charm++.
>
> Tom Quinn Astronomy, University of Washington
> Internet:
> trq AT astro.washington.edu
> Phone: 206-685-9009
>
>
> On Mon, 20 Jul 2015, Eric Bohm wrote:
>
>> The sparseReducer library does some of that work already. However it
>> currently only works on sparse arrays of POD data.
>>
>> On 07/20/2015 03:46 PM, Orion Lawlor wrote:
>> Nikhil, it is true the reduction system only works with a
>> contiguous block of bytes, but the same is actually true of the
>> Charm++ message passing system at the bottom level--parameter
>> marshalling is a fairly thin layer that serializes the C++
>> object to a buffer, sends it as a simple flat message, and
>> unpacks it on the other side. Couldn't Jozsef do the same thing
>> with a custom reducer type--unpack the inputs from flat bytes,
>> combine them as C++ objects, then reserialize before returning?
>> I'd reply to him directly, but it'd be good if somebody tested and
>> wrote up a good example for the manual before I mislead customers with
>> my decade-old Charm++ knowledge!
>>
>> On Mon, Jul 20, 2015 at 7:21 AM, Nikhil Jain
>> <nikhil.jain AT acm.org>
>> wrote:
>> Hi Jozsef,
>>
>> Unfortunately, contributions to reductions have to be a
>> contiguous
>> buffer of data. Advanced support for contributing and
>> reducing non-POD
>> does not exist in Charm++ currently. The round about way
>> you described
>> is the only method I know of.
>>
>> --Nikhil
>>
>> On Fri, Jul 17, 2015 at 12:50 PM, Jozsef Bakosi
>>
>> <jbakosi AT gmail.com>
>> wrote:
>> > Hi folks,
>> >
>> > What is the recommended way to define a custom reduction
>> in which chare
>> > array elements contribute user-defined-type (ptentially
>> non-POD) objects?
>> >
>> > What I have in mind is to convert an existing
>> contribution of chare array
>> > elements using the vanilla entry-method call, estimate()
>> to a typed (or
>> > non-typed) reduction. Example:
>> >
>> > User-defined non-POD type:
>> >
>> > class Cat {
>> > std::map< int, double > catmap;
>> > void pup( PUP::er& p ) { ... }
>> > };
>> >
>> > === Inefficient contribution using existing vanilla
>> entry method call to
>> > host from array elements ===
>> >
>> > In some member function of a chare array:
>> >
>> > std::vector< Cat > v;
>> > hostproxy.estimate( v ); // non-reduction
>> contribute a vector of Cats
>> >
>> > In the host's .ci file:
>> >
>> > entry void estimate( std::vector< Cat >& v );
>> >
>> > === Pseudo-code yielding a more efficient reduction to
>> host from array
>> > elements ===
>> >
>> > Now in some member function of a chare array:
>> >
>> > std::vector< Cat > v;
>> > // reduction contribute a vector of Cats
>> > contribute( ... some way to specify the contribution v,
>> hostproxy, and a
>> > custom reduction type on how to merge a Cat across a
>> reduction );
>> >
>> > Now in the host's .ci file:
>> >
>> > entry [reductiontarget] void estimate( some way to
>> receive a std::vector<
>> > Cat > );
>> >
>> > I think I should define a new reduction type (as in 16.2), but
>> that example
>> > defines a custom reduction on a POD data of two short ints.
>> What I think I
>> > need is a custom reduction on a non-POD type (Cat, containing
>> a std::map).
>> >
>> > One solution I know I can do is to convert the std::map in Cat
>> to a POD for
>> > the purpose of contributing to a reduction, but I'm wondering
>> if there is a
>> > better/cleaner way to do this.
>> >
>> > Thanks,
>> > Jozsef
>> >
>> > _______________________________________________
>> > charm mailing list
>> > charm AT cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/charm
>> >
>>
>>
>>
>> --
>> Nikhil Jain,
>> nikhil.jain AT acm.org,
>> http://charm.cs.uiuc.edu/people/nikhil
>> Doctoral Candidate @ CS, UIUC
>> _______________________________________________
>> charm mailing list
>> charm AT cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/charm
>> _______________________________________________
>> ppl mailing list
>> ppl AT cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/ppl
>>
>>
>>
>>
>> --
>> Dr. Orion Sky Lawlor
>> lawlor AT alaska.edu
>> http://www.cs.uaf.edu/~olawlor/
>>
>>
>> _______________________________________________
>> charm mailing list
>> charm AT cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/charm
>>
>>
>>
>
> _______________________________________________
> charm mailing list
> charm AT cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/charm
>



--
Nikhil Jain,
nikhil.jain AT acm.org,
http://charm.cs.uiuc.edu/people/nikhil
Doctoral Candidate @ CS, UIUC
#include <stdio.h>
#include "hello.decl.h"

/*readonly*/ CProxy_Main mainProxy;
/*readonly*/ int nElements;

CkReduction::reducerType classRed;

class TestClass {
  public:
  int id;
  int value;

  void pup(PUP::er &p) {
    p | id;
    p | value;
  }
};

CkReductionMsg *findHigherClass(int nMsg, CkReductionMsg **msgs) {
  TestClass final;
  PUP::fromMem creator(msgs[0]->getData());
  creator | final;

  for (int i = 1; i < nMsg; i++) {
    TestClass curData;
    PUP::fromMem curCreater(msgs[i]->getData());
    curCreater | curData;
    if(curData.value > final.value) {
      final.id = curData.id;
      final.value = curData.value;
    }
  }

  PUP::sizer size_pup;
  size_pup | final;
  char *flatData = new char[size_pup.size()];
  PUP::toMem packer(flatData);
  packer | final;

  return CkReductionMsg::buildNew(size_pup.size(), flatData);
  delete [] flatData;
}

/*initnode*/ void registerClassRed(void)
{
  classRed = CkReduction::addReducer(findHigherClass);
}

/*mainchare*/
class Main : public CBase_Main
{
  public:
    Main(CkArgMsg* m)
    {
      nElements = 5;
      if(m->argc >1 ) nElements = atoi(m->argv[1]);
      delete m;

      CkPrintf("Running RedTest on %d processors for %d elements\n", CkNumPes(), 
          nElements);
      mainProxy = thisProxy;

      CProxy_Hello arr = CProxy_Hello::ckNew(nElements);
      arr.giveInput();
    };

    void printMaxRank(CkReductionMsg *msg)
    {
      PUP::fromMem creator(msg->getData());
      TestClass answer;
      creator | answer;

      printf("Maximum id found %d with value %d\n", answer.id, answer.value);
      delete msg;
      CkExit();
    };
};

class Hello : public CBase_Hello
{
  TestClass myData;
  public:
  Hello()
  {
    srand(CmiWallTimer()*1000000);
    myData.id = rand() % 1024;
    myData.value = rand() % 524288;
    printf("[%d][%d] Created %d %d\n", CkMyPe(), thisIndex, myData.id, myData.value);
  }

  Hello(CkMigrateMessage *m) {}

  void giveInput()
  {
    PUP::sizer size_pup;
    size_pup | myData;
    char *flatData = new char[size_pup.size()];
    PUP::toMem packer(flatData);
    packer | myData;
  
    CkCallback cb(CkIndex_Main::printMaxRank(NULL), mainProxy);
    contribute(size_pup.size(), flatData, classRed, cb);
    delete [] flatData;
  }
};

#include "hello.def.h"

Attachment: hello.ci
Description: Binary data

Attachment: Makefile
Description: Binary data




Archive powered by MHonArc 2.6.16.

Top of Page