Logo AND Algorithmique Numérique Distribuée

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