#include "groupring.h"

int groupring_thisgroup;
static int nextseq = 0;

void groupring_init(void)
{
  groupring_message *msg = new groupring_message(nextseq++,0);
  CProxy_groupring_group pgg(groupring_thisgroup);
  pgg.start(msg, 0);
}

void groupring_moduleinit(void) {}

void groupring_group::start(groupring_message *msg)
{
  if(CkMyPe()==0 && msg->iter==NITER) {
    delete msg;
    finishTest();
  } else if(CkMyPe()==0) {
    msg->iter++;
    CProxy_groupring_group pgg(groupring_thisgroup);
    pgg.start(msg, (CkMyPe()+1)%CkNumPes());
  } else {
    CProxy_groupring_group pgg(groupring_thisgroup);
    pgg.start(msg, (CkMyPe()+1)%CkNumPes());
  }
}

#include "groupring.def.h"
