1 /* Copyright (c) 2006-2007, 2012-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.HostNotFoundException;
9 import org.simgrid.msg.Msg;
10 import org.simgrid.msg.MsgException;
11 import org.simgrid.msg.Process;
12 import org.simgrid.msg.Task;
13 import org.simgrid.trace.Trace;
15 public class Receiver extends Process {
16 private static final double COMM_SIZE_LAT = 1;
17 private static final double COMM_SIZE_BW = 100000000;
18 private static final String PM_STATE = Main.PM_STATE;
20 public Receiver(String hostname, String name, String[]args) throws HostNotFoundException {
21 super(hostname,name,args);
24 public void main(String[] args) throws MsgException {
26 Trace.hostPushState (getHost().getName(), PM_STATE, "waitingPing");
28 /* Wait for the ping */
29 Msg.info("try to get a task");
31 PingPongTask ping = (PingPongTask)Task.receive(getHost().getName());
32 double timeGot = Msg.getClock();
33 double timeSent = ping.getTime();
35 Msg.info("Got at time "+ timeGot);
36 Msg.info("Was sent at time "+timeSent);
39 double communicationTime=timeGot - time;
40 Msg.info("Communication time : " + communicationTime);
42 Msg.info(" --- bw "+ COMM_SIZE_BW/communicationTime + " ----");
45 Trace.hostPushState (getHost().getName(), PM_STATE, "sendingPong");
46 double computeDuration = 0;
47 PingPongTask pong = new PingPongTask("no name",computeDuration,COMM_SIZE_LAT);
49 pong.send(ping.getSource().getName());
51 /* Pop the two states */
52 Trace.hostPopState (getHost().getName(), PM_STATE);
53 Trace.hostPopState (getHost().getName(), PM_STATE);