/** Default constructor (all fields to 0 or null) */
public Task() {
- MsgNative.taskCreate(this, null, 0, 0);
+ create(null, 0, 0);
}
+
/* * * *
* * Constructors * *
* * * */
* This value has to be >= 0.
*/
public Task(String name, double computeDuration, double messageSize) {
- MsgNative.taskCreate(this, name, computeDuration, messageSize);
+ create(name, computeDuration, messageSize);
}
/**
* Construct an new parallel task with the specified processing amount and amount for each host
* @param messageSizes A matrix describing the amount of data to exchange between hosts.
*/
public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) {
- MsgNative.parallelTaskCreate(this, name, hosts, computeDurations, messageSizes);
+ parallelCreate(name, hosts, computeDurations, messageSizes);
}
+
+ /**
+ * The natively implemented method to create a MSG task.
+ *
+ * @param name The name of th task.
+ * @param computeDuration A value of the processing amount (in flop) needed
+ * to process the task. If 0, then it cannot be executed
+ * with the execute() method. This value has to be >= 0.
+ * @param messageSize A value of amount of data (in bytes) needed to transfert
+ * this task. If 0, then it cannot be transfered this task.
+ * If 0, then it cannot be transfered with the get() and put()
+ * methods. This value has to be >= 0.
+ * @exception IllegalArgumentException if compute duration <0 or message size <0
+ */
+ final native void create(String name,
+ double computeDuration,
+ double messageSize)
+ throws IllegalArgumentException;
+ /**
+ * The natively implemented method to create a MSG parallel task.
+ *
+ * @param name The name of the parallel task.
+ * @param hosts The list of hosts implied by the parallel task.
+ * @param computeDurations The total number of operations that have to be performed
+ * on the hosts.
+ * @param messageSizes An array of doubles
+ *
+ */
+ final native void parallelCreate(String name,
+ Host[]hosts,
+ double[]computeDurations,
+ double[]messageSizes)
+ throws NullPointerException, IllegalArgumentException;
/* * * *
* * Getters / Setters * *
* * * */
- /** Gets the name of a task */
- public String getName() {
- return MsgNative.taskGetName(this);
- }
- /** Gets the sender of the task */
- Process getSender() {
- return MsgNative.taskGetSender(this);
- }
- /** Gets the source of the task */
- public Host getSource() {
- return MsgNative.taskGetSource(this);
- }
- /** Gets the computing amount of the task */
- public double getComputeDuration() {
- return MsgNative.taskGetComputeDuration(this);
- }
- /** Gets the remaining computation of the task */
- public double getRemainingDuration() {
- return MsgNative.taskGetRemainingDuration(this);
- }
+ /** Gets the name of a task
+ * FIXME: Cache it.
+ * @return
+ */
+ public native String getName();
+ /** Gets the sender of the task */
+ //FIXME: Don't crash when the task has just been created.
+ public native Process getSender();
+ /** Gets the source of the task
+ * FIXME: Not defensive enough, can crash.
+ */
+ public native Host getSource();
+ /** Gets the computing amount of the task
+ * FIXME: Cache it !
+ */
+ public native double getComputeDuration();
+ /** Gets the remaining computation of the task
+ */
+ public native double getRemainingDuration();
/**
* This method sets the priority of the computation of the task.
- * The priority doesn't affect the transfert rate. For example a
+ * The priority doesn't affect the transfer rate. For example a
* priority of 2 will make the task receive two times more cpu than
* the other ones.
*
* @param priority The new priority of the task.
*/
- public void setPriority(double priority) {
- MsgNative.taskSetPriority(this, priority);
- }
+ public native void setPriority(double priority);
/* * * *
* * Communication-related * *
* * * */
/**
* Executes a task on the location on which the process is running.
*
- * @exception HostFailureException,TaskCancelledException
- */
- public void execute() throws HostFailureException,TaskCancelledException {
- MsgNative.taskExecute(this);
- }
+ *
+ * @throws HostFailureException
+ * @throws TaskCancelledException
+ */
+ public native void execute() throws HostFailureException,TaskCancelledException;
/**
* Cancels a task.
*
- * @exception NativeException if the cancellation failed.
*/
- public void cancel() {
- MsgNative.taskCancel(this);
- }
+ public native void cancel();
/** Deletes a task.
*
* @exception NativeException if the destruction failed.
*/
protected void finalize() throws NativeException {
- if (this.bind != 0)
- MsgNative.taskDestroy(this);
+ destroy();
}
+ /**
+ * The natively implemented method to destroy a MSG task.
+ */
+ protected native void destroy();
+ /** Send the task asynchronously on the mailbox identified by the specified name,
+ * with no way to retrieve whether the communication succeeded or not
+ *
+ */
+ public native void dsend(String mailbox);
/**
* Sends the task on the mailbox identified by the specified name
*
- * @throws TimeoutException
+ * @param mailbox
+ * @throws TimeoutException
* @throws HostFailureException
* @throws TransferFailureException
*/
public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
- MsgNative.taskSend(mailbox, this, -1);
+ send(mailbox, -1);
}
/**
* Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds)
*
- * @exception NativeException if the retrieval fails.
+ * @param mailbox
+ * @param timeout
+ * @exception NativeException if the retrieval fails.
* @throws TimeoutException
* @throws HostFailureException
* @throws TransferFailureException
*/
- public void send(String mailbox, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
- MsgNative.taskSend(mailbox, this, timeout);
- }
-
+ public native void send(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
/**
* Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate)
*
- * @exception TransferFailureException, HostFailureException, TimeoutException.
+ * @param alias
+ * @param maxrate
+ * @throws TransferFailureException
+ * @throws HostFailureException
+ * @throws TimeoutException
*/
- public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException {
- MsgNative.taskSendBounded(alias, this, maxrate);
- }
-
+ public native void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException;
+ /**
+ * Sends the task on the mailbox asynchronously
+ */
+ public native Comm isend(String mailbox);
+
+ /**
+ * Starts listening for receiving a task from an asynchronous communication
+ * @param mailbox
+ */
+ public static native Comm irecv(String mailbox);
/**
* Retrieves next task from the mailbox identified by the specified name
*
- * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails.
+ * @param mailbox
*/
public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
- return MsgNative.taskReceive(mailbox, -1.0, null);
+ return receive(mailbox, -1.0, null);
}
/**
* Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds)
*
- * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails.
+ * @param mailbox
+ * @param timeout
*/
public static Task receive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException {
- return MsgNative.taskReceive(mailbox, timeout, null);
+ return receive(mailbox, timeout, null);
}
/**
* Retrieves next task sent by a given host on the mailbox identified by the specified alias
*
- * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails.
+ * @param mailbox
+ * @param host
*/
public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
- return MsgNative.taskReceive(mailbox, -1.0, host);
+ return receive(mailbox, -1.0, host);
}
/**
* Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds)
*
- * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails.
+ * @param mailbox
+ * @param timeout
+ * @param host
*/
- public static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
- return MsgNative.taskReceive(mailbox, timeout, host);
- }
-
+ public native static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException;
/**
* Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
- *
- */
- public static int listenFrom(String mailbox) {
- return MsgNative.taskListenFrom(mailbox);
- }
+ */
+ public native static int listenFrom(String mailbox);
/**
* Listen whether there is a waiting task on the mailbox identified by the specified alias
- *
- */
- public static boolean listen(String mailbox) {
- return MsgNative.taskListen(mailbox);
- }
+ */
+ public native static boolean listen(String mailbox);
/**
* 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.
- *
- */
- public static int listenFromHost(String alias, Host host) {
- return MsgNative.taskListenFromHost(alias, host);
+ */
+ public native static int listenFromHost(String alias, Host host);
+
+ /**
+ * Class initializer, to initialize various JNI stuff
+ */
+ public static native void nativeInit();
+ static {
+ nativeInit();
}
}