1 /* Copyright (c) 2006-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 package org.simgrid.msg;
10 * A task is either something to compute somewhere, or something to exchange between two hosts (or both).
11 * It is defined by a computing amount and a message size.
16 * This attribute represents a bind between a java task object and
17 * a native task. Even if this attribute is public you must never
18 * access to it. It is set automatically during the build of the object.
20 private long bind = 0;
24 protected String name;
26 private double messageSize;
28 static private Long idCpt = 0L;
32 /** Default constructor (all fields to 0 or null) */
44 * Construct an new task with the specified processing amount and amount
47 * @param name Task's name
49 * @param flopsAmount A value of the processing amount (in flop) needed to process the task.
50 * If 0, then it cannot be executed with the execute() method.
51 * This value has to be >= 0.
53 * @param bytesAmount A value of amount of data (in bytes) needed to transfert this task.
54 * If 0, then it cannot be transfered with the get() and put() methods.
55 * This value has to be >= 0.
57 public Task(String name, double flopsAmount, double bytesAmount) {
58 create(name, flopsAmount, bytesAmount);
59 this.messageSize = bytesAmount;
64 * Construct an new parallel task with the specified processing amount and amount for each host
67 * @param name The name of the parallel task.
68 * @param hosts The list of hosts implied by the parallel task.
69 * @param flopsAmount The amount of operations to be performed by each host of \a hosts.
70 * @param bytesAmount A matrix describing the amount of data to exchange between hosts.
72 public Task(String name, Host[]hosts, double[]flopsAmount, double[]bytesAmount) {
73 parallelCreate(name, hosts, flopsAmount, bytesAmount);
77 * The natively implemented method to create a MSG task.
79 * @param name The name of th task.
80 * @param flopsAmount A value of the processing amount (in flop) needed
81 * to process the task. If 0, then it cannot be executed
82 * with the execute() method. This value has to be >= 0.
83 * @param bytesAmount A value of amount of data (in bytes) needed to transfert
84 * this task. If 0, then it cannot be transfered this task.
85 * If 0, then it cannot be transfered with the get() and put()
86 * methods. This value has to be >= 0.
87 * @exception IllegalArgumentException if compute duration <0 or message size <0
89 private final native void create(String name,
92 throws IllegalArgumentException;
94 * The natively implemented method to create a MSG parallel task.
96 * @param name The name of the parallel task.
97 * @param hosts The list of hosts implied by the parallel task.
98 * @param flopsAmount The total number of operations that have to be performed
100 * @param bytesAmount An array of doubles
103 private final native void parallelCreate(String name,
107 throws NullPointerException, IllegalArgumentException;
109 * * Getters / Setters * *
112 * Gets the name of a task
114 public String getName() {
118 * Gets the sender of the task
119 * Returns null if the task hasn't been sent yet
121 public native Process getSender();
122 /** Gets the source of the task.
123 * Returns null if the task hasn't been sent yet.
125 public native Host getSource();
127 /** Gets the remaining amount of flops to execute in this task
129 * If it's ongoing, you get the exact amount at the present time. If it's already done, it's 0.
131 public native double getFlopsAmount();
133 * Sets the name of the task
134 * @param name the new task name.c
136 public native void setName(String name);
138 * This method sets the priority of the computation of the task.
139 * The priority doesn't affect the transfer rate. For example a
140 * priority of 2 will make the task receive two times more cpu than
143 * @param priority The new priority of the task.
145 public native void setPriority(double priority);
147 * Set the computation amount needed to process the task
148 * @param computationAmount the amount of computation needed to process the task
150 public native void setComputeDuration(double computationAmount);
152 * Set the data size of the task
153 * @param dataSize the size of the task
155 public native void setDataSize(double dataSize);
157 * * Computation-related * *
160 * Executes a task on the location on which the process is running.
163 * @throws HostFailureException
164 * @throws TaskCancelledException
166 public native void execute() throws HostFailureException,TaskCancelledException;
168 * Bound a computation to a certain load
171 public native void setBound(double load);
176 public native void cancel();
179 * @exception NativeException if the destruction failed.
181 protected void finalize() throws NativeException {
185 * The natively implemented method to destroy a MSG task.
187 protected native void destroy();
189 * * Communication-related * *
192 /** Send the task asynchronously on the mailbox identified by the specified name,
193 * with no way to retrieve whether the communication succeeded or not
196 public native void dsendBounded(String mailbox, double maxrate);
199 /** Send the task asynchronously on the mailbox identified by the specified name,
200 * with no way to retrieve whether the communication succeeded or not
203 public native void dsend(String mailbox);
206 * Sends the task on the mailbox identified by the specified name
209 * @throws TimeoutException
210 * @throws HostFailureException
211 * @throws TransferFailureException
213 public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
218 * Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds)
222 * @exception NativeException if the retrieval fails.
223 * @throws TimeoutException
224 * @throws HostFailureException
225 * @throws TransferFailureException
227 public native void send(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
229 * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate)
233 * @throws TransferFailureException
234 * @throws HostFailureException
235 * @throws TimeoutException
237 public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException {
238 sendBounded(alias,-1,maxrate);
243 * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate) with a timeout
248 * @throws TransferFailureException
249 * @throws HostFailureException
250 * @throws TimeoutException
252 public native void sendBounded(String alias, double timeout, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException;
256 * Sends the task on the mailbox asynchronously
258 public native Comm isend(String mailbox);
261 * Sends the task on the mailbox asynchronously (capping the sending rate to \a maxrate)
263 public native Comm isendBounded(String mailbox, double maxrate);
267 * Starts listening for receiving a task from an asynchronous communication
270 public static native Comm irecv(String mailbox);
272 * Retrieves next task from the mailbox identified by the specified name
277 public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
278 return receive(mailbox, -1.0, null);
282 * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds)
287 public static Task receive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException {
288 return receive(mailbox, timeout, null);
292 * Retrieves next task sent by a given host on the mailbox identified by the specified alias
298 public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
299 return receive(mailbox, -1.0, host);
303 * Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds)
309 public native static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException;
312 * Starts listening for receiving a task from an asynchronous communication with a capped rate
315 public static native Comm irecvBounded(String mailbox, double rate);
317 * Retrieves next task from the mailbox identified by the specified name with a capped rate
322 public static Task receiveBounded(String mailbox, double rate) throws TransferFailureException, HostFailureException, TimeoutException {
323 return receiveBounded(mailbox, -1.0, null, rate);
327 * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds) with a capped rate
332 public static Task receiveBounded(String mailbox, double timeout, double rate) throws TransferFailureException, HostFailureException, TimeoutException {
333 return receiveBounded(mailbox, timeout, null, rate);
337 * Retrieves next task sent by a given host on the mailbox identified by the specified alias with a capped rate
343 public static Task receiveBounded(String mailbox, Host host, double rate) throws TransferFailureException, HostFailureException, TimeoutException {
344 return receiveBounded(mailbox, -1.0, host, rate);
348 * Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds)
355 public native static Task receiveBounded(String mailbox, double timeout, Host host, double rate) throws TransferFailureException, HostFailureException, TimeoutException;
360 * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
362 public native static int listenFrom(String mailbox);
364 * Listen whether there is a waiting task on the mailbox identified by the specified alias
366 public native static boolean listen(String mailbox);
369 * 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.
371 public native static int listenFromHost(String alias, Host host);
374 * Class initializer, to initialize various JNI stuff
376 public static native void nativeInit();
382 public double getMessageSize() {
383 return this.messageSize;
386 public Long getId() {
390 public void setId(Long id) {