2 * Sender of basic ping/pong example
4 * Copyright 2006-2012 The SimGrid Team. All rights reserved.
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.
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;
18 public class Sender extends Process {
20 private final double commSizeLat = 1;
21 private final double commSizeBw = 100000000;
23 public Sender(Host host, String name, String[] args) {
24 super(host,name,args);
27 public void main(String[] args) throws MsgException {
29 Trace.hostPushState (host.getName(), "PM_STATE", "sendingPing");
31 int hostCount = args.length;
32 Msg.info("host count: " + hostCount);
33 String mailboxes[] = new String[hostCount];
35 double computeDuration = 0;
36 PingPongTask ping, pong;
38 for(int pos = 0; pos < args.length ; pos++) {
40 mailboxes[pos] = Host.getByName(args[pos]).getName();
41 } catch (HostNotFoundException e) {
42 Msg.info("Invalid deployment file: " + e.toString());
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);
52 ping.send(mailboxes[pos]);
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;
60 Msg.info("Got at time "+ timeGot);
61 Msg.info("Was sent at time "+timeSent);
64 communicationTime=timeGot - time;
65 Msg.info("Communication time : " + communicationTime);
67 Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
69 /* Pop the last state (going back to sending ping) */
70 Trace.hostPopState (host.getName(), "PM_STATE");
73 /* Pop the sendingPong state */
74 Trace.hostPopState (host.getName(), "PM_STATE");