#include <collate.cvh>
#include <stdlib.h>
#include <stdio.h>

$scope root = $here;
$gcollator gcollator;

void process(int place) {
  $scope here = $here;	
  $collator collator = $collator_create(gcollator, here, place);
  $collate_state cs;

  cs = $collate_arrives(collator, here);
  if($collate_complete(cs)) printf("place = %d, complete!\n", place);
  $collate_departs(collator, cs);
  free(collator);
}

int main() {
  gcollator = $gcollator_create(root, 5);
  $parfor (int i : 0 .. 4)    {
    process(i);
}   
  $gcollator_destroy(gcollator);
  return 0;
}
