2 * Copyright 2006-2012 The SimGrid Team.
5 * This program is free software; you can redistribute
6 * it and/or modify it under the terms of the license
7 * (GNU LGPL) which comes with this package.
10 package org.simgrid.msg;
13 * A task is either something to compute somewhere, or something to exchange between two hosts (or both).
14 * It is defined by a computing amount and a message size.
19 * This attribute represents a bind between a java task object and
20 * a native task. Even if this attribute is public you must never
21 * access to it. It is set automatically during the build of the object.
23 private long bind = 0;
27 protected String name;
29 private double messageSize;
31 static private Long idCpt = 0L;
35 /** Default constructor (all fields to 0 or null) */
47 * Construct an new task with the specified processing amount and amount
50 * @param name Task's name
52 * @param computeDuration A value of the processing amount (in flop) needed to process the task.
53 * If 0, then it cannot be executed with the execute() method.
54 * This value has to be >= 0.
56 * @param messageSize A value of amount of data (in bytes) needed to transfert this task.
57 * If 0, then it cannot be transfered with the get() and put() methods.
58 * This value has to be >= 0.
60 public Task(String name, double computeDuration, double messageSize) {
61 create(name, computeDuration, messageSize);
62 this.messageSize = messageSize;
67 * Construct an new parallel task with the specified processing amount and amount for each host
70 * @param name The name of the parallel task.
71 * @param hosts The list of hosts implied by the parallel task.
72 * @param computeDurations The amount of operations to be performed by each host of \a hosts.
73 * @param messageSizes A matrix describing the amount of data to exchange between hosts.
75 public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) {
76 parallelCreate(name, hosts, computeDurations, messageSizes);
80 * The natively implemented method to create a MSG task.
82 * @param name The name of th task.
83 * @param computeDuration A value of the processing amount (in flop) needed
84 * to process the task. If 0, then it cannot be executed
85 * with the execute() method. This value has to be >= 0.
86 * @param messageSize A value of amount of data (in bytes) needed to transfert
87 * this task. If 0, then it cannot be transfered this task.
88 * If 0, then it cannot be transfered with the get() and put()
89 * methods. This value has to be >= 0.
90 * @exception IllegalArgumentException if compute duration <0 or message size <0
92 private final native void create(String name,
93 double computeDuration,
95 throws IllegalArgumentException;
97 * The natively implemented method to create a MSG parallel task.
99 * @param name The name of the parallel task.
100 * @param hosts The list of hosts implied by the parallel task.
101 * @param computeDurations The total number of operations that have to be performed
103 * @param messageSizes An array of doubles
106 private final native void parallelCreate(String name,
108 double[]computeDurations,
109 double[]messageSizes)
110 throws NullPointerException, IllegalArgumentException;
112 * * Getters / Setters * *
115 * Gets the name of a task
117 public String getName() {
121 * Gets the sender of the task
122 * Returns null if the task hasn't been sent yet
124 public native Process getSender();
125 /** Gets the source of the task.
126 * Returns null if the task hasn't been sent yet.
128 public native Host getSource();
129 /** Gets the computing amount of the task
132 public native double getComputeDuration();
133 /** Gets the remaining computation of the task
135 public native double getRemainingDuration();
137 * Sets the name of the task
138 * @param name the new task name.c
140 public native void setName(String name);
142 * This method sets the priority of the computation of the task.
143 * The priority doesn't affect the transfer rate. For example a
144 * priority of 2 will make the task receive two times more cpu than
147 * @param priority The new priority of the task.
149 public native void setPriority(double priority);
151 * Set the computation amount needed to process the task
152 * @param computationAmount the amount of computation needed to process the task
154 public native void setComputeDuration(double computationAmount);
156 * Set the data size of the task
157 * @param dataSize the size of the task
159 public native void setDataSize(double dataSize);
161 * * Computation-related * *
164 * Executes a task on the location on which the process is running.
167 * @throws HostFailureException
168 * @throws TaskCancelledException
170 public native void execute() throws HostFailureException,TaskCancelledException;
172 * Bound a computation to a certain load
175 public native void setBound(double load);
180 public native void cancel();
183 * @exception NativeException if the destruction failed.
185 protected void finalize() throws NativeException {
189 * The natively implemented method to destroy a MSG task.
191 protected native void destroy();
193 * * Communication-related * *
196 /** Send the task asynchronously on the mailbox identified by the specified name,
197 * with no way to retrieve whether the communication succeeded or not
200 public native void dsendBounded(String mailbox, double maxrate);
203 /** Send the task asynchronously on the mailbox identified by the specified name,
204 * with no way to retrieve whether the communication succeeded or not
207 public native void dsend(String mailbox);
210 * Sends the task on the mailbox identified by the specified name
213 * @throws TimeoutException
214 * @throws HostFailureException
215 * @throws TransferFailureException
217 public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
222 * Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds)
226 * @exception NativeException if the retrieval fails.
227 * @throws TimeoutException
228 * @throws HostFailureException
229 * @throws TransferFailureException
231 public native void send(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
233 * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate)
237 * @throws TransferFailureException
238 * @throws HostFailureException
239 * @throws TimeoutException
241 public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException {
242 sendBounded(alias,-1,maxrate);
247 * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate) with a timeout
252 * @throws TransferFailureException
253 * @throws HostFailureException
254 * @throws TimeoutException
256 public native void sendBounded(String alias, double timeout, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException;
260 * Sends the task on the mailbox asynchronously
262 public native Comm isend(String mailbox);
265 * Sends the task on the mailbox asynchronously (capping the sending rate to \a maxrate)
267 public native Comm isendBounded(String mailbox, double maxrate);
271 * Starts listening for receiving a task from an asynchronous communication
274 public static native Comm irecv(String mailbox);
276 * Retrieves next task from the mailbox identified by the specified name
281 public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
282 return receive(mailbox, -1.0, null);
286 * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds)
291 public static Task receive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException {
292 return receive(mailbox, timeout, null);
296 * Retrieves next task sent by a given host on the mailbox identified by the specified alias
302 public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
303 return receive(mailbox, -1.0, host);
307 * Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds)
313 public native static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException;
316 * Starts listening for receiving a task from an asynchronous communication with a capped rate
319 public static native Comm irecvBounded(String mailbox, double rate);
321 * Retrieves next task from the mailbox identified by the specified name with a capped rate
326 public static Task receiveBounded(String mailbox, double rate) throws TransferFailureException, HostFailureException, TimeoutException {
327 return receiveBounded(mailbox, -1.0, null, rate);
331 * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds) with a capped rate
336 public static Task receiveBounded(String mailbox, double timeout, double rate) throws TransferFailureException, HostFailureException, TimeoutException {
337 return receiveBounded(mailbox, timeout, null, rate);
341 * Retrieves next task sent by a given host on the mailbox identified by the specified alias with a capped rate
347 public static Task receiveBounded(String mailbox, Host host, double rate) throws TransferFailureException, HostFailureException, TimeoutException {
348 return receiveBounded(mailbox, -1.0, host, rate);
352 * Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds)
359 public native static Task receiveBounded(String mailbox, double timeout, Host host, double rate) throws TransferFailureException, HostFailureException, TimeoutException;
364 * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
366 public native static int listenFrom(String mailbox);
368 * Listen whether there is a waiting task on the mailbox identified by the specified alias
370 public native static boolean listen(String mailbox);
373 * Counts the number of tasks waiting to be received on the \a mailbox identified by the specified alia and sended by the specified \a host.
375 public native static int listenFromHost(String alias, Host host);
378 * Class initializer, to initialize various JNI stuff
380 public static native void nativeInit();
386 public double getMessageSize() {
387 return this.messageSize;
390 public Long getId() {
394 public void setId(Long id) {