Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1128e75979c37ecd886dbf9baf68e47a4d22d0e8
[simgrid.git] / examples / java / cloud / energy / Test.java
1 /* Copyright (c) 2014. 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 //package cloud.energy;
8
9 import org.simgrid.msg.*;
10 import org.simgrid.msg.Process;
11
12 public class Test extends Process{
13
14
15     public class DummyProcess extends Process {
16                 public  DummyProcess (Host host, String name) {
17                super(host, name); 
18            }
19
20            public void main(String[] args) {            
21               Task  task = new Task(this.getHost().getName()+"-task", 30E6 , 0);
22               try {
23                   task.execute();   
24               } catch (Exception e) {
25                   e.printStackTrace();
26               } 
27               //task.finalize();
28               Msg.info("This worker is done."); 
29            }
30         }      
31  
32     Test(Host host, String name, String[] args) throws HostNotFoundException, NativeException  {
33         super(host, name, args);
34     }
35
36     public void main(String[] strings) throws MsgException {
37
38        double startTime = 0;
39        double endTime = 0;
40
41        /* get hosts */
42         Host host1 = null;
43         Host host2 = null;
44         Host host3 = null;
45
46         try {
47             host1 = Host.getByName("MyHost1");
48             host2 = Host.getByName("MyHost2");
49             host3 = Host.getByName("MyHost3");
50         } catch (HostNotFoundException e) {
51             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
52         }
53
54
55       /* Host 1*/
56                   Msg.info("Creating and starting two VMs");
57         VM vmHost1 = null;
58         vmHost1 = new VM(
59                 host1,
60                 "vmHost1",
61                 4, // Nb of vcpu
62                 2048, // Ramsize,
63                 100, // Net Bandwidth
64                 null, //VM disk image
65                 1024 * 20,   //size of disk image,
66                 10, // Net bandwidth,
67                 50 // Memory intensity
68         );
69         vmHost1.start();
70
71                   VM vmHost3 = null;
72         vmHost3 = new VM(
73                 host3,
74                 "vmHost3",
75                 4, // Nb of vcpu
76                 2048, // Ramsize,
77                 100, // Net Bandwidth
78                 null, //VM disk image
79                 1024 * 20,   //size of disk image,
80                 10, // Net bandwidth,
81                 50 // Memory intensity
82         );
83         vmHost3.start();
84
85         Msg.info("Create two tasks on Host1: one inside a VM, the other directly on the host");
86                   DummyProcess p11 = new DummyProcess (vmHost1, "p11"); 
87         p11.run(); 
88                   DummyProcess p12 = new DummyProcess (host1, "p12"); 
89         p12.run(); 
90    
91         Msg.info("Create two tasks on Host2: both directly on the host");
92                   DummyProcess p21 = new DummyProcess (host2, "p21"); 
93         p21.run(); 
94                   DummyProcess p22 = new DummyProcess (host2, "p22"); 
95         p22.run(); 
96  
97         Msg.info("Create two tasks on Host3: both inside a VM");
98                   DummyProcess p31 = new DummyProcess (vmHost3, "p31"); 
99         p31.run(); 
100                   DummyProcess p32 = new DummyProcess (vmHost3, "p312"); 
101         p32.run(); 
102   
103         Msg.info("Wait 5 seconde. The tasks are still runing (they run for 3 secondes, but 2 tasks are co-located, so they run for 6 seconds)"); 
104         Process.sleep(5); 
105         Msg.info("Wait another 5 seconds. The tasks stop at some point in between"); 
106         Process.sleep(5); 
107
108         vmHost1.shutdown(); 
109         vmHost3.shutdown(); 
110      }
111 }