Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / examples / deprecated / java / trace / pingpong / Sender.java
1 /* Copyright (c) 2006-2021. 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 trace.pingpong;
8 import org.simgrid.msg.Host;
9 import org.simgrid.msg.HostNotFoundException;
10 import org.simgrid.msg.Msg;
11 import org.simgrid.msg.MsgException;
12 import org.simgrid.msg.Process;
13 import org.simgrid.msg.Task;
14 import org.simgrid.trace.Trace;
15
16 public class Sender extends Process {
17   private static final double COMM_SIZE_LAT = 1;
18   private static final double COMM_SIZE_BW = 100000000;
19   private static final String PM_STATE = Main.PM_STATE;
20
21   public Sender(String hostname, String name, String[] args) throws HostNotFoundException {
22     super(hostname,name,args);
23   }
24
25   public void main(String[] args) throws MsgException {
26     Msg.info("hello !"); 
27     Trace.hostPushState (getHost().getName(), PM_STATE, "sendingPing");
28
29     int hostCount = args.length;
30     Msg.info("host count: " + hostCount);
31     String[] mailboxes = new String[hostCount]; 
32     double time;
33     double computeDuration = 0;
34     PingPongTask ping;
35
36     for(int pos = 0; pos < args.length ; pos++) {
37       mailboxes[pos] = Host.getByName(args[pos]).getName();
38     }
39
40     for (int pos = 0; pos < hostCount; pos++) { 
41       time = Msg.getClock(); 
42       Msg.info("sender time: " + time);
43       ping = new PingPongTask("no name",computeDuration,COMM_SIZE_LAT);
44       ping.setTime(time);
45       ping.send(mailboxes[pos]);
46
47       Trace.hostPushState (getHost().getName(), PM_STATE, "waitingPong");
48       Task.receive(getHost().getName());
49       double timeGot = Msg.getClock();
50       double timeSent = ping.getTime();
51       double communicationTime;
52
53       Msg.info("Got at time "+ timeGot);
54       Msg.info("Was sent at time "+timeSent);
55       time = timeSent;
56
57       communicationTime=timeGot - time;
58       Msg.info("Communication time : " + communicationTime);
59
60       Msg.info(" --- bw "+ COMM_SIZE_BW/communicationTime + " ----");
61
62       /* Pop the last state (going back to sending ping) */  
63       Trace.hostPopState (getHost().getName(), PM_STATE);
64     }
65
66     /* Pop the sendingPong state */  
67     Trace.hostPopState (getHost().getName(), PM_STATE);
68     Msg.info("goodbye!");
69   }
70 }