/
ComputeThread.cpp
74 lines (63 loc) · 2.56 KB
/
ComputeThread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Copyright (c) 2017. The WRENCH Team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include "wrench/logging/TerminalOutput.h"
#include <wrench-dev.h>
#include "ComputeThread.h"
WRENCH_LOG_NEW_DEFAULT_CATEGORY(compute_thread, "Log category for ComputeThread");
namespace wrench {
/**
* @brief Constructor
* @param simulation: a pointer to the simulation object
* @param hostname: the host on which the compute thread should run
* @param flops: the number of flops to perform
* @param reply_mailbox: the mailbox to which the "done/failed" message should be sent
*/
ComputeThread::ComputeThread(Simulation *simulation, std::string hostname, double flops, std::string reply_mailbox)
:
Service(hostname, "compute_thread", "compute_thread") {
this->simulation = simulation;
this->flops = flops;
this->reply_mailbox = reply_mailbox;
}
/**
* @brief The main method of the compute thread
* @return
*/
int ComputeThread::main() {
WRENCH_INFO("New compute thread (%.2f flops, will report to %s)", this->flops, reply_mailbox.c_str());
S4U_Simulation::compute(this->flops);
try {
S4U_Mailbox::putMessage(this->reply_mailbox, new ComputeThreadDoneMessage());
} catch (std::shared_ptr<NetworkError> &e) {
WRENCH_INFO("Couldn't report on my completion to my parent [ignoring and returning as if everything's ok]");
return 0;
}
return 0;
}
/**
* @brief Terminate (brutally) the compute thread
*/
void ComputeThread::kill() {
try {
this->killActor();
} catch (std::shared_ptr<FatalFailure> &e) {
WRENCH_INFO("Failed to kill a compute thread.. .perhaps it's already dead... nevermind");
}
}
/**
* @brief Cleanup method that overrides the base method and does nothing as a compute thread
* does not need to implement any particular fault-tolerant behavior (it runs on the
* same how as a workunit executor, which is also dead anyway)
* @param has_returned_from_main: whether the daemon has terminated cleanly (i.e., returned from main)
* @param return_value: main's return value
*/
void ComputeThread::cleanup(bool has_returned_from_main, int return_value) {
return;
}
};