2 * Sender of basic ping/pong example
4 * Copyright (c) 2006-2013. The SimGrid Team.
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.
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;
19 public class Sender extends Process {
21 private final double commSizeLat = 1;
22 private final double commSizeBw = 100000000;
24 public Sender(Host host, String name, String[] args) {
25 super(host,name,args);
28 public void main(String[] args) throws MsgException {
30 Trace.hostPushState (host.getName(), "PM_STATE", "sendingPing");
32 int hostCount = args.length;
33 Msg.info("host count: " + hostCount);
34 String mailboxes[] = new String[hostCount];
36 double computeDuration = 0;
37 PingPongTask ping, pong;
39 for(int pos = 0; pos < args.length ; pos++) {
41 mailboxes[pos] = Host.getByName(args[pos]).getName();
42 } catch (HostNotFoundException e) {
43 Msg.info("Invalid deployment file: " + e.toString());
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);
53 ping.send(mailboxes[pos]);
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;
61 Msg.info("Got at time "+ timeGot);
62 Msg.info("Was sent at time "+timeSent);
65 communicationTime=timeGot - time;
66 Msg.info("Communication time : " + communicationTime);
68 Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
70 /* Pop the last state (going back to sending ping) */
71 Trace.hostPopState (host.getName(), "PM_STATE");
74 /* Pop the sendingPong state */
75 Trace.hostPopState (host.getName(), "PM_STATE");