3 #include <MsgException.hpp>
\r
4 #include <InvalidArgumentException.hpp>
\r
5 #include <NullPointerException.hpp>
\r
6 #include <MsgException.hpp>
\r
7 #include <BadAllocException.hpp>
\r
9 #include <Process.hpp>
\r
15 #include <msg/msg.h>
\r
22 MSG_IMPLEMENT_DYNAMIC(Task, Object);
\r
30 Task::Task(const Task& rTask)
\r
32 this->nativeTask = rTask.nativeTask;
\r
39 if(NULL != nativeTask)
\r
40 if(MSG_OK != MSG_task_destroy(nativeTask))
\r
41 throw MsgException("MSG_task_destroy() failed");
\r
45 Task::Task(const char* name, double computeDuration, double messageSize)
\r
46 throw(InvalidArgumentException, NullPointerException)
\r
49 if(computeDuration < 0)
\r
50 throw InvalidArgumentException("computeDuration");
\r
52 if(messageSize < 0)
\r
53 throw InvalidArgumentException("messageSize");
\r
56 throw NullPointerException("name");
\r
59 nativeTask = MSG_task_create(name, computeDuration, messageSize, NULL);
\r
61 nativeTask->data = (void*)this;
\r
64 Task::Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes, int hostCount)
\r
65 throw(NullPointerException, InvalidArgumentException)
\r
67 // check the parameters
\r
70 throw NullPointerException("name");
\r
73 throw NullPointerException("hosts");
\r
75 if(!computeDurations)
\r
76 throw NullPointerException("computeDurations");
\r
79 throw NullPointerException("messageSizes");
\r
82 throw InvalidArgumentException("hostCount (must not be zero)");
\r
85 m_host_t* nativeHosts;
\r
90 nativeHosts = xbt_new0(m_host_t, hostCount);
\r
91 durations = xbt_new0(double,hostCount);
\r
92 sizes = xbt_new0(double, hostCount * hostCount);
\r
95 for(int index = 0; index < hostCount; index++)
\r
98 nativeHosts[index] = hosts[index].nativeHost;
\r
99 durations[index] = computeDurations[index];
\r
102 for(int index = 0; index < hostCount*hostCount; index++)
\r
103 sizes[index] = messageSizes[index];
\r
106 nativeTask = MSG_parallel_task_create(name, hostCount, nativeHosts, durations, sizes,NULL);
\r
110 this->nativeTask->data = (void*)this;
\r
114 const char* Task::getName(void) const
\r
116 return nativeTask->name;
\r
119 Process& Task::getSender(void) const
\r
121 m_process_t nativeProcess = MSG_task_get_sender(nativeTask);
\r
123 return (*((Process*)(nativeProcess->data)));
\r
126 Host& Task::getSource(void) const
\r
128 m_host_t nativeHost = MSG_task_get_source(nativeTask);
\r
130 return (*((Host*)(nativeHost->data)));
\r
133 double Task::getComputeDuration(void) const
\r
135 return MSG_task_get_compute_duration(nativeTask);
\r
138 double Task::getRemainingDuration(void) const
\r
140 return MSG_task_get_remaining_computation(nativeTask);
\r
143 void Task::setPriority(double priority)
\r
144 throw(InvalidArgumentException)
\r
146 // check the parameters
\r
149 throw InvalidArgumentException("priority");
\r
151 MSG_task_set_priority(nativeTask, priority);
\r
154 /*Task& Task::get(int channel)
\r
155 throw(InvalidArgumentException, MsgException)
\r
157 // check the parameters
\r
160 throw InvalidArgumentException("channel (must not be negative)");
\r
162 m_task_t nativeTask = NULL;
\r
164 if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, NULL))
\r
165 throw MsgException("MSG_task_get_ext() failed");
\r
167 return (*((Task*)(nativeTask->data)));
\r
170 Task* Task::get(int channel)
\r
171 throw(InvalidArgumentException, MsgException)
\r
173 // check the parameters
\r
176 throw InvalidArgumentException("channel (must not be negative)");
\r
178 m_task_t nativeTask = NULL;
\r
180 if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, NULL))
\r
181 throw MsgException("MSG_task_get_ext() failed");
\r
183 return ((Task*)(nativeTask->data));
\r
186 Task& Task::get(int channel, const Host& rHost)
\r
187 throw(InvalidArgumentException, MsgException)
\r
189 // check the parameters
\r
192 throw InvalidArgumentException("channel (must not be negative)");
\r
194 m_task_t nativeTask = NULL;
\r
197 if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, rHost.nativeHost))
\r
198 throw MsgException("MSG_task_get_ext() failed");
\r
200 return (*((Task*)(nativeTask->data)));
\r
203 Task& Task::get(int channel, double timeout, const Host& rHost)
\r
204 throw(InvalidArgumentException, MsgException)
\r
206 // check the parameters
\r
209 throw InvalidArgumentException("channel (must not be negative)");
\r
211 if(timeout < 0 && timeout !=-1.0)
\r
212 throw InvalidArgumentException("timeout (must not be negative and different thant -1.0)");
\r
214 m_task_t nativeTask = NULL;
\r
217 if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , timeout, rHost.nativeHost))
\r
218 throw MsgException("MSG_task_get_ext() failed");
\r
220 return (*((Task*)(nativeTask->data)));
\r
223 int Task::probe(int channel)
\r
224 throw(InvalidArgumentException)
\r
226 // check the parameters
\r
229 throw InvalidArgumentException("channel (must not be negative)");
\r
231 return MSG_task_Iprobe(channel);
\r
234 int Task::probe(int channel, const Host& rHost)
\r
235 throw(InvalidArgumentException)
\r
237 // check the parameters
\r
240 throw InvalidArgumentException("channel (must not be negative)");
\r
242 return MSG_task_probe_from_host(channel,rHost.nativeHost);
\r
245 void Task::execute(void)
\r
246 throw(MsgException)
\r
248 if(MSG_OK != MSG_task_execute(nativeTask))
\r
249 throw MsgException("MSG_task_execute() failed");
\r
252 void Task::cancel(void)
\r
253 throw(MsgException)
\r
255 if(MSG_OK != MSG_task_cancel(nativeTask))
\r
256 throw MsgException("MSG_task_cancel() failed");
\r
259 void Task::send(void)
\r
260 throw(BadAllocException, MsgException)
\r
262 char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));
\r
265 throw BadAllocException("alias");
\r
267 sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());
\r
269 MSG_error_t rv = MSG_task_send_with_timeout(nativeTask, alias, -1.0);
\r
274 throw MsgException("MSG_task_send_with_timeout() failed");
\r
277 void Task::send(const char* alias)
\r
278 throw(NullPointerException, MsgException)
\r
280 // check the parameters
\r
283 throw NullPointerException("alias");
\r
285 if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, -1.0))
\r
286 throw MsgException("MSG_task_send_with_timeout() failed");
\r
289 void Task::send(double timeout)
\r
290 throw(BadAllocException, InvalidArgumentException, MsgException)
\r
292 // check the parameters
\r
294 if(timeout < 0 && timeout != -1.0)
\r
295 throw InvalidArgumentException("timeout (must not be negative and different than -1.0");
\r
297 char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));
\r
300 throw BadAllocException("alias");
\r
302 sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());
\r
304 MSG_error_t rv = MSG_task_send_with_timeout(nativeTask, alias, timeout);
\r
309 throw MsgException("MSG_task_send_with_timeout() failed");
\r
312 void Task::send(const char* alias, double timeout)
\r
313 throw(NullPointerException, InvalidArgumentException, MsgException)
\r
315 // check the parameters
\r
318 throw NullPointerException("alias");
\r
320 if(timeout < 0 && timeout != -1.0)
\r
321 throw InvalidArgumentException("timeout (must not be negative and different than -1.0");
\r
324 if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, timeout))
\r
325 throw MsgException("MSG_task_send_with_timeout() failed");
\r
328 void Task::sendBounded(double maxRate)
\r
329 throw(BadAllocException, InvalidArgumentException, MsgException)
\r
331 // check the parameters
\r
333 if(maxRate < 0 && maxRate != -1.0)
\r
334 throw InvalidArgumentException("maxRate (must not be negative and different than -1.0");
\r
336 char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));
\r
339 throw BadAllocException("alias");
\r
341 sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());
\r
343 MSG_error_t rv = MSG_task_send_bounded(nativeTask, alias, maxRate);
\r
348 throw MsgException("MSG_task_send_bounded() failed");
\r
352 void Task::sendBounded(const char* alias, double maxRate)
\r
353 throw(NullPointerException, InvalidArgumentException, MsgException)
\r
355 // check the parameters
\r
357 if(maxRate < 0 && maxRate != -1.0)
\r
358 throw InvalidArgumentException("maxRate (must not be negative and different than -1.0");
\r
361 throw NullPointerException("alias");
\r
363 if(MSG_OK != MSG_task_send_bounded(nativeTask, alias, maxRate))
\r
364 throw MsgException("MSG_task_send_bounded() failed");
\r
367 /*Task& Task::receive(void)
\r
368 throw(BadAllocException, MsgException)
\r
370 char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));
\r
373 throw BadAllocException("alias");
\r
375 sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());
\r
377 m_task_t nativeTask = NULL;
\r
379 MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL);
\r
384 throw MsgException("MSG_task_receive_ext() failed");
\r
386 return (*((Task*)nativeTask->data));
\r
389 Task* Task::receive(void)
\r
390 throw(BadAllocException, MsgException)
\r
392 char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));
\r
395 throw BadAllocException("alias");
\r
397 sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());
\r
399 m_task_t nativeTask = NULL;
\r
401 MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL);
\r
406 throw MsgException("MSG_task_receive_ext() failed");
\r
408 return ((Task*)nativeTask->data);
\r
411 /*Task& Task::receive(const char* alias)
\r
412 throw(NullPointerException, MsgException)
\r
414 // check the parameters
\r
417 throw NullPointerException("alias");
\r
419 m_task_t nativeTask = NULL;
\r
421 if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL))
\r
422 throw MsgException("MSG_task_receive_ext() failed");
\r
424 return (*((Task*)nativeTask->data));
\r
427 Task* Task::receive(const char* alias)
\r
428 throw(NullPointerException, MsgException)
\r
430 // check the parameters
\r
433 throw NullPointerException("alias");
\r
435 m_task_t nativeTask = NULL;
\r
437 if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL))
\r
438 throw MsgException("MSG_task_receive_ext() failed");
\r
440 return ((Task*)nativeTask->data);
\r
443 Task& Task::receive(const char* alias, double timeout)
\r
444 throw(NullPointerException, InvalidArgumentException, MsgException)
\r
446 // check the parameters
\r
449 throw NullPointerException("alias");
\r
451 if(timeout < 0 && timeout != -1.0)
\r
452 throw InvalidArgumentException("timeout (must not be negative and differnt than -1.0)");
\r
454 m_task_t nativeTask = NULL;
\r
456 if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, NULL))
\r
457 throw MsgException("MSG_task_receive_ext() failed");
\r
459 return (*((Task*)nativeTask->data));
\r
462 Task& Task::receive(const char* alias, const Host& rHost)
\r
463 throw(NullPointerException, MsgException)
\r
465 // check the parameters
\r
468 throw NullPointerException("alias");
\r
470 m_task_t nativeTask = NULL;
\r
472 if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost))
\r
473 throw MsgException("MSG_task_receive_ext() failed");
\r
475 return (*((Task*)nativeTask->data));
\r
478 Task& Task::receive(const char* alias, double timeout, const Host& rHost)
\r
479 throw(NullPointerException, InvalidArgumentException, MsgException)
\r
481 // check the parameters
\r
484 throw NullPointerException("alias");
\r
486 if(timeout < 0 && timeout != -1.0)
\r
487 throw InvalidArgumentException("timeout (must not be negative and differnt than -1.0)");
\r
489 m_task_t nativeTask = NULL;
\r
492 if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost))
\r
493 throw MsgException("MSG_task_receive_ext() failed");
\r
495 return (*((Task*)nativeTask->data));
\r
498 int Task::listen(void)
\r
499 throw(BadAllocException)
\r
501 char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));
\r
504 throw BadAllocException("alias");
\r
506 sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());
\r
508 int rv = MSG_task_listen(alias);
\r
515 int Task::listen(const char* alias)
\r
516 throw(NullPointerException)
\r
518 // check the parameters
\r
521 throw NullPointerException("alias");
\r
523 return MSG_task_listen(alias);
\r
526 int Task::listenFrom(void)
\r
527 throw(BadAllocException)
\r
529 char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));
\r
532 throw BadAllocException("alias");
\r
534 sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());
\r
536 int rv = MSG_task_listen_from(alias);
\r
543 int Task::listenFrom(const char* alias)
\r
544 throw(NullPointerException)
\r
547 throw NullPointerException("alias");
\r
549 return MSG_task_listen_from(alias);
\r
553 int Task::listenFromHost(const Host& rHost)
\r
554 throw(BadAllocException)
\r
556 char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));
\r
559 throw BadAllocException("alias");
\r
561 sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());
\r
563 int rv = MSG_task_listen_from_host(alias, rHost.nativeHost);
\r
570 int Task::listenFromHost(const char* alias, const Host& rHost)
\r
571 throw(NullPointerException)
\r
573 // check the parameters
\r
575 throw NullPointerException("alias");
\r
577 return MSG_task_listen_from_host(alias, rHost.nativeHost);
\r
580 const Task& Task::operator = (const Task& rTask)
\r
582 this->nativeTask = rTask.nativeTask;
\r
585 } // namespace Msg
\r
586 } // namespace SimGrid
\r