2017-05-18 34 views
1

のは私がエージェントのリストを持っている。このユニットSpecmanに「parallel all of」がありますか?

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

を持っていると仮定しましょう、エージェントの数が異なります。私はすべてのエージェントがinit_all_regs()メソッドを呼び出して、すべてが並列に実行されるようにしたい。

"all"と "for each"の構文の組み合わせはありますか?

答えて

3

"all for each"構文はありませんが、既存の構文で実装するのは簡単です。たとえば、異論を使用することができます。 objection_kindを定義し、これを使用して同期します。例えば

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; 
     }; 
    }; 
}; 
1

別のオプションは、静的メンバで実装カウンタを使用することです。 1つの欠点は、より多くのラインが必要であることです。

このような何か -

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; 
     }; 
    }; 
    }; 
関連する問題