|
|
@@ -1,192 +0,0 @@
|
|
|
-include("../Framework/AtomicDEVS.jl")
|
|
|
-include("../Framework/CoupledDEVS.jl")
|
|
|
-include("DelayedAtomic.jl")
|
|
|
-include("Generator.jl")
|
|
|
-include("Topologies.jl")
|
|
|
-
|
|
|
-using Agents
|
|
|
-using ArgParse
|
|
|
-using Profile
|
|
|
-using ProfileView
|
|
|
-using .Atomic, .Coupled, .BaseAtomic, .GeneratorModel, .DEVStoneTopologies
|
|
|
-
|
|
|
-function build_environment(type::Structure, devstone_model::CoupledDEVS, gen_period::Float64, num_outputs::Int)
|
|
|
- env = CoupledDEVS("DEVStoneEnvironment")
|
|
|
- add_submodel!(env, :generator, GeneratorModel.Generator;
|
|
|
- num_outputs = num_outputs, period = gen_period, cycles = 1)
|
|
|
- add_submodel!(env, :devstone, devstone_model)
|
|
|
-
|
|
|
- connect!(env, ModelRef(:generator).o_out, ModelRef(:devstone).i_in)
|
|
|
- if type == HO
|
|
|
- connect!(env, ModelRef(:generator).o_out, ModelRef(:devstone).i_in2)
|
|
|
- end
|
|
|
- return env
|
|
|
-end
|
|
|
-
|
|
|
-function parse_commandline()
|
|
|
- s = ArgParseSettings(description = "Julia DEVS Orchestrator and Benchmarker")
|
|
|
-
|
|
|
- @add_arg_table! s begin
|
|
|
- "--path", "-p"
|
|
|
- help = "Path to the results directory"
|
|
|
- default = "./Results-Julia"
|
|
|
- "--filename", "-f"
|
|
|
- help = "Name of the output file suffix"
|
|
|
- default = ""
|
|
|
- "--append", "-a"
|
|
|
- help = "Append to the output file instead of overwriting."
|
|
|
- action = :store_true
|
|
|
- "--max-depth", "-D"
|
|
|
- help = "Max depth for the generated models"
|
|
|
- arg_type = Int
|
|
|
- default = 8
|
|
|
- "--depth-stepsize"
|
|
|
- help = "Determines for which depths a model is generated."
|
|
|
- arg_type = Int
|
|
|
- default = 0 # Will be mapped to max-depth later if 0
|
|
|
- "--max-width", "-W"
|
|
|
- help = "Max width for the generated models"
|
|
|
- arg_type = Int
|
|
|
- default = 8
|
|
|
- "--width-stepsize"
|
|
|
- help = "Determines for which widths a model is generated."
|
|
|
- arg_type = Int
|
|
|
- default = 0 # Will be mapped to max-width later if 0
|
|
|
- "--repetitions", "-r"
|
|
|
- help = "The number of times a simulation is repeated"
|
|
|
- arg_type = Int
|
|
|
- default = 1
|
|
|
- "--output", "-O"
|
|
|
- help = "Print Simulation Outputs to console"
|
|
|
- action = :store_true
|
|
|
- "--stats", "-S"
|
|
|
- help = "Enable Event Tracking"
|
|
|
- action = :store_true
|
|
|
- "--logging", "-L"
|
|
|
- help = "Enables and print model traces to the console"
|
|
|
- action = :store_true
|
|
|
- "--model-structure", "-m"
|
|
|
- help = "List of structures to run (e.g., LI HI HO)"
|
|
|
- nargs = '*'
|
|
|
- default = ["LI", "HI", "HO"]
|
|
|
- end
|
|
|
-
|
|
|
- return parse_args(s)
|
|
|
-end
|
|
|
-
|
|
|
-# --- Single Simulation Runner ---
|
|
|
-function run_single_simulation(topology_type::Structure, type_str::String, depth::Int, width::Int, stats::Bool, logging::Bool)
|
|
|
- int_delay = 0.0
|
|
|
- ext_delay = 0.0
|
|
|
-
|
|
|
- # Model Creation
|
|
|
- start_time = time()
|
|
|
- devstone_model = build_devstone(topology_type, "DEVStone_$(type_str)", depth, width, int_delay, ext_delay, stats)
|
|
|
- env = build_environment(topology_type, devstone_model, Float64(width), 1)
|
|
|
- model_created_time = time()
|
|
|
-
|
|
|
- # Setup
|
|
|
- AgentUnion = Union{BaseAtomic.DelayedAtomic, GeneratorModel.Generator}
|
|
|
- model = compile_devs(env, AgentUnion, (Atomic.UniversalEvent, ); logging)
|
|
|
- engine_setup_time = time()
|
|
|
-
|
|
|
-# simulate_devs!(warmup)
|
|
|
-# model = compile_devs(env, AgentUnion, (Atomic.UniversalEvent, ); logging=false)
|
|
|
-
|
|
|
-# Profile.clear()
|
|
|
-
|
|
|
- # Simulate
|
|
|
- simulate_devs!(model)
|
|
|
-# @profile simulate_devs!(model)
|
|
|
- sim_time = time()
|
|
|
-# Profile.print(format=:flat, sortedby=:count)
|
|
|
-
|
|
|
- t_creation = model_created_time - start_time
|
|
|
- t_setup = engine_setup_time - model_created_time
|
|
|
- t_sim = sim_time - engine_setup_time
|
|
|
-
|
|
|
- return t_creation, t_setup, t_sim, model
|
|
|
-end
|
|
|
-
|
|
|
-# --- Orchestrator Main ---
|
|
|
-function main()
|
|
|
- args = parse_commandline()
|
|
|
- stats = args["stats"]
|
|
|
- logging = args["logging"]
|
|
|
-
|
|
|
- # Process step sizes
|
|
|
- ds = args["depth-stepsize"] > 0 ? args["depth-stepsize"] : args["max-depth"]
|
|
|
- ws = args["width-stepsize"] > 0 ? args["width-stepsize"] : args["max-width"]
|
|
|
-
|
|
|
- # Setup directories
|
|
|
- time_dir = joinpath(args["path"], "Time", "parallel")
|
|
|
- mkpath(time_dir)
|
|
|
-
|
|
|
- # Convert string inputs to Enum
|
|
|
- struct_map = Dict("LI" => LI, "HI" => HI, "HO" => HO)
|
|
|
-
|
|
|
- for model_str in args["model-structure"]
|
|
|
- if !haskey(struct_map, model_str)
|
|
|
- println("Skipping unknown structure: $model_str")
|
|
|
- continue
|
|
|
- end
|
|
|
- topology_type = struct_map[model_str]
|
|
|
-
|
|
|
- # Construct filename
|
|
|
- suffix = args["filename"] == "" ? "" : "_$(args["filename"])"
|
|
|
- file_path = joinpath(time_dir, "$(model_str)$(suffix).csv")
|
|
|
- file_mode = args["append"] ? "a" : "w"
|
|
|
-
|
|
|
- # Open CSV
|
|
|
- open(file_path, file_mode) do file
|
|
|
- # Write Header if new file
|
|
|
- if !args["append"] || filesize(file_path) == 0
|
|
|
- write(file, "model_type,depth,width,run,creation_time,setup_time,simulation_time\n")
|
|
|
- end
|
|
|
-
|
|
|
- # Grid Search Loop
|
|
|
- repetitions = args["repetitions"]
|
|
|
- for depth in ds:ds:args["max-depth"]
|
|
|
- for width in ws:ws:args["max-width"]
|
|
|
- for run in 0:(repetitions - 1)
|
|
|
- if args["output"]
|
|
|
- println("Running $model_str (D:$depth, W:$width) - Repetition $run...")
|
|
|
- end
|
|
|
-
|
|
|
- # WARM-UP PASS (Only for the very first execution of the script to compile)
|
|
|
- if run == 0 && depth == ds && width == ws && repetitions != 1
|
|
|
- run_single_simulation(topology_type, model_str, 2, 2, false, false)
|
|
|
- end
|
|
|
-
|
|
|
- # Actual measured run
|
|
|
- t_creation, t_setup, t_sim, model = run_single_simulation(topology_type, model_str, depth, width, stats, logging)
|
|
|
-
|
|
|
- # Log to CSV
|
|
|
- write(file, "$model_str,$depth,$width,$run,$t_creation,$t_setup,$t_sim\n")
|
|
|
-
|
|
|
- if args["output"] || args["stats"]
|
|
|
- println(" Creation: $(round(t_creation, digits=4))s | Setup: $(round(t_setup, digits=4))s | Sim: $(round(t_sim, digits=4))s")
|
|
|
- end
|
|
|
- if args["stats"]
|
|
|
- total_int = 0
|
|
|
- total_ext = 0
|
|
|
- for agent in allagents(model)
|
|
|
- if agent isa BaseAtomic.DelayedAtomic
|
|
|
- total_int += agent.int_count
|
|
|
- total_ext += agent.ext_count
|
|
|
- end
|
|
|
- end
|
|
|
- println(" Total internal transitions: $total_int")
|
|
|
- println(" Total external transitions: $total_ext")
|
|
|
- println(" Total Number of Transitions: $(total_int + total_ext)")
|
|
|
- println(" " * "-"^48)
|
|
|
- end
|
|
|
- end
|
|
|
- end
|
|
|
- end
|
|
|
- end
|
|
|
- println("✅ Saved timing results to $file_path")
|
|
|
- end
|
|
|
-end
|
|
|
-
|
|
|
-main()
|