Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __call__(self):
computation_amount = this_actor.get_host().speed
this_actor.info("Execute {:.0f} flops, should take 1 second.".format(computation_amount))
activity = this_actor.exec_init(computation_amount).start()
while not activity.test():
this_actor.info("Remaining amount of flops: {:.0f} ({:.0f}%)".format(
activity.remaining, 100 * activity.remaining_ratio))
this_actor.sleep_for(0.3)
activity.wait()
this_actor.info("Goodbye now!")
def __call__(self):
computation_amount = this_actor.get_host().speed
this_actor.info("Execute {:.0f} flops, should take 1 second.".format(computation_amount))
activity = this_actor.exec_init(computation_amount)
activity.start()
activity.wait()
this_actor.info("Goodbye now!")
def __call__(self):
for _ in range(self.number_of_yields):
this_actor.yield_()
this_actor.info("I yielded {:d} times. Goodbye now!".format(
self.number_of_yields))
def receiver(mailbox_name):
"""
Our first class of actors is simply implemented with a function, that takes a single string as parameter.
Later, this actor class is instantiated within the simulation.
"""
mailbox = Mailbox.by_name(mailbox_name)
this_actor.info(
"Hello s4u, I'm ready to get any message you'd want on {:s}".format(mailbox.name))
msg1 = mailbox.get()
msg2 = mailbox.get()
msg3 = mailbox.get()
this_actor.info(
"I received '{:s}', '{:s}' and '{:s}'".format(msg1, msg2, msg3))
this_actor.info("I'm done. See you.")
def lazy_guy():
"""The Lazy guy only wants to sleep, but can be awaken by the dream_master process"""
this_actor.info("Nobody's watching me ? Let's go to sleep.")
this_actor.suspend() # - Start by suspending itself
this_actor.info("Uuuh ? Did somebody call me ?")
# - Then repetitively go to sleep, but get awaken
this_actor.info("Going to sleep...")
this_actor.sleep_for(10)
this_actor.info("Mmm... waking up.")
this_actor.info("Going to sleep one more time (for 10 sec)...")
this_actor.sleep_for(10)
this_actor.info("Waking up once for all!")
this_actor.info("Ok, let's do some work, then (for 10 sec on Boivin).")
this_actor.execute(980.95e6)
this_actor.info("Mmmh, I'm done now. Goodbye.")
def __call__(self):
this_actor.info("Hello! I go to sleep.")
this_actor.sleep_for(10)
this_actor.info("Done sleeping.")
mbox = mboxes[i % self.receivers_count]
this_actor.info("Send '{:s}' to '{:s}'".format(content, str(mbox)))
# Create a communication representing the ongoing communication, and store it in pending_comms
comm = mbox.put_async(content, self.msg_size)
pending_comms.append(comm)
# Start sending messages to let the workers know that they should stop
for i in range(0, self.receivers_count):
mbox = mboxes[i]
this_actor.info("Send 'finalize' to '{:s}'".format(str(mbox)))
comm = mbox.put_async("finalize", 0)
pending_comms.append(comm)
this_actor.info("Done dispatching all messages")
# Now that all message exchanges were initiated, wait for their completion in one single call
Comm.wait_all(pending_comms)
this_actor.info("Goodbye now!")