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.
29 protected String name;
31 /** Default constructor (all fields to 0 or null) */
40 * Construct an new task with the specified processing amount and amount
43 * @param name Task's name
45 * @param computeDuration A value of the processing amount (in flop) needed to process the task.
46 * If 0, then it cannot be executed with the execute() method.
47 * This value has to be >= 0.
49 * @param messageSize A value of amount of data (in bytes) needed to transfert this task.
50 * If 0, then it cannot be transfered with the get() and put() methods.
51 * This value has to be >= 0.
53 public Task(String name, double computeDuration, double messageSize) {
54 create(name, computeDuration, messageSize);
57 * Construct an new parallel task with the specified processing amount and amount for each host
60 * @param name The name of the parallel task.
61 * @param hosts The list of hosts implied by the parallel task.
62 * @param computeDurations The amount of operations to be performed by each host of \a hosts.
63 * @param messageSizes A matrix describing the amount of data to exchange between hosts.
65 public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) {
66 parallelCreate(name, hosts, computeDurations, messageSizes);
70 * The natively implemented method to create a MSG task.
72 * @param name The name of th task.
73 * @param computeDuration A value of the processing amount (in flop) needed
74 * to process the task. If 0, then it cannot be executed
75 * with the execute() method. This value has to be >= 0.
76 * @param messageSize A value of amount of data (in bytes) needed to transfert
77 * this task. If 0, then it cannot be transfered this task.
78 * If 0, then it cannot be transfered with the get() and put()
79 * methods. This value has to be >= 0.
80 * @exception IllegalArgumentException if compute duration <0 or message size <0
82 final native void create(String name,
83 double computeDuration,
85 throws IllegalArgumentException;
87 * The natively implemented method to create a MSG parallel task.
89 * @param name The name of the parallel task.
90 * @param hosts The list of hosts implied by the parallel task.
91 * @param computeDurations The total number of operations that have to be performed
93 * @param messageSizes An array of doubles
96 final native void parallelCreate(String name,
98 double[]computeDurations,
100 throws NullPointerException, IllegalArgumentException;
102 * * Getters / Setters * *
105 * Gets the name of a task
107 public String getName() {
111 * Gets the sender of the task
112 * Returns null if the task hasn't been sent yet
114 public native Process getSender();
115 /** Gets the source of the task.
116 * Returns null if the task hasn't been sent yet.
118 public native Host getSource();
119 /** Gets the computing amount of the task
122 public native double getComputeDuration();
123 /** Gets the remaining computation of the task
125 public native double getRemainingDuration();
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 native void setPriority(double priority);
136 * Set the computation amount needed to process the task
137 * @param computationAmount the amount of computation needed to process the task
139 public native void setComputeDuration(double computationAmount);
141 * * Computation-related * *
144 * Executes a task on the location on which the process is running.
147 * @throws HostFailureException
148 * @throws TaskCancelledException
150 public native void execute() throws HostFailureException,TaskCancelledException;
155 public native void cancel();
158 * @exception NativeException if the destruction failed.
160 protected void finalize() throws NativeException {
164 * The natively implemented method to destroy a MSG task.
166 protected native void destroy();
168 * * Communication-related * *
171 /** Send the task asynchronously on the mailbox identified by the specified name,
172 * with no way to retrieve whether the communication succeeded or not
175 public native void dsend(String mailbox);
177 * Sends the task on the mailbox identified by the specified name
180 * @throws TimeoutException
181 * @throws HostFailureException
182 * @throws TransferFailureException
184 public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
189 * Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds)
193 * @exception NativeException if the retrieval fails.
194 * @throws TimeoutException
195 * @throws HostFailureException
196 * @throws TransferFailureException
198 public native void send(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
200 * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate)
204 * @throws TransferFailureException
205 * @throws HostFailureException
206 * @throws TimeoutException
208 public native void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException;
210 * Sends the task on the mailbox asynchronously
212 public native Comm isend(String mailbox);
215 * Starts listening for receiving a task from an asynchronous communication
218 public static native Comm irecv(String mailbox);
220 * Retrieves next task from the mailbox identified by the specified name
225 public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
226 return receive(mailbox, -1.0, null);
230 * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds)
235 public static Task receive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException {
236 return receive(mailbox, timeout, null);
240 * Retrieves next task sent by a given host on the mailbox identified by the specified alias
246 public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
247 return receive(mailbox, -1.0, host);
251 * Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds)
257 public native static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException;
259 * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
261 public native static int listenFrom(String mailbox);
263 * Listen whether there is a waiting task on the mailbox identified by the specified alias
265 public native static boolean listen(String mailbox);
268 * 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.
270 public native static int listenFromHost(String alias, Host host);
273 * Class initializer, to initialize various JNI stuff
275 public static native void nativeInit();