Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
snake_case s4u::Mutex
[simgrid.git] / examples / platforms / cluster_prototype.lua
1 -- Copyright (c) 2011-2018. The SimGrid Team.
2 -- All rights reserved.
3
4 -- This program is free software; you can redistribute it and/or modify it
5 -- under the terms of the license (GNU LGPL) which comes with this package.
6
7   require("simgrid")
8
9   function seq(min,max)
10     L={}
11     for i=min,max,1 do
12       table.insert(L,i)
13     end
14     return L
15   end
16
17   function my_cluster(args)
18     -- args is a table with the following keys
19     --   -
20     local required_args = {"id", "prefix", "suffix", "radical", "speed", "bw", "lat" }
21     for _,val in pairs(required_args) do
22       if args[val] == nil then simgrid.critical("Must specify '" .. val .. "' attribute. See docs for details.") end
23     end
24     if args.sharing_sharing_policy == nil then
25         args.sharing_sharing_policy = "SHARED"
26     end
27     if args.topology ~= "TORUS" and args.topology ~= "FAT_TREE" then
28         args.topology = "Cluster"
29     end
30
31     -- Check the mode = Cluster here
32     return function()
33
34         simgrid.engine.AS_open{id=args.id,mode=args.topology};
35
36         if args.bb_bw ~= nil and args.bb_lat ~= nil then
37           simgrid.engine.backbone_new{id=args.id .. "-bb",bandwidth=args.bb_bw,latency=args.bb_lat,sharing_policy=args.bb_sharing_sharing_policy}
38         end
39         for _,i in pairs(args.radical) do
40             local hostname = args.prefix .. i .. args.suffix
41             local linkname = args.id .."_link_" .. i
42             simgrid.engine.host_new{id=hostname, speed=args.speed,core=args.core,power_trace=args.availability_file,state_trace=args.state_file};
43             simgrid.engine.link_new{id=linkname, bandwidth=args.bw,latency=args.lat, sharing_policy=args.sharing_sharing_policy};
44             simgrid.engine.host_link_new{id=hostname,up=linkname.."_UP",down=linkname.."_DOWN"};
45
46             if args.loopback_bw ~= nil and args.loopback_lat ~= nil then
47               simgrid.engine.link_new{id=linkname .. "_loopback",bandwidth=args.loopback_bw,latency=args.loopback_lat,sharing_policy="FATPIPE"}
48             end
49         end
50         simgrid.engine.AS_seal()
51       end
52   end
53
54   simgrid.engine.open();
55   cluster_factory = my_cluster{prefix="node-", suffix=".acme.org", radical=seq(0,262144), host_factory = function(hostno)
56       if hostno % 2 == 0 then return "blabla" end
57       if hostno % 2 == 1 then return "blublub" end
58     end,
59     speed="1Gf",
60     id="AS0",
61     bw="125MBps",
62     lat="50us",
63     sharing_sharing_policy="SPLITDUPLEX"
64   }()
65   --my_cluster{prefix="node2-", suffix=".acme.org", radical=seq(0,44) }
66
67   simgrid.engine.close();