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):
fafard = Host.by_name("Fafard")
ginette = Host.by_name("Ginette")
boivin = Host.by_name("Boivin")
this_actor.info("I'm a wizard! I can run a task on the Ginette host from the Fafard one! Look!")
activity = this_actor.exec_init(48.492e6)
activity.host = ginette
activity.start()
this_actor.info("It started. Running 48.492Mf takes exactly one second on Ginette (but not on Fafard).")
this_actor.sleep_for(0.1)
this_actor.info("Loads in flops/s: Boivin={:.0f}; Fafard={:.0f}; Ginette={:.0f}".format(boivin.load, fafard.load,
ginette.load))
activity.wait()
this_actor.info("Done!")
this_actor.info("And now, harder. Start a remote task on Ginette and move it to Boivin after 0.5 sec")
activity = this_actor.exec_init(73293500)
activity.host = ginette
activity.start()
this_actor.sleep_for(0.5)
this_actor.info(
"Loads before the move: Boivin={:.0f}; Fafard={:.0f}; Ginette={:.0f}".format(
boivin.load,
fafard.load,
ginette.load))
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).start()
this_actor.sleep_for(0.5)
this_actor.info("I changed my mind, cancel!")
activity.cancel()
this_actor.info("Goodbye now!")
actor.join(2)
this_actor.info("Start sleeper")
actor = Actor.create("sleeper from master", Host.current(), sleeper)
this_actor.info("Join the sleeper (timeout 4)")
actor.join(4)
this_actor.info("Start sleeper")
actor = Actor.create("sleeper from master", Host.current(), sleeper)
this_actor.info("Join the sleeper (timeout 2)")
actor.join(2)
this_actor.info("Start sleeper")
actor = Actor.create("sleeper from master", Host.current(), sleeper)
this_actor.info("Waiting 4")
this_actor.sleep_for(4)
this_actor.info("Join the sleeper after its end (timeout 1)")
actor.join(1)
this_actor.info("Goodbye now!")
this_actor.sleep_for(1)
this_actor.info("Goodbye now!")
this_actor.info("Start sleeper")
actor = Actor.create("sleeper from master", Host.current(), sleeper)
this_actor.info("Join the sleeper (timeout 2)")
actor.join(2)
this_actor.info("Start sleeper")
actor = Actor.create("sleeper from master", Host.current(), sleeper)
this_actor.info("Waiting 4")
this_actor.sleep_for(4)
this_actor.info("Join the sleeper after its end (timeout 1)")
actor.join(1)
this_actor.info("Goodbye now!")
this_actor.sleep_for(1)
this_actor.info("Goodbye now!")
def __call__(self):
this_actor.info("Hello! I go to sleep.")
this_actor.sleep_for(10)
this_actor.info("Done sleeping.")
this_actor.info("Let's create a lazy guy.") # Create a lazy_guy process
lazy = Actor.create("Lazy", this_actor.get_host(), lazy_guy)
this_actor.info("Let's wait a little bit...")
this_actor.sleep_for(10) # Wait for 10 seconds
this_actor.info("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!")
if lazy.is_suspended():
lazy.resume() # Then wake up the lazy_guy
else:
this_actor.error(
"I was thinking that the lazy guy would be suspended now")
this_actor.sleep_for(5) # Repeat two times:
this_actor.info("Suspend the lazy guy while he's sleeping...")
lazy.suspend() # Suspend the lazy_guy while he's asleep
this_actor.info("Let him finish his siesta.")
this_actor.sleep_for(10) # Wait for 10 seconds
this_actor.info("Wake up, lazy guy!")
lazy.resume() # Then wake up the lazy_guy again
this_actor.sleep_for(5)
this_actor.info("Suspend again the lazy guy while he's sleeping...")
lazy.suspend()
this_actor.info("This time, don't let him finish his siesta.")
this_actor.sleep_for(2)
this_actor.info("Wake up, lazy guy!")
lazy.resume()
this_actor.sleep_for(5)
this_actor.info(
"Give a 2 seconds break to the lazy guy while he's working...")
lazy.suspend()
this_actor.sleep_for(2)
def killer():
this_actor.info("Hello!") # - First start a victim process
victim_a = Actor.create("victim A", Host.by_name("Fafard"), victim_a_fun)
victim_b = Actor.create("victim B", Host.by_name("Jupiter"), victim_b_fun)
this_actor.sleep_for(10) # - Wait for 10 seconds
# - Resume it from its suspended state
this_actor.info("Resume the victim A")
victim_a.resume()
this_actor.sleep_for(2)
this_actor.info("Kill the victim A") # - and then kill it
Actor.by_pid(victim_a.pid).kill() # You can retrieve an actor from its PID (and then kill it)
this_actor.sleep_for(1)
# that's a no-op, there is no zombies in SimGrid
this_actor.info("Kill victim B, even if it's already dead")
victim_b.kill()
this_actor.sleep_for(1)
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.")