Exemplo n.º 1
0
def master():
    this_actor.info("Start 1st sleeper")
    actor = Actor.create("1st sleeper from master", Host.current(), sleeper)
    this_actor.info("Join the 1st sleeper (timeout 2)")
    actor.join(2)

    this_actor.info("Start 2nd sleeper")
    actor = Actor.create("2nd sleeper from master", Host.current(), sleeper)
    this_actor.info("Join the 2nd sleeper (timeout 4)")
    actor.join(4)

    this_actor.info("Start 3rd sleeper")
    actor = Actor.create("3rd sleeper from master", Host.current(), sleeper)
    this_actor.info("Join the 3rd sleeper (timeout 2)")
    actor.join(2)

    this_actor.info("Start 4th sleeper")
    actor = Actor.create("4th sleeper from master", Host.current(), sleeper)
    this_actor.info("Waiting 4")
    this_actor.sleep_for(4)
    this_actor.info("Join the 4th sleeper after its end (timeout 1)")
    actor.join(1)

    this_actor.info("Goodbye now!")

    this_actor.sleep_for(1)

    this_actor.info("Goodbye now!")
Exemplo n.º 2
0
def do_sleep5(i, dur):
    if i > 0:
        this_actor.info("5-Iter {:d}".format(i))
        do_sleep1(i - 1, dur)
        this_actor.sleep_for(dur)
        this_actor.info("5-Mid ({:d})".format(i))
        do_sleep1(int(i / 2), dur)
        this_actor.info("5-Done ({:d})".format(i))
Exemplo n.º 3
0
    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!")
Exemplo n.º 4
0
def my_daemon():
    """The daemon, displaying a message every 3 seconds until all other processes stop"""
    Actor.self().daemonize()

    while True:
        this_actor.info("Hello from the infinite loop")
        this_actor.sleep_for(3.0)

    this_actor.info(
        "I will never reach that point: daemons are killed when regular processes are done"
    )
Exemplo n.º 5
0
    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!")
Exemplo n.º 6
0
def monitor():
    boivin = Host.by_name("Boivin")
    jacquelin = Host.by_name("Jacquelin")
    fafard = Host.by_name("Fafard")

    actor = Actor.create("worker", fafard, worker, boivin, jacquelin)

    this_actor.sleep_for(5)

    this_actor.info("After 5 seconds, move the process to {:s}".format(
        jacquelin.name))
    actor.host = jacquelin

    this_actor.sleep_until(15)
    this_actor.info("At t=15, move the process to {:s} and resume it.".format(
        fafard.name))
    actor.host = fafard
    actor.resume()
Exemplo n.º 7
0
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.")
Exemplo n.º 8
0
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)

    this_actor.info("Start a new actor, and kill it right away")
    victim_c = Actor.create("victim C", Host.by_name("Jupiter"), victim_a_fun)
    victim_c.kill()

    this_actor.sleep_for(1)

    this_actor.info("Killing everybody but myself")
    Actor.kill_all()

    this_actor.info("OK, goodbye now. I commit a suicide.")
    this_actor.exit()

    this_actor.info(
        "This line never gets displayed: I'm already dead since the previous line."
    )
Exemplo n.º 9
0
    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))

        activity.host = boivin

        this_actor.sleep_for(0.1)
        this_actor.info(
            "Loads after the move: Boivin={:.0f}; Fafard={:.0f}; Ginette={:.0f}"
            .format(boivin.load, fafard.load, ginette.load))

        activity.wait()
        this_actor.info("Done!")
Exemplo n.º 10
0
def sleeper():
    this_actor.info("Sleeper started")
    this_actor.sleep_for(3)
    this_actor.info("I'm done. See you!")
Exemplo n.º 11
0
 def __call__(self):
     this_actor.info("Hello! I go to sleep.")
     this_actor.sleep_for(10)
     this_actor.info("Done sleeping.")
Exemplo n.º 12
0
def dream_master():
    """The Dream master"""
    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)
    this_actor.info("Back to work, lazy guy!")
    lazy.resume()

    this_actor.info("OK, I'm done here.")
Exemplo n.º 13
0
def receiver():
    this_actor.sleep_for(5)
    this_actor.info("Five seconds elapsed")
Exemplo n.º 14
0
def sender():
    this_actor.sleep_for(3)
    this_actor.info("Goodbye now!")