1 /* Copyright (c) 2006-2014, 2016. The SimGrid Team.
2 * All rights reserved. */
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. */
7 package trace.pingpong;
8 import org.simgrid.msg.Msg;
9 import org.simgrid.msg.Host;
10 import org.simgrid.msg.Task;
11 import org.simgrid.msg.Process;
12 import org.simgrid.msg.MsgException;
13 import org.simgrid.msg.NativeException;
14 import org.simgrid.msg.HostNotFoundException;
15 import org.simgrid.trace.Trace;
17 public class Sender extends Process {
18 private final double commSizeLat = 1;
19 private final double commSizeBw = 100000000;
21 public Sender(String hostname, String name, String[] args) throws HostNotFoundException, NativeException {
22 super(hostname,name,args);
25 public void main(String[] args) throws MsgException {
27 Trace.hostPushState (getHost().getName(), "PM_STATE", "sendingPing");
29 int hostCount = args.length;
30 Msg.info("host count: " + hostCount);
31 String mailboxes[] = new String[hostCount];
33 double computeDuration = 0;
34 PingPongTask ping, pong;
36 for(int pos = 0; pos < args.length ; pos++) {
38 mailboxes[pos] = Host.getByName(args[pos]).getName();
39 } catch (HostNotFoundException e) {
40 Msg.info("Invalid deployment file: " + e.toString());
45 for (int pos = 0; pos < hostCount; pos++) {
46 time = Msg.getClock();
47 Msg.info("sender time: " + time);
48 ping = new PingPongTask("no name",computeDuration,commSizeLat);
50 ping.send(mailboxes[pos]);
52 Trace.hostPushState (getHost().getName(), "PM_STATE", "waitingPong");
53 pong = (PingPongTask)Task.receive(getHost().getName());
54 double timeGot = Msg.getClock();
55 double timeSent = ping.getTime();
56 double communicationTime=0;
58 Msg.info("Got at time "+ timeGot);
59 Msg.info("Was sent at time "+timeSent);
62 communicationTime=timeGot - time;
63 Msg.info("Communication time : " + communicationTime);
65 Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
67 /* Pop the last state (going back to sending ping) */
68 Trace.hostPopState (getHost().getName(), "PM_STATE");
71 /* Pop the sendingPong state */
72 Trace.hostPopState (getHost().getName(), "PM_STATE");