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.
15 * Since most scheduling algorithms rely on a concept of
16 * task that can be either computed locally or transferred
17 * on another processor, it seems to be the right level of
18 * abstraction for our purposes. A task may then be defined
19 * by a computing amount, a message size and some private
20 * data. To transfer a task you use an instance of the class
21 * Channel identified by an number.
23 * @author Abdelmalek Cherier
24 * @author Martin Quinson
30 * This attribute represents a bind between a java task object and
31 * a native task. Even if this attribute is public you must never
32 * access to it. It is set automaticatly during the build of the object.
37 /* Default constructor (disabled) */
43 * Construct an new task with the specified processing amount and amount
46 * @param name Task's name
48 * @param computeDuration A value of the processing amount (in flop) needed to process the task.
49 * If 0, then it cannot be executed with the execute() method.
50 * This value has to be >= 0.
52 * @param messageSize A value of amount of data (in bytes) needed to transfert this task.
53 * If 0, then it cannot be transfered with the get() and put() methods.
54 * This value has to be >= 0.
56 * @exception JniException if the binding mecanism fails.
57 */ public Task(String name, double computeDuration,
58 double messageSize) throws JniException {
59 MsgNative.taskCreate(this, name, computeDuration, messageSize);
62 * Construct an new parallel task with the specified processing amount and amount for each host
65 * @param name The name of the parallel task.
66 * @param hosts The list of hosts implied by the parallel task.
67 * @param computeDurations The amount of operations to be performed by each host of @hosts.
68 * @param messageSizes A matrix describing the amount of data to exchange between hosts.
70 * @exception JniException if the binding mecanism fails.
71 */ public Task(String name, Host[]hosts, double[]computeDurations,
72 double[]messageSizes) throws JniException {
73 MsgNative.parallelTaskCreate(this, name, hosts, computeDurations,
77 * * Getters / Setters * *
79 * This method gets the name of a task.
81 * @return The name of the task.
83 * @exception JniException if the binding mecanism fails.
84 * @exception InvalidTaskException is the specified task is not valid. A task
85 * is invalid if it is not binded with a native task.
86 */ public String getName() throws JniException {
87 return MsgNative.taskGetName(this);
90 * This method gets the sender of the task.
92 * @return The sender of the task.
94 * @exception JniException if the binding mecanism fails.
96 */ Process getSender() throws JniException {
97 return MsgNative.taskGetSender(this);
100 * This method gets the source of the task.
102 * @return The source of the task.
104 * @exception JniException if the binding mecanism fails.
105 */ public Host getSource() throws JniException, NativeException {
106 return MsgNative.taskGetSource(this);
109 * This method gets the computing amount of the task.
111 * @return The computing amount of the task.
113 * @exception JniException if the binding mecanism fails.
114 */ public double getComputeDuration() throws JniException {
115 return MsgNative.taskGetComputeDuration(this);
118 * This method gets the remaining computation.
120 * @return The remaining duration.
122 * @exception JniException if the binding mecanism fails.
123 */ public double getRemainingDuration() throws JniException {
124 return MsgNative.taskGetRemainingDuration(this);
127 * This method sets the priority of the computation of the task.
128 * The priority doesn't affect the transfert rate. For example a
129 * priority of 2 will make the task receive two times more cpu than
132 * @param The new priority of the task.
134 * @exception InvalidTaskException is the specified task is not valid. A task
135 * is invalid if it is not binded with a native task.
136 */ public void setPrirority(double priority) throws JniException {
137 MsgNative.taskSetPriority(this, priority);
140 * * Communication-related * *
142 * Retrieves next task on given channel of local host
144 * @exception JniException if the binding mecanism fails.
145 * @exception NativeException if the retrival fails.
147 public static Task get(int channel) throws JniException, NativeException {
148 return MsgNative.taskGet(channel, -1.0, null);
151 * Retrieves next task on given channel of local host (wait at most #timeout seconds)
153 * @exception JniException if the binding mecanism fails.
154 * @exception NativeException if the retrival fails.
156 public static Task get(int channel, double timeout) throws JniException,
158 return MsgNative.taskGet(channel, timeout, null);
161 * Retrieves next task from given host on given channel of local host
163 * @exception JniException if the binding mecanism fails.
164 * @exception NativeException if the retrival fails.
166 public static Task get(int channel, Host host) throws JniException,
168 return MsgNative.taskGet(channel, -1, host);
171 * Retrieves next task from given host on given channel of local host (wait at most #timeout seconds)
173 * @exception JniException if the binding mecanism fails.
174 * @exception NativeException if the retrival fails.
175 */ public static Task get(int channel, double timeout,
176 Host host) throws JniException, NativeException {
177 return MsgNative.taskGet(channel, timeout, host);
181 * Probes whether there is a waiting task on the given channel of local host
183 * @exception JniException if the binding mecanism fails.
184 * @exception NativeException if the retrival fails.
185 */ public static boolean probe(int channel) throws JniException {
186 return MsgNative.taskProbe(channel);
189 * Counts tasks waiting on the given #channel of local host and sent by given #host
191 * @exception JniException if the binding mecanism fails.
192 */ public static int probe(int channel, Host host) throws JniException {
193 return MsgNative.taskProbeHost(channel, host);
197 * * Computation-related * *
199 * This method execute a task on the location on which the
200 * process is running.
202 * @exception JniException if the binding mecanism fails.
203 * @exception NativeException if the cancelation failed.
204 */ public void execute() throws JniException, NativeException {
205 MsgNative.taskExecute(this);
208 * This method cancels a task.
210 * @exception JniException if the binding mecanism fails.
211 * @exception NativeException if the cancelation failed.
212 */ public void cancel() throws JniException, NativeException {
213 MsgNative.taskCancel(this);
216 * This method deletes a task.
218 * @exception InvalidTaskException is the specified task is not valid. A task
219 * is invalid if it is not binded with a native task.
220 * MsgException if the destruction failed.
221 */ protected void finalize() throws JniException, NativeException {
223 MsgNative.taskDestroy(this);
227 * Send the task on the mailbox identified by the default alias (defaultAlias = "currentHostName:CurrentProcessName")
229 * @exception JniException if the binding mecanism fails.
230 * @exception NativeException if the retrival fails.
232 public void send() throws JniException,NativeException {
234 String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
236 MsgNative.taskSend(alias, this, -1);
240 * Send the task on the mailbox identified by the specified alias
242 * @exception JniException if the binding mecanism fails.
243 * @exception NativeException if the retrival fails.
245 public void send(String alias) throws JniException,NativeException {
246 MsgNative.taskSend(alias, this, -1);
250 * Send the task on the mailbox identified by the default alias (wait at most #timeout seconds)
252 * @exception JniException if the binding mecanism fails.
253 * @exception NativeException if the retrival fails.
255 public void send(double timeout) throws JniException,NativeException {
256 String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
257 MsgNative.taskSend(alias, this, timeout);
261 * Send the task on the mailbox identified by the specified alias (wait at most #timeout seconds)
263 * @exception JniException if the binding mecanism fails.
264 * @exception NativeException if the retrival fails.
266 public void send(String alias, double timeout) throws JniException,NativeException {
267 MsgNative.taskSend(alias, this, timeout);
272 * Send the task on the mailbox identified by the default alias (capping the emision rate to #maxrate)
274 * @exception JniException if the binding mecanism fails.
275 * @exception NativeException if the retrival fails.
277 public void sendBounded(double maxrate) throws JniException,NativeException {
278 String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
279 MsgNative.taskSendBounded(alias, this, maxrate);
283 * Send the task on the mailbox identified by the specified alias (capping the emision rate to #maxrate)
285 * @exception JniException if the binding mecanism fails.
286 * @exception NativeException if the retrival fails.
288 public void sendBounded(String alias, double maxrate) throws JniException,NativeException {
289 MsgNative.taskSendBounded(alias, this, maxrate);
293 * Retrieves next task from the mailbox identified by the default alias (defaultAlias = "currentHostName:CurrentProcessName")
295 * @exception JniException if the binding mecanism fails.
296 * @exception NativeException if the retrival fails.
298 public static Task receive() throws JniException, NativeException {
299 String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
300 return MsgNative.taskReceive(alias, -1.0, null);
304 * Retrieves next task from the mailbox identified by the specified alias
306 * @exception JniException if the binding mecanism fails.
307 * @exception NativeException if the retrival fails.
310 public static Task receive(String alias) throws JniException, NativeException {
311 return MsgNative.taskReceive(alias, -1.0, null);
315 * Retrieves next task on the mailbox identified by the specified alias (wait at most #timeout seconds)
317 * @exception JniException if the binding mecanism fails.
318 * @exception NativeException if the retrival fails.
320 public static Task receive(String alias, double timeout) throws JniException, NativeException {
321 return MsgNative.taskReceive(alias, timeout, null);
325 * Retrieves next task sended by a given host on the mailbox identified by the specified alias
327 * @exception JniException if the binding mecanism fails.
328 * @exception NativeException if the retrival fails.
331 public static Task receive(String alias, Host host) throws JniException, NativeException {
332 return MsgNative.taskReceive(alias, -1.0, host);
336 * Retrieves next task sended by a given host on the mailbox identified by the specified alias (wait at most #timeout seconds)
338 * @exception JniException if the binding mecanism fails.
339 * @exception NativeException if the retrival fails.
341 public static Task receive(String alias, double timeout, Host host) throws JniException, NativeException {
342 return MsgNative.taskReceive(alias, timeout, host);
346 * Listen whether there is a waiting task on the mailbox identified by the default alias of local host
348 * @exception JniException if the binding mecanism fails.
349 * @exception NativeException if the retrival fails.
351 public static boolean listen() throws JniException, NativeException {
352 String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
354 return MsgNative.taskListen(alias);
358 * Test whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
360 * @exception JniException if the binding mecanism fails.
361 * @exception NativeException if the retrival fails.
363 public static int listenFrom(String alias) throws JniException, NativeException {
364 return MsgNative.taskListenFrom(alias);
368 * Test whether there is a pending communication on the mailbox identified by the default alias, of the current host, and who sent it
370 * @exception JniException if the binding mecanism fails.
371 * @exception NativeException if the retrival fails.
373 public static int listenFrom() throws JniException, NativeException {
374 String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
376 return MsgNative.taskListenFrom(alias);
380 * Listen whether there is a waiting task on the mailbox identified by the specified alias
382 * @exception JniException if the binding mecanism fails.
383 * @exception NativeException if the retrival fails.
385 public static boolean listen(String alias) throws JniException, NativeException {
386 return MsgNative.taskListen(alias);
390 * Counts the number of tasks waiting to be received on the #mailbox identified by the specified alias and sended by the current host.
392 * @exception JniException if the binding mecanism fails.
393 * @exception NativeException if the retrival fails.
395 public static int listenFromHost(Host host) throws JniException, NativeException {
396 String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
397 return MsgNative.taskListenFromHost(alias,host);
401 * Counts the number of tasks waiting to be received on the #mailbox identified by the specified alia and sended by the specified #host.
403 * @exception JniException if the binding mecanism fails.
404 * @exception NativeException if the retrival fails.
406 public static int listenFromHost(String alias, Host host) throws JniException, NativeException {
407 return MsgNative.taskListenFromHost(alias, host);