1 /* Copyright (c) 2006-2014, 2016-2017. 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.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;
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;
21 public Sender(String hostname, String name, String[] args) throws HostNotFoundException {
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;
36 for(int pos = 0; pos < args.length ; pos++) {
37 mailboxes[pos] = Host.getByName(args[pos]).getName();
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);
45 ping.send(mailboxes[pos]);
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;
53 Msg.info("Got at time "+ timeGot);
54 Msg.info("Was sent at time "+timeSent);
57 communicationTime=timeGot - time;
58 Msg.info("Communication time : " + communicationTime);
60 Msg.info(" --- bw "+ COMM_SIZE_BW/communicationTime + " ----");
62 /* Pop the last state (going back to sending ping) */
63 Trace.hostPopState (getHost().getName(), PM_STATE);
66 /* Pop the sendingPong state */
67 Trace.hostPopState (getHost().getName(), PM_STATE);