1 /* Copyright (c) 2016. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
7 import org.simgrid.msg.Host;
8 import org.simgrid.msg.Msg;
9 import org.simgrid.msg.MsgException;
10 import org.simgrid.msg.Process;
11 import org.simgrid.msg.Task;
13 public class RelayRunner extends Process {
15 private static final int TASK_COMM_SIZE = 1000000; /* The token is 1MB long*/
17 public RelayRunner(Host host, String name, String[]args) {
18 super(host,name,args);
21 /* This is the function executed by this kind of processes */
23 public void main(String[] args) throws MsgException {
24 // In this example, the processes are given numerical names: "0", "1", "2", and so on
25 int rank = Integer.parseInt(this.getName());
28 /* The root (rank 0) first sends the token then waits to receive it back */
31 Task token = new Task("Token", 0/* no computation associated*/ , TASK_COMM_SIZE );
33 Msg.info("Host '"+rank+"' send '"+token.getName()+"' to Host '"+mailbox+"'");
36 token = Task.receive(this.getName()); // Get a message from the mailbox having the same name as the current processor
38 Msg.info("Host '"+rank+"' received '"+token.getName()+"'");
41 /* The others processes receive on their name (coming from their left neighbor -- rank-1)
42 * and send to their right neighbor (rank+1) */
43 Task token = Task.receive(this.getName());
45 Msg.info("Host '"+rank+"' received '"+token.getName()+"'");
47 String mailbox = Integer.toString(rank+1);
48 if (rank+1 == Host.getCount()) {
49 /* The last process has no right neighbor, so it sends the token back to rank 0 */
53 Msg.info("Host '"+rank+"' send '"+token.getName()+"' to Host '"+mailbox+"'");