2

Let’s assume I have this unit

unit agent {
    init_all_regs() @clock is {…};
};

I have a list of agents, the number of agents vary. I want to call the method init_all_regs() all of the agents, so that all of them run in parallel.

Is there some combination of “all of” and “for each” syntax?

2 Answers2

4

There is no "all of for each" syntax, but there is easy to implement with existing syntax. For example, you can use objections. Define an objection_kind, and use it to synchronize.

for example:

extend objection_kind :[AGNETS_CHECK_REGS];

unit agent {
    init_all_regs()@clk is {
        raise_objection(AGNETS_CHECK_REGS);
        //...
        drop_objection(AGNETS_CHECK_REGS);   
    };
};
extend env {
   my_method() @clock is {
        for each in agents {
        start it.init_all_regs();
        };

        wait cycle;
        while get_objection_total(AGNETS_CHECK_REGS) > 0 {
            wait cycle;
        };
   };
};
user3467290
  • 706
  • 3
  • 4
1

Another option is to use a counter, implemented with static member. One disadvantage is that it needs more lines.

Something like this -

unit agent {
    static active_counter : int = 0;
    static increase_active_counter() is {
        active_counter += 1;
    };
    ////....
    init_all_regs()@clk is {
        increase_active_counter();
        //....

        decrease_active_counter();
    };
};

extend env {
    scenario() @any is {

        agent::init_active_counter();

        for each in agents {
            start it.init_all_regs();
        };

        wait cycle;
        while agent::get_active_counter() > 0 {
            wait cycle;
        };
    };
  };
user3467290
  • 706
  • 3
  • 4