2 * simgrid.msg.Task.java 1.00 07/05/01
4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
7 * This program is free software; you can redistribute
8 * it and/or modify it under the terms of the license
9 *(GNU LGPL) which comes with this package.
12 package org.simgrid.msg;
15 * A task is either something to compute somewhere, or something to exchange between two hosts (or both).
16 * It is defined by a computing amount and a message size.
21 * This attribute represents a bind between a java task object and
22 * a native task. Even if this attribute is public you must never
23 * access to it. It is set automatically during the build of the object.
28 /** Default constructor (all fields to 0 or null) */
37 * Construct an new task with the specified processing amount and amount
40 * @param name Task's name
42 * @param computeDuration A value of the processing amount (in flop) needed to process the task.
43 * If 0, then it cannot be executed with the execute() method.
44 * This value has to be >= 0.
46 * @param messageSize A value of amount of data (in bytes) needed to transfert this task.
47 * If 0, then it cannot be transfered with the get() and put() methods.
48 * This value has to be >= 0.
50 public Task(String name, double computeDuration, double messageSize) {
51 create(name, computeDuration, messageSize);
54 * Construct an new parallel task with the specified processing amount and amount for each host
57 * @param name The name of the parallel task.
58 * @param hosts The list of hosts implied by the parallel task.
59 * @param computeDurations The amount of operations to be performed by each host of \a hosts.
60 * @param messageSizes A matrix describing the amount of data to exchange between hosts.
62 public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) {
63 parallelCreate(name, hosts, computeDurations, messageSizes);
67 * The natively implemented method to create a MSG task.
69 * @param name The name of th task.
70 * @param computeDuration A value of the processing amount (in flop) needed
71 * to process the task. If 0, then it cannot be executed
72 * with the execute() method. This value has to be >= 0.
73 * @param messageSize A value of amount of data (in bytes) needed to transfert
74 * this task. If 0, then it cannot be transfered this task.
75 * If 0, then it cannot be transfered with the get() and put()
76 * methods. This value has to be >= 0.
77 * @exception IllegalArgumentException if compute duration <0 or message size <0
79 final native void create(String name,
80 double computeDuration,
82 throws IllegalArgumentException;
84 * The natively implemented method to create a MSG parallel task.
86 * @param name The name of the parallel task.
87 * @param hosts The list of hosts implied by the parallel task.
88 * @param computeDurations The total number of operations that have to be performed
90 * @param messageSizes An array of doubles
93 final native void parallelCreate(String name,
95 double[]computeDurations,
97 throws NullPointerException, IllegalArgumentException;
99 * * Getters / Setters * *
101 /** Gets the name of a task
105 public native String getName();
106 /** Gets the sender of the task */
107 public native Process getSender();
108 /** Gets the source of the task
111 public Host getSource() {
112 return MsgNative.taskGetSource(this);
114 /** Gets the computing amount of the task
117 public double getComputeDuration() {
118 return MsgNative.taskGetComputeDuration(this);
120 /** Gets the remaining computation of the task
123 public double getRemainingDuration() {
124 return MsgNative.taskGetRemainingDuration(this);
127 * This method sets the priority of the computation of the task.
128 * The priority doesn't affect the transfer rate. For example a
129 * priority of 2 will make the task receive two times more cpu than
132 * @param priority The new priority of the task.
134 public void setPriority(double priority) {
135 MsgNative.taskSetPriority(this, priority);
138 * * Communication-related * *
143 * * Computation-related * *
146 * Executes a task on the location on which the process is running.
149 * @throws HostFailureException
150 * @throws TaskCancelledException
152 public void execute() throws HostFailureException,TaskCancelledException {
153 MsgNative.taskExecute(this);
159 public void cancel() {
160 MsgNative.taskCancel(this);
164 * @exception NativeException if the destruction failed.
166 protected void finalize() throws NativeException {
170 * The natively implemented method to destroy a MSG task.
172 protected native void destroy();
174 /** Send the task asynchronously on the mailbox identified by the specified name,
175 * with no way to retrieve whether the communication succeeded or not
178 public native void dsend(String mailbox);
180 * Sends the task on the mailbox identified by the specified name
183 * @throws TimeoutException
184 * @throws HostFailureException
185 * @throws TransferFailureException
187 public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
188 MsgNative.taskSend(mailbox, this, -1);
192 * Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds)
196 * @exception NativeException if the retrieval fails.
197 * @throws TimeoutException
198 * @throws HostFailureException
199 * @throws TransferFailureException
201 public void send(String mailbox, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
202 MsgNative.taskSend(mailbox, this, timeout);
206 * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate)
210 * @throws TransferFailureException
211 * @throws HostFailureException
212 * @throws TimeoutException
214 public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException {
215 MsgNative.taskSendBounded(alias, this, maxrate);
218 * Sends the task on the mailbox asynchronously
220 public native Comm isend(String mailbox);
223 * Starts listening for receiving a task from an asynchronous communication
227 public static native Comm irecv(String mailbox);
229 * Retrieves next task from the mailbox identified by the specified name
233 * @throws TransferFailureException
234 * @throws HostFailureException
235 * @throws TimeoutException
238 public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
239 return MsgNative.taskReceive(mailbox, -1.0, null);
243 * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds)
248 * @throws TransferFailureException
249 * @throws HostFailureException
250 * @throws TimeoutException
252 public static Task receive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException {
253 return MsgNative.taskReceive(mailbox, timeout, null);
257 * Retrieves next task sent by a given host on the mailbox identified by the specified alias
262 * @throws TransferFailureException
263 * @throws TimeoutException
264 * @throws HostFailureException
267 public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
268 return MsgNative.taskReceive(mailbox, -1.0, host);
272 * Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds)
278 * @throws TransferFailureException
279 * @throws HostFailureException
280 * @throws TimeoutException
282 public static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
283 return MsgNative.taskReceive(mailbox, timeout, host);
287 * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
289 public native static int listenFrom(String mailbox);
291 * Listen whether there is a waiting task on the mailbox identified by the specified alias
293 public native static boolean listen(String mailbox);
296 * 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.
298 public native static int listenFromHost(String alias, Host host);
301 * Class initializer, to initialize various JNI stuff
303 public static native void nativeInit();