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 static final double commSizeLat = 1;
19 private static final double commSizeBw = 100000000;
20 private static final String PM_STATE = "PM_STATE";
22 public Sender(String hostname, String name, String[] args) throws HostNotFoundException, NativeException {
23 super(hostname,name,args);
26 public void main(String[] args) throws MsgException {
28 Trace.hostPushState (getHost().getName(), PM_STATE, "sendingPing");
30 int hostCount = args.length;
31 Msg.info("host count: " + hostCount);
32 String[] mailboxes = new String[hostCount];
34 double computeDuration = 0;
37 for(int pos = 0; pos < args.length ; pos++) {
38 mailboxes[pos] = Host.getByName(args[pos]).getName();
41 for (int pos = 0; pos < hostCount; pos++) {
42 time = Msg.getClock();
43 Msg.info("sender time: " + time);
44 ping = new PingPongTask("no name",computeDuration,commSizeLat);
46 ping.send(mailboxes[pos]);
48 Trace.hostPushState (getHost().getName(), PM_STATE, "waitingPong");
49 Task.receive(getHost().getName());
50 double timeGot = Msg.getClock();
51 double timeSent = ping.getTime();
52 double communicationTime;
54 Msg.info("Got at time "+ timeGot);
55 Msg.info("Was sent at time "+timeSent);
58 communicationTime=timeGot - time;
59 Msg.info("Communication time : " + communicationTime);
61 Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
63 /* Pop the last state (going back to sending ping) */
64 Trace.hostPopState (getHost().getName(), PM_STATE);
67 /* Pop the sendingPong state */
68 Trace.hostPopState (getHost().getName(), PM_STATE);