コード例 #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!")
コード例 #2
0
ファイル: io-degradation.py プロジェクト: sthibaul/simgrid
def create_sata_disk(host: Host, disk_name: str):
    """ Same for a SATA disk, only read operation follows a non-linear resource sharing """
    disk = host.create_disk(disk_name, "68MBps", "50MBps")
    disk.set_sharing_policy(Disk.Operation.READ, Disk.SharingPolicy.NONLINEAR,
                            functools.partial(sata_dynamic_sharing, disk))
    # this is the default behavior, expliciting only to make it clearer
    disk.set_sharing_policy(Disk.Operation.WRITE, Disk.SharingPolicy.LINEAR)
    disk.set_sharing_policy(Disk.Operation.READWRITE,
                            Disk.SharingPolicy.LINEAR)
コード例 #3
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()
コード例 #4
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!")
コード例 #5
0
ファイル: platform-mix.py プロジェクト: sthibaul/simgrid
 def __call__(self):
     this_actor.execute(1e9)
     for disk in Host.current().get_disks():
         this_actor.info("Using disk " + disk.name)
         disk.read(10000)
         disk.write(10000)
     mbox = Mailbox.by_name(this_actor.get_host().name)
     msg = mbox.get()
     this_actor.info("I got '%s'." % msg)
     this_actor.info("Finished executing. Goodbye!")
コード例 #6
0
ファイル: io-degradation.py プロジェクト: sthibaul/simgrid
def create_ssd_disk(host: Host, disk_name: str):
    """ Creates an SSD disk, setting the appropriate callback for non-linear resource sharing """
    disk = host.create_disk(disk_name, "240MBps", "170MBps")
    disk.set_sharing_policy(
        Disk.Operation.READ, Disk.SharingPolicy.NONLINEAR,
        functools.partial(ssd_dynamic_sharing, disk, "read"))
    disk.set_sharing_policy(
        Disk.Operation.WRITE, Disk.SharingPolicy.NONLINEAR,
        functools.partial(ssd_dynamic_sharing, disk, "write"))
    disk.set_sharing_policy(Disk.Operation.READWRITE,
                            Disk.SharingPolicy.LINEAR)
コード例 #7
0
ファイル: actor-kill.py プロジェクト: soupria/simgrid
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."
    )
コード例 #8
0
ファイル: exec-dvfs.py プロジェクト: soupria/simgrid
    def __call__(self):
        workload = 100E6
        host = this_actor.get_host()

        nb = host.get_pstate_count()
        this_actor.info("Count of Processor states={:d}".format(nb))

        this_actor.info("Current power peak={:f}".format(host.speed))

        # Run a task
        this_actor.execute(workload)

        task_time = Engine.get_clock()
        this_actor.info("Task1 duration: {:.2f}".format(task_time))

        # Change power peak
        new_pstate = 2

        this_actor.info(
            "Changing power peak value to {:f} (at index {:d})".format(
                host.get_pstate_speed(new_pstate), new_pstate))

        host.pstate = new_pstate

        this_actor.info("Changed power peak={:f}".format(host.speed))

        # Run a second task
        this_actor.execute(workload)

        task_time = Engine.get_clock() - task_time
        this_actor.info("Task2 duration: {:.2f}".format(task_time))

        # Verify that the default pstate is set to 0
        host2 = Host.by_name("MyHost2")
        this_actor.info("Count of Processor states={:d}".format(
            host2.get_pstate_count()))

        this_actor.info("Final power peak={:f}".format(host2.speed))
コード例 #9
0
    this_actor.info("Let's do some work (for 10 sec on Boivin).")
    this_actor.execute(980.95e6)

    this_actor.info("I'm done now. I leave even if it makes the daemon die.")


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"
    )


if __name__ == '__main__':
    e = Engine(sys.argv)
    if len(sys.argv) < 2:
        raise AssertionError(
            "Usage: actor-daemon.py platform_file [other parameters]")

    e.load_platform(sys.argv[1])
    Actor.create("worker", Host.by_name("Boivin"), worker)
    Actor.create("daemon", Host.by_name("Tremblay"), my_daemon)

    e.run()
コード例 #10
0
if __name__ == '__main__':
    # Here comes the main function of your program

    # When your program starts, you have to first start a new simulation engine, as follows
    e = Engine(sys.argv)

    # Then you should load a platform file, describing your simulated platform
    e.load_platform("../../platforms/small_platform.xml")

    # And now you have to ask SimGrid to actually start your actors.
    #
    # The easiest way to do so is to implement the behavior of your actor in a single function,
    # as we do here for the receiver actors. This function can take any kind of parameters, as
    # long as the last parameters of Actor::create() match what your function expects.
    Actor.create("receiver", Host.by_name("Fafard"), receiver, "mb42")

    # If your actor is getting more complex, you probably want to implement it as a class instead,
    # as we do here for the sender actors. The main behavior goes into operator()() of the class.
    #
    # You can then directly start your actor, as follows:
    Actor.create("sender1", Host.by_name("Tremblay"), Sender())
    # If you want to pass parameters to your class, that's very easy: just use your constructors
    Actor.create("sender2", Host.by_name("Jupiter"), Sender("GloubiBoulga"))

    # But starting actors directly is considered as a bad experimental habit, since it ties the code
    # you want to test with the experimental scenario. Starting your actors from an external deployment
    # file in XML ensures that you can test your code in several scenarios without changing the code itself.
    #
    # For that, you first need to register your function or your actor as follows.
    e.register_actor("sender", Sender)
