Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Dig through git history, and update copyright lines.
[simgrid.git] / examples / java / tracing / Sender.java
1 /*
2  * Sender of basic ping/pong example
3  *
4  * Copyright (c) 2006-2013. The SimGrid Team.
5  * All rights reserved.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. 
9  */
10 package tracing;
11 import org.simgrid.msg.Host;
12 import org.simgrid.msg.HostNotFoundException;
13 import org.simgrid.msg.Msg;
14 import org.simgrid.msg.Task;
15 import org.simgrid.msg.MsgException;
16 import org.simgrid.msg.Process;
17 import org.simgrid.trace.Trace;
18
19 public class Sender extends Process {
20         
21                                 private final double commSizeLat = 1;
22                                 private final double commSizeBw = 100000000;
23
24                                 public Sender(Host host, String name, String[] args) {
25                                                                 super(host,name,args);
26                                 }
27                                 
28                                 public void main(String[] args) throws MsgException {
29                                                                 Msg.info("hello !"); 
30                                                                 Trace.hostPushState (host.getName(), "PM_STATE", "sendingPing");
31                                                                 
32                                                                 int hostCount = args.length;
33                                                                 Msg.info("host count: " + hostCount);
34                                                                 String mailboxes[] = new String[hostCount]; 
35                                                                 double time;
36                                                                 double computeDuration = 0;
37                                                                 PingPongTask ping, pong;
38                                                                 
39                                                                 for(int pos = 0; pos < args.length ; pos++) {
40                                                                                                 try {
41                                                                                                                                 mailboxes[pos] = Host.getByName(args[pos]).getName();
42                                                                                                 } catch (HostNotFoundException e) {
43                                                                                                                                 Msg.info("Invalid deployment file: " + e.toString());
44                                                                                                                                 System.exit(1);
45                                                                                                 }
46                                                                 }
47                                                                 
48                                                                 for (int pos = 0; pos < hostCount; pos++) { 
49                                                                                                 time = Msg.getClock(); 
50                                                                                                 Msg.info("sender time: " + time);
51                                                                                                 ping = new PingPongTask("no name",computeDuration,commSizeLat);
52                                                                                                 ping.setTime(time);
53                                                                                                 ping.send(mailboxes[pos]);
54                                                                 
55                                                                                                 Trace.hostPushState (host.getName(), "PM_STATE", "waitingPong");
56                                                                                                 pong = (PingPongTask)Task.receive(getHost().getName());
57                                                                         double timeGot = Msg.getClock();
58                                                                         double timeSent = ping.getTime();
59                                                         double communicationTime=0;
60                                                                         
61                                                                                                 Msg.info("Got at time "+ timeGot);
62                                                                         Msg.info("Was sent at time "+timeSent);
63                                                                         time=timeSent;
64             
65                                                                         communicationTime=timeGot - time;
66                                                                         Msg.info("Communication time : " + communicationTime);
67             
68                                                                         Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
69       
70                                                                                                 /* Pop the last state (going back to sending ping) */   
71                                                                                                 Trace.hostPopState (host.getName(), "PM_STATE");
72
73                                                                 }
74                                                            /* Pop the sendingPong state */      
75                                                                 Trace.hostPopState (host.getName(), "PM_STATE");
76                                                                 Msg.info("goodbye!");
77                                 }
78 }