DistributedAgentSieve.borg

DistributedAgentSieve.borg


{
machines:
    [
    agent("igwepc121/Alice&ui"),
    agent("igwepc122/Alice&ui"),
    agent("igwepc123/Alice&ui"),
    agent("igwepc124/Alice&ui")
    ];

`creeert zeef-agents
createsieve(next,collector,sievenr)::
    {
    prime:0;
    data(num)::
        {
        if (prime = 0,
            collector.prime(prime:=num),
                if( (!((num\\prime)=0)), next.data(num)))};
    display("created sieve"+text(sievenr)+eoln);
    clone2agent("sieve"+text(sievenr))
    };

`verzameld primes en print ze
numcounter:0;
prime(p)::
    {
    if ((numcounter\\10)=0,display(eoln));
    display("  "+text(p));
    numcounter:=numcounter+1
    };

data(p)::void;

`start de zeef met 20 agents for machine 1,2,3 en 4
startsieve()::
{
  col:beg:agentname;

  for(i:20,i>0,i:=i-1,
    {beg:=createsieve(beg,col,i);
    beg.agentmove(machines[1])});
  for(i:40,i>20,i:=i-1,
    {beg:=createsieve(beg,col,i);
    beg.agentmove(machines[2])});
  for(i:60,i>40,i:=i-1,
    {beg:=createsieve(beg,col,i);
    beg.agentmove(machines[3])});
  for(i:80,i>60,i:=i-1,
    {beg:=createsieve(beg,col,i);
    beg.agentmove(machines[4])});

    display("Starting Datastream"+eoln);
  for(i:2,i<200,i:=i+1, beg.data(i))
};

display("startsieve()")
}