コード例 #11
0
ファイル: exec-dvfs.py プロジェクト: soupria/simgrid
        host.pstate = new_pstate

        this_actor.info("Changed power peak={:f}".format(host.speed))

        # Run a second task
        this_actor.execute(workload)

        task_time = Engine.get_clock() - task_time
        this_actor.info("Task2 duration: {:.2f}".format(task_time))

        # Verify that the default pstate is set to 0
        host2 = Host.by_name("MyHost2")
        this_actor.info("Count of Processor states={:d}".format(
            host2.get_pstate_count()))

        this_actor.info("Final power peak={:f}".format(host2.speed))


if __name__ == '__main__':
    e = Engine(sys.argv)
    if len(sys.argv) < 2:
        raise AssertionError(
            "Usage: exec-dvfs.py platform_file [other parameters] (got {:d} params)"
            .format(len(sys.argv)))

    e.load_platform(sys.argv[1])
    Actor.create("dvfs_test", Host.by_name("MyHost1"), Dvfs())
    Actor.create("dvfs_test", Host.by_name("MyHost2"), Dvfs())

    e.run()
コード例 #12
0
        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!")


if __name__ == '__main__':
    e = Engine(sys.argv)

    e.load_platform(sys.argv[1])

    Actor.create("test", Host.by_name("Fafard"), Wizard())

    e.run()
コード例 #13
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()


if __name__ == '__main__':
    e = Engine(sys.argv)
    if len(sys.argv) < 2:
        raise AssertionError(
            "Usage: actor-migration.py platform_file [other parameters]")
    e.load_platform(sys.argv[1])

    Actor.create("monitor", Host.by_name("Boivin"), monitor)
    e.run()
コード例 #14
0
ファイル: io-degradation.py プロジェクト: sthibaul/simgrid
def host():
    # Estimating bw for each disk and considering concurrent flows
    for n in range(1, 15, 2):
        for disk in Host.current().get_disks():
            estimate_bw(disk, n, True)
            estimate_bw(disk, n, False)
コード例 #15
0
    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!")


if __name__ == '__main__':
    e = Engine(sys.argv)
    if len(sys.argv) < 2:
        raise AssertionError(
            "Usage: actor-join.py platform_file [other parameters]")

    e.load_platform(sys.argv[1])

    Actor.create("master", Host.by_name("Tremblay"), master)

    e.run()

    this_actor.info("Simulation time {}".format(Engine.get_clock()))
コード例 #16
0
    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.")


if __name__ == '__main__':
    e = Engine(sys.argv)
    if len(sys.argv) < 2:
        raise AssertionError(
            "Usage: actor-kill.py platform_file [other parameters]")

    e.load_platform(sys.argv[1])     # Load the platform description
    # Create and deploy killer process, that will create the victim actors
    Actor.create("killer", Host.by_name("Tremblay"), killer)

    e.run()
コード例 #17
0
class Canceller:
    """This actor cancels the ongoing execution after a while."""
    def __call__(self):
        computation_amount = this_actor.get_host().speed
        this_actor.info(
            "Canceller executes {:.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 from canceller!")


if __name__ == '__main__':
    e = Engine(sys.argv)
    if len(sys.argv) < 2:
        raise AssertionError(
            "Usage: exec-async.py platform_file [other parameters]")

    e.load_platform(sys.argv[1])

    Actor.create("wait", Host.by_name("Fafard"), Waiter())
    Actor.create("monitor", Host.by_name("Ginette"), Monitor())
    Actor.create("cancel", Host.by_name("Boivin"), Canceller())

    e.run()
コード例 #18
0
ファイル: exec-basic.py プロジェクト: xpertopensource/simgrid
    # execute() tells SimGrid to pause the calling actor until
    # its host has computed the amount of flops passed as a parameter
    this_actor.execute(98095)
    this_actor.info("Done.")
    # This simple example does not do anything beyond that


def privileged():
    # You can also specify the priority of your execution as follows.
    # An execution of priority 2 computes twice as fast as a regular one.
    #
    # So instead of a half/half sharing between the two executions,
    # we get a 1/3 vs 2/3 sharing.
    this_actor.execute(98095, priority=2)
    this_actor.info("Done.")

    # Note that the timings printed when executing this example are a bit misleading,
    # because the uneven sharing only last until the privileged actor ends.
    # After this point, the unprivileged one gets 100% of the CPU and finishes
    # quite quickly.


if __name__ == '__main__':
    e = Engine(sys.argv)
    e.load_platform(sys.argv[1])

    Actor.create("executor", Host.by_name("Tremblay"), executor)
    Actor.create("privileged", Host.by_name("Tremblay"), privileged)

    e.run()