1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
/* Copyright (c) 2010-2025. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/* This example shows how to simulate variability for CPUs, using multiplicative factors */
import org.simgrid.s4u.*;
/* *********************************************************************************************** */
class runner extends Actor {
public void run()
{
double computation_amount = this.get_host().get_speed();
Engine.info("Executing 1 tasks of %.0f flops, should take 1 second.", computation_amount);
this.execute(computation_amount);
Engine.info("Executing 1 tasks of %f flops, it would take .001s without factor. It'll take .002s",
computation_amount / 10);
this.execute(computation_amount / 1000);
Engine.info("Finished executing. Goodbye now!");
}
}
/*************************************************************************************************/
public class exec_cpu_factors {
public static void main(String[] args)
{
Engine e = new Engine(args);
/* create platform */
NetZone zone = e.get_netzone_root();
Host runner_host = zone.add_host("runner", 1e6);
runner_host.set_cpu_factor_cb(new CallbackDHostDouble() {
/* Variability for CPU */
@Override public double run(Host host, double flops)
{
/* creates variability for tasks smaller than 1% of CPU power.
* unrealistic, for learning purposes */
double factor = (flops < host.get_speed() / 100) ? 0.5 : 1.0;
Engine.info("Host %s, task with %f flops, new factor %f", host.get_name(), flops, factor);
return factor;
}
});
zone.seal();
/* create actor runner */
runner_host.add_actor("runner", new runner());
/* runs the simulation */
e.run();
// The following call is useless in your code, but our continuous integration uses it to track memleaks
e.force_garbage_collection();
}
}
|