4 * This file contains the declaration of the wrapper class of the native MSG task type.
\r
6 * Copyright 2006,2007 Martin Quinson, Malek Cherier
\r
7 * All right reserved.
\r
9 * This program is free software; you can redistribute
\r
10 * it and/or modify it under the terms of the license
\r
11 *(GNU LGPL) which comes with this package.
\r
15 #ifndef MSG_TASK_HPP
\r
16 #define MSG_TASK_HPP
\r
18 // Compilation C++ recquise
\r
20 #error Task.hpp requires C++ compilation (use a .cxx suffix)
\r
23 #include <msg/datatypes.h>
\r
25 #include <Config.hpp>
\r
27 #include <Object.hpp>
\r
34 class InvalidArgumentException;
\r
35 class NullPointerException;
\r
37 class BadAllocException;
\r
42 // SimGrid::Msg::Task wrapper class declaration.
\r
43 class SIMGRIDX_EXPORT Task : public Object
\r
45 MSG_DECLARE_DYNAMIC(Task);
\r
51 // Default constructor.
\r
65 void operator++(void){
\r
70 void operator--(void){
\r
82 /*! \brief Copy constructor.
\r
84 Task(const Task& rTask);
\r
86 /*! \brief Destructor.
\r
88 * \exception If the destructor failed, it throw the exception described below:
\r
90 * [MsgException] if a native exception occurs.
\r
93 throw(MsgException);
\r
95 /*! \brief Constructs an new task with the specified processing amount and amount
\r
98 * \param name Task's name
\r
99 * \param computeDuration A value of the processing amount (in flop) needed to process the task.
\r
100 * If 0, then it cannot be executed with the execute() method.
\r
101 * This value has to be >= 0.
\r
102 * \param messageSize A value of amount of data (in bytes) needed to transfert this task.
\r
103 * If 0, then it cannot be transfered with the get() and put() methods.
\r
104 * This value has to be >= 0.
\r
106 * \exception If this method failed, it throws one of the exceptions described below:
\r
108 * [InvalidArgumentException] if the parameter computeDuration or messageSize
\r
110 * [NullPointerException] if the parameter name is NULL.
\r
112 * [MsgException] if a internal exception occurs.
\r
114 Task(const char* name, double computeDuration, double messageSize)
\r
115 throw (InvalidArgumentException, NullPointerException);
\r
117 /*! \Constructs an new parallel task with the specified processing amount and amount for each host
\r
120 * \param name The name of the parallel task.
\r
121 * \param hosts The list of hosts implied by the parallel task.
\r
122 * \param computeDurations The amount of operations to be performed by each host of \a hosts.
\r
123 * \param messageSizes A matrix describing the amount of data to exchange between hosts.
\r
124 * \hostCount The number of hosts implied in the parallel task.
\r
126 * \exception If this method fails, it throws one of the exceptions described below:
\r
128 * [NullPointerException] if the parameter name is NULL or
\r
129 * if the parameter computeDurations is NULL or
\r
130 * if the parameter messageSizes is NULL
\r
132 * [InvalidArgumentException] if the parameter hostCount is negative or zero.
\r
134 Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes, int hostCount)
\r
135 throw(NullPointerException, InvalidArgumentException);
\r
138 /*! \brief Task::getName() - Gets the names of the task.
\r
140 * \return The name of the task.
\r
142 const char* getName(void) const;
\r
144 /*! \brief Task::getSender() - Gets the sender of the task.
\r
146 * \return A reference to the sender of the task.
\r
148 Process& getSender(void) const;
\r
150 /*! \brief Task::getSource() - Gets the source of the task.
\r
152 * \return A reference to the source of the task.
\r
154 Host& getSource(void) const;
\r
156 /*! \brief Task::getComputeDuration() - Get the computing amount of the task.
\r
158 * \return The computing amount of the task.
\r
161 double getComputeDuration(void) const;
\r
163 /*! \brief Task::getRemainingDuration() - Gets the remaining computation.
\r
165 * \return The remining computation of the task.
\r
167 double getRemainingDuration(void) const;
\r
169 /*! \brief Task::setPrirority() - Sets the priority of the computation of the task.
\r
170 * The priority doesn't affect the transfert rate. For example a
\r
171 * priority of 2 will make the task receive two times more cpu than
\r
174 * \param priority The new priority of the task.
\r
176 * execption If this method fails, it throws the exception described below:
\r
178 * [InvalidArgumentException] if the parameter priority is negative.
\r
180 void setPriority(double priority)
\r
181 throw(InvalidArgumentException);
\r
183 /*! \brief Task::get() - Gets a task from the specified channel of the host of the current process.
\r
185 * \param channel The channel number to get the task.
\r
187 * \return If successful the method returns the task. Otherwise the method throws one
\r
188 * of the exceptions described below:
\r
190 * \exception [InvalidArgumentException] if the channel parameter is negative.
\r
192 * [MsgException] if an internal excpetion occurs.
\r
194 /*static Task& get(int channel)
\r
195 throw(InvalidArgumentException, MsgException);*/
\r
197 static Task* get(int channel)
\r
198 throw(InvalidArgumentException, MsgException);
\r
200 /*! \brief Task::get() - Gets a task from the given channel number of the given host.
\r
202 * \param channel The channel number.
\r
203 * \param rHost A reference of the host owning the channel.
\r
205 * \return If successful, the method returns the task. Otherwise the method
\r
206 * throw one of the exceptions described below:
\r
208 * \exception [InvalidArgumentException] if the channel number is negative.
\r
210 * [MsgException] if an internal exception occurs.
\r
212 static Task& get(int channel, const Host& rHost)
\r
213 throw(InvalidArgumentException, MsgException);
\r
215 /*! \brief Task::get() - Gets a task from the specified channel of the specified host
\r
216 * (waiting at most given time).
\r
218 * \param channel The channel number.
\r
219 * \param timeout The timeout value.
\r
220 * \param rHost A reference to the host owning the channel.
\r
222 * \return If successful, the method returns the task. Otherwise the method returns
\r
223 * one of the exceptions described below:
\r
225 * \exception [InvalidArgumentException] if the channel number is negative or
\r
226 * if the timeout value is negative and
\r
227 * different than -1.0.
\r
228 * [MsgException] if an internal exception occurs.
\r
230 static Task& get(int channel, double timeout, const Host& rHost)
\r
231 throw(InvalidArgumentException, MsgException);
\r
233 /*! \brief Task::probe() - Probes whether there is a waiting task on the given channel of local host.
\r
235 * \param channel The channel number.
\r
237 * \return If there is a waiting task on the channel the method returns 1. Otherwise
\r
238 * the method returns 0.
\r
240 * \exception If this method fails, it throws the exception described below:
\r
242 * [InvalidArgumentException] if the parameter channel is negative.
\r
244 static int probe(int channel)
\r
245 throw(InvalidArgumentException);
\r
247 /*! \brief Task::probe() - Counts tasks waiting on the given channel of local host and sent by given host.
\r
249 * \param channel The channel id.
\r
250 * \param rHost A reference to the host that has sent the task.
\r
252 * \return The number of tasks.
\r
254 * \exception [InvalidArgumentException] if the parameter channel is negative.
\r
256 static int probe(int channel, const Host& rHost)
\r
257 throw(InvalidArgumentException);
\r
259 /*! \brief Task::execute() - This method executes a task on the location on which the
\r
260 * process is running.
\r
262 * \exception If this method fails, it returns the exception described below:
\r
264 * [MsgException] if an internal exception occurs.
\r
266 void execute(void)
\r
267 throw(MsgException);
\r
269 /*! \brief Task::cancel() - This method cancels a task.
\r
271 * \exception If this method fails, it returns the exception described below:
\r
273 * [MsgException] if an internal exception occurs.
\r
276 throw(MsgException);
\r
278 /*! \brief Task::send() - Send the task on the mailbox identified by the default alias.
\r
280 * \exception If this method failed, it returns one of the exceptions described
\r
283 * [BadAllocException] if there is not enough memory to build the default alias.
\r
285 * [MsgException] if an internal exception occurs.
\r
288 throw(BadAllocException, MsgException);
\r
290 /*! \brief Task::send() - Send the task on the mailbox identified by the given alias.
\r
292 * \param alias The alias of the mailbox where to send the task.
\r
294 * \exception If this method failed, it returns one of the exceptions described
\r
297 * [NullPointerException] if there parameter alias is NULL.
\r
299 * [MsgException] if an internal exception occurs.
\r
301 void send(const char* alias)
\r
302 throw(NullPointerException, MsgException);
\r
304 /*! \brief Task::send() - Send the task on the mailbox identified by the default alias
\r
305 * (waiting at most given time).
\r
307 * \param timeout The timeout value.
\r
309 * \exception If this method failed, it returns one of the exceptions described
\r
312 * [BadAllocException] if there is not enough memory to build the default alias.
\r
314 * [InvalidArgumentException] if the timeout value is negative or different -1.0.
\r
316 * [MsgException] if an internal exception occurs.
\r
318 void send(double timeout)
\r
319 throw(BadAllocException, InvalidArgumentException, MsgException);
\r
321 /*! \brief Task::send() - Send the task on the mailbox identified by a given alias
\r
322 * (waiting at most given time).
\r
324 * \param alias The alias of the mailbox where to send the task.
\r
325 * \param timeout The timeout value.
\r
327 * \exception If this method failed, it returns one of the exceptions described
\r
330 * [NullPointerException] if alias parameter is NULL.
\r
332 * [InvalidArgumentException] if the timeout value is negative or different -1.0.
\r
334 * [MsgException] if an internal exception occurs.
\r
336 void send(const char* alias, double timeout)
\r
337 throw(NullPointerException, InvalidArgumentException, MsgException);
\r
339 /*! \brief Task::sendBounded() - Sends the task on the mailbox identified by the default alias.
\r
340 * (capping the emision rate to maxrate).
\r
342 * \param maxRate The maximum rate value.
\r
344 * \exception If this method failed, it throws one of the exceptions described below:
\r
346 * [BadAllocException] if there is not enough memory to build the default alias.
\r
348 * [InvalidArgumentException] if the parameter maxRate is negative and different
\r
351 * [MsgException] if an internal exception occurs.
\r
353 void sendBounded(double maxRate)
\r
354 throw(BadAllocException, InvalidArgumentException, MsgException);
\r
356 /*! \brief Task::sendBounded() - Sends the task on the mailbox identified by the given alias.
\r
357 * (capping the emision rate to maxrate).
\r
359 *\ param alias The alias of the mailbox where to send the task.
\r
360 * \param maxRate The maximum rate value.
\r
362 * \exception If this method failed, it throws one of the exceptions described below:
\r
364 * [NullPointerException] if the alias parameter is NULL.
\r
366 * [InvalidArgumentException] if the parameter maxRate is negative and different
\r
369 * [MsgException] if an internal exception occurs.
\r
371 void sendBounded(const char* alias, double maxRate)
\r
372 throw(NullPointerException, InvalidArgumentException, MsgException);
\r
375 /*! \brief Task::receive() - Receives a task from the mailbox identified by the default alias (located
\r
376 * on the local host).
\r
378 * \return A reference to the task.
\r
380 * \exception If this method failed, it throws one of the exception described below:
\r
382 * [BadAllocException] if there is not enough memory to build the default alias.
\r
384 * [MsgException] if an internal exception occurs.
\r
386 /*static Task& receive(void)
\r
387 throw(BadAllocException, MsgException);*/
\r
389 static Task* receive(void)
\r
390 throw(BadAllocException, MsgException);
\r
392 /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias (located
\r
393 * on the local host).
\r
395 * \alias The alias of the mailbox.
\r
397 * \return A reference to the task.
\r
399 * \exception If this method failed, it throws one of the exception described below:
\r
401 * [NullPointerException] if the alias parameter is NULL.
\r
403 * [MsgException] if an internal exception occurs.
\r
405 /*static Task& receive(const char* alias)
\r
406 throw(NullPointerException, MsgException);*/
\r
407 static Task* receive(const char* alias)
\r
408 throw(NullPointerException, MsgException);
\r
410 /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias (located
\r
411 * on the local host and waiting at most given time).
\r
413 * \alias The alias of the mailbox.
\r
414 * \timeout The timeout value.
\r
416 * \return A reference to the task.
\r
418 * \exception If this method failed, it throws one of the exception described below:
\r
420 * [NullPointerException] if the alias parameter is NULL.
\r
422 * [InvalidArgumentException] if the timeout value is negatif and different than
\r
425 * [MsgException] if an internal exception occurs.
\r
427 static Task& receive(const char* alias, double timeout)
\r
428 throw(NullPointerException, InvalidArgumentException, MsgException);
\r
430 /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias located
\r
431 * on the given host.
\r
433 * \alias The alias of the mailbox.
\r
434 * \rHost The location of the mailbox.
\r
436 * \return A reference to the task.
\r
438 * \exception If this method failed, it throws one of the exception described below:
\r
440 * [NullPointerException] if the alias parameter is NULL.
\r
442 * [MsgException] if an internal exception occurs.
\r
444 static Task& receive(const char* alias, const Host& rHost)
\r
445 throw(NullPointerException, MsgException);
\r
447 /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias located
\r
448 * on the given host (and waiting at most given time).
\r
450 * \alias The alias of the mailbox.
\r
451 * \timeout The timeout value.
\r
452 * \rHost The location of the mailbox.
\r
454 * \return A reference to the task.
\r
456 * \exception If this method failed, it throws one of the exception described below:
\r
458 * [NullPointerException] if the alias parameter is NULL.
\r
460 * [InvalidArgumentException] if the timeout value is negatif and different than
\r
463 * [MsgException] if an internal exception occurs.
\r
465 static Task& receive(const char* alias, double timeout, const Host& rHost)
\r
466 throw(NullPointerException, InvalidArgumentException, MsgException);
\r
468 /*! \brief Task::listen() - Listen whether there is a waiting task on the mailbox
\r
469 * identified by the default alias of local host.
\r
471 * \return If there is a waiting task on the mailbox the method returns true.
\r
472 * Otherwise the method returns false.
\r
474 * \exception If this method fails, it throws one of the exceptions described below:
\r
476 * [BadAllocException] if there is not enough memory to build the default alias.
\r
478 static int listen(void)
\r
479 throw(BadAllocException);
\r
481 /*! \brief Task::listen() - Listen whether there is a waiting task on the mailbox
\r
482 * identified by the given alias of local host.
\r
484 * \param alias The alias of the mailbox.
\r
486 * \return If there is a waiting task on the mailbox the method returns 1.
\r
487 * Otherwise the method returns 0.
\r
489 * \exception If this method fails, it throws one of the exceptions described below:
\r
491 * [NullPointerException] if the parameter alias is NULL.
\r
493 static int listen(const char* alias)
\r
494 throw(NullPointerException);
\r
496 /*! \brief Task::listenFrom() - Tests whether there is a pending communication on the mailbox
\r
497 * identified by the default alias, and who sent it.
\r
499 * \return If there is a pending communication on the mailbox, the method returns
\r
500 * the PID of it sender. Otherwise the method returns -1.
\r
502 * \exception If this method fails, it throws the exception described below:
\r
504 * [BadAllocException] if there is not enough memory to build the default
\r
507 static int listenFrom(void)
\r
508 throw(BadAllocException);
\r
510 /*! \brief Task::listenFrom() - Tests whether there is a pending communication on the mailbox
\r
511 * identified by the specified alias, and who sent it.
\r
513 * \alias The alias of the mailbox.
\r
515 * \return If there is a pending communication on the mailbox, the method returns
\r
516 * the PID of it sender. Otherwise the method returns -1.
\r
518 * \exception If this method fails, it throws the exception described below:
\r
520 * [NullPointerException] if the alias parameter is NULL.
\r
522 static int listenFrom(const char* alias)
\r
523 throw(NullPointerException);
\r
525 /*! \brief Task::listenFromHost() - Tests whether there is a pending communication on the mailbox
\r
526 * identified by the default alias and located on the host of the current process, and who sent it.
\r
528 * \param rHost The location of the mailbox.
\r
530 * \return If there is a pending communication on the mailbox, the method returns
\r
531 * the PID of it sender. Otherwise the method returns -1.
\r
533 * \exception If this method fails, it throws the exception described below:
\r
535 * [BadAllocException] if there is not enough memory to build the default
\r
538 static int listenFromHost(const Host& rHost)
\r
539 throw(BadAllocException);
\r
541 /*! \brief Task::listenFromHost() - Tests whether there is a pending communication on the mailbox
\r
542 * identified by the default alias and located on the host of the current process, and who sent it.
\r
544 * \param rHost The location of the mailbox.
\r
546 * \return If there is a pending communication on the mailbox, the method returns
\r
547 * the PID of it sender. Otherwise the method returns -1.
\r
549 * \exception If this method fails, it throws the exception described below:
\r
551 * [BadAllocException] if there is not enough memory to build the default
\r
554 static int listenFromHost(const char* alias, const Host& rHost)
\r
555 throw(NullPointerException, MsgException);
\r
557 virtual const Task& operator= (const Task& rTask);
\r
563 m_task_t nativeTask; // the native MSG task.
\r
568 } // namespace Msg
\r
569 } // namespace SimGrid
\r
571 typedef Task* TaskPtr;
\r
573 #endif // §MSG_TASK_HPP