#include "nodering.h"

int nodering_thisgroup;
static int nextseq = 0;

void nodering_init(void)
{
  nodering_message *msg = new nodering_message(nextseq++,0);
  CProxy_nodering_group pgg(nodering_thisgroup);
  pgg.start(msg, 0);
}

void nodering_moduleinit(void) {}

void nodering_group::start(nodering_message *msg)
{
  if(CkMyNode()==0 && msg->iter==NITER) {
    delete msg;
    finishTest();
  } else if(CkMyNode()==0) {
    msg->iter++;
    CProxy_nodering_group pgg(nodering_thisgroup);
    pgg.start(msg, (CkMyNode()+1)%CkNumNodes());
  } else {
    CProxy_nodering_group pgg(nodering_thisgroup);
    pgg.start(msg, (CkMyNode()+1)%CkNumNodes());
  }
}

#include "nodering.def.h"
