31 #ifndef __adevs_par_simulator_h_
32 #define __adevs_par_simulator_h_
33 #include "adevs_abstract_simulator.h"
34 #include "adevs_msg_manager.h"
36 #include "adevs_lp_graph.h"
93 LogicalProcess<X,T>** lp;
100 template <
class X,
class T>
105 lp_count = omp_get_max_threads();
107 for (
int i = 0; i < lp_count; i++)
109 for (
int j = 0; j < lp_count; j++)
121 template <
class X,
class T>
129 template <
class X,
class T>
134 if (omp_get_max_threads() < lp_count)
137 sprintf(buffer,
"More LPs than threads. Set OMP_NUM_THREADS=%d.",
142 omp_set_num_threads(lp_count);
143 lp =
new LogicalProcess<X,T>*[lp_count];
144 for (
int i = 0; i < lp_count; i++)
146 lp[i] =
new LogicalProcess<X,T>(i,g.
getI(i),g.
getE(i),
147 lp,
this,msg_manager);
152 template <
class X,
class T>
156 for (
int i = 0; i < lp_count; i++)
158 if (lp[i]->getNextEventTime() < tN)
159 tN = lp[i]->getNextEventTime();
164 template <
class X,
class T>
167 for (
int i = 0; i < lp_count; i++)
173 template <
class X,
class T>
178 lp[omp_get_thread_num()]->run(tstop);
182 template <
class X,
class T>
187 lp[model->
getProc()]->addModel(model);
193 int lp_assign = a->getProc();
194 if (lp_assign < 0 || lp_assign >= lp_count)
196 ((
unsigned long int)(a)^(
unsigned long int)(
this))%lp_count;
197 lp[lp_assign]->addModel(a);
201 Set<Devs<X,T>*> components;
203 typename Set<Devs<X,T>*>::iterator iter = components.begin();
204 for (; iter != components.end(); iter++)
static adevs::Time< T > Inf()
Value for infinity.
Definition: adevs_time.h:58
Definition: adevs_abstract_simulator.h:45
Definition: adevs_msg_manager.h:63
Definition: adevs_par_simulator.h:55
T nextEventTime()
Get the model's next event time.
Definition: adevs_par_simulator.h:153
int getProc()
Definition: adevs_models.h:130
Definition: adevs_lp_graph.h:46
Definition: adevs_exception.h:43
Definition: adevs_msg_manager.h:41
~ParSimulator()
Definition: adevs_par_simulator.h:165
Definition: adevs_time.h:53
virtual Network< X, T > * typeIsNetwork()
Definition: adevs_models.h:81
const std::vector< int > & getI(int B)
Get the influencers of node B.
Definition: adevs_lp_graph.h:66
virtual Atomic< X, T > * typeIsAtomic()
Returns NULL if this is not an atomic model; returns itself otherwise.
Definition: adevs_models.h:83
Definition: adevs_models.h:63
void execUntil(T stop_time)
Definition: adevs_par_simulator.h:174
int getLPCount() const
Get the number of LPs.
Definition: adevs_lp_graph.h:64
void addEdge(int A, int B)
Create an edge from node A to node B.
Definition: adevs_lp_graph.h:52
const std::vector< int > & getE(int A)
Get the influencees of node A.
Definition: adevs_lp_graph.h:68
ParSimulator(Devs< X, T > *model, MessageManager< X > *msg_manager=NULL)
Definition: adevs_par_simulator.h:101