/** Helper to sort answer_t objects */
static int _answer_sort_function(const void *e1, const void *e2)
{
- node_contact_t c1 = *(const node_contact_t*)e1;
- node_contact_t c2 = *(const node_contact_t*)e2;
+ const s_node_contact_t* c1 = *(const node_contact_t*)e1;
+ const s_node_contact_t* c2 = *(const node_contact_t*)e2;
if (c1->distance == c2->distance)
return 0;
else
if (xbt_dynar_is_empty(answer->nodes)) {
return 0;
}
- node_contact_t contact_tail = xbt_dynar_get_as(answer->nodes, 0, node_contact_t);
+ const s_node_contact_t* contact_tail = xbt_dynar_get_as(answer->nodes, 0, node_contact_t);
return contact_tail->distance == 0;
}
*/
unsigned int join(node_t node, unsigned int id_known)
{
- answer_t node_list;
+ const s_answer_t* node_list;
msg_error_t status;
unsigned int trial = 0;
unsigned int i;
XBT_DEBUG("Received an answer from the node I know.");
answer_got = 1;
//retrieve the node list and ping them.
- task_data_t data = MSG_task_get_data(node->task_received);
+ const s_task_data_t* data = MSG_task_get_data(node->task_received);
xbt_assert((data != NULL), "Null data received");
if (data->type == TASK_FIND_NODE_ANSWER) {
node_contact_t contact;
if (status == MSG_OK) {
xbt_assert((node->task_received != NULL), "Invalid task received");
//Figure out if we received an answer or something else
- task_data_t data = MSG_task_get_data(node->task_received);
+ const s_task_data_t* data = MSG_task_get_data(node->task_received);
xbt_assert((data != NULL), "No data in the task");
//Check if what we have received is what we are looking for.
while (j < KADEMLIA_ALPHA && i < node_list->size) {
/* We need to have at most "KADEMLIA_ALPHA" requests each time, according to the protocol */
/* Gets the node we want to send the query to */
- node_contact_t node_to_query = xbt_dynar_get_as(node_list->nodes, i, node_contact_t);
+ const s_node_contact_t* node_to_query = xbt_dynar_get_as(node_list->nodes, i, node_contact_t);
if (node_to_query->id != node->id) { /* No need to query ourselves */
send_find_node(node, node_to_query->id, destination);
j++;
MSG_task_receive(&task, "coordinator");
const char *kind = MSG_task_get_name(task); //is it a request or a release?
if (!strcmp(kind, "request")) { // that's a request
- char *req = MSG_task_get_data(task);
+ const char* req = MSG_task_get_data(task);
if (CS_used) {
XBT_INFO("CS already used.");
msg_task_t answer = MSG_task_create("not grant", 0, 1000, NULL);
}
char *tracefilename;
- char *last = strrchr(argv[2], '.');
+ const char* last = strrchr(argv[2], '.');
tracefilename = bprintf("%.*s.trace", (int) (last == NULL ? strlen(argv[2]) : last - argv[2]),argv[2]);
if (argc == 4)
tracefilename = xbt_strdup(argv[3]);
xbt_assert(argc > 2, "Usage: %s platform_file dax_file [jedule_file]\n"
"\tExample: %s simulacrum_7_hosts.xml Montage_25.xml Montage_25.jed", argv[0], argv[0]);
- char *last = strrchr(argv[2], '.');
+ const char* last = strrchr(argv[2], '.');
char * tracefilename = bprintf("%.*s.trace",(int) (last == NULL ? strlen(argv[2]):last - argv[2]), argv[2]);
if (argc == 4)
tracefilename = xbt_strdup(argv[3]);
XBT_INFO("------------------- Run the schedule ---------------------------");
SD_simulate(-1);
XBT_INFO("------------------- Produce the trace file---------------------------");
- char* basename = strrchr(tracefilename, '/');
+ const char* basename = strrchr(tracefilename, '/');
XBT_INFO("Producing the trace of the run into %s", basename ? basename + 1 : tracefilename);
FILE *out = fopen(tracefilename, "w");
xbt_assert(out, "Cannot write to %s", tracefilename);
}
char *tracefilename;
- char *last = strrchr(argv[2], '.');
+ const char* last = strrchr(argv[2], '.');
tracefilename = bprintf("%.*s.trace", (int) (last == NULL ? strlen(argv[2]) : last - argv[2]),argv[2]);
if (argc == 4)
tracefilename = xbt_strdup(argv[3]);
static double sg_host_get_available_at(sg_host_t host)
{
- HostAttribute attr = (HostAttribute)sg_host_data(host);
+ const struct _HostAttribute* attr = (HostAttribute)sg_host_data(host);
return attr->available_at;
}
}
static SD_task_t sg_host_get_last_scheduled_task( sg_host_t host){
- HostAttribute attr = (HostAttribute)sg_host_data(host);
+ const struct _HostAttribute* attr = (HostAttribute)sg_host_data(host);
return attr->last_scheduled_task;
}
SD_task_schedule(taskC, 2, host_list, computation_amount, communication_amount, -1);
SD_task_schedule(taskD, 2, host_list, computation_amount, communication_amount, -1);
- std::set<SD_task_t> *changed_tasks = simgrid::sd::simulate(-1.0);
+ const std::set<SD_task_t>* changed_tasks = simgrid::sd::simulate(-1.0);
for (auto const& task : *changed_tasks) {
XBT_INFO("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task),
SD_task_get_start_time(task), SD_task_get_finish_time(task));
XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->get_cname());
- std::string* msg1 = static_cast<std::string*>(mailbox->get());
- std::string* msg2 = static_cast<std::string*>(mailbox->get());
- std::string* msg3 = static_cast<std::string*>(mailbox->get());
+ const std::string* msg1 = static_cast<std::string*>(mailbox->get());
+ const std::string* msg2 = static_cast<std::string*>(mailbox->get());
+ const std::string* msg3 = static_cast<std::string*>(mailbox->get());
XBT_INFO("I received '%s', '%s' and '%s'", msg1->c_str(), msg2->c_str(), msg3->c_str());
delete msg1;
delete msg2;
void joinChain()
{
- ChainMessage* msg = static_cast<ChainMessage*>(me->get());
+ const ChainMessage* msg = static_cast<ChainMessage*>(me->get());
prev = msg->prev_;
next = msg->next_;
total_pieces = msg->num_pieces;
{
double compute_cost;
do {
- double* msg = static_cast<double*>(mailbox->get());
+ const double* msg = static_cast<double*>(mailbox->get());
compute_cost = *msg;
delete msg;
{
xbt_assert(args.size() == 1, "The worker expects no argument");
- simgrid::s4u::Host* my_host = simgrid::s4u::this_actor::get_host();
+ const simgrid::s4u::Host* my_host = simgrid::s4u::this_actor::get_host();
simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(my_host->get_name());
double compute_cost;
do {
- double* msg = static_cast<double*>(mailbox->get());
+ const double* msg = static_cast<double*>(mailbox->get());
compute_cost = *msg;
delete msg;
mailbox_out->put(payload, 1);
/* - ... then wait for the (large) pong */
- double* sender_time = static_cast<double*>(mailbox_in->get());
+ const double* sender_time = static_cast<double*>(mailbox_in->get());
double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
XBT_INFO("Task received : large communication (bandwidth bound)");
XBT_INFO("Pong from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str());
/* - Receive the (small) ping first ....*/
- double* sender_time = static_cast<double*>(mailbox_in->get());
+ const double* sender_time = static_cast<double*>(mailbox_in->get());
double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
XBT_INFO("Task received : small communication (latency bound)");
XBT_INFO(" Ping time (latency bound) %f", communication_time);
{
try {
rank = std::stoi(simgrid::s4u::this_actor::get_name());
- } catch (std::invalid_argument& ia) {
+ } catch (const std::invalid_argument& ia) {
throw std::invalid_argument(std::string("Processes of this example must have a numerical name, not ") +
ia.what());
}
XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->get_cname());
std::string msg = "Token";
neighbor_mailbox->put(&msg, task_comm_size);
- std::string* res = static_cast<std::string*>(my_mailbox->get());
+ const std::string* res = static_cast<std::string*>(my_mailbox->get());
XBT_INFO("Host \"%u\" received \"%s\"", rank, res->c_str());
} else {
std::string* res = static_cast<std::string*>(my_mailbox->get());
while (pending_finalize_messages > 0) {
if (my_mbox->ready()) {
double start = simgrid::s4u::Engine::get_clock();
- std::string* received = static_cast<std::string*>(my_mbox->get());
+ const std::string* received = static_cast<std::string*>(my_mbox->get());
double waiting_time = simgrid::s4u::Engine::get_clock() - start;
xbt_assert(waiting_time == 0, "Expecting the waiting time to be 0 because the communication was supposedly ready, but got %f instead", waiting_time);
XBT_INFO("I got a '%s'.", received->c_str());
XBT_INFO("Wait for my first message");
for (bool cont = true; cont;) {
- std::string* received = static_cast<std::string*>(mbox->get());
+ const std::string* received = static_cast<std::string*>(mbox->get());
XBT_INFO("I got a '%s'.", received->c_str());
if (*received == "finalize")
cont = false; // If it's a finalize message, we're done.
{
XBT_INFO("Wait for my first message");
for (bool cont = true; cont;) {
- std::string* received = static_cast<std::string*>(mbox->get());
+ const std::string* received = static_cast<std::string*>(mbox->get());
XBT_INFO("I got a '%s'.", received->c_str());
cont = (*received != "finalize"); // If it's a finalize message, we're done
// Receiving the message was all we were supposed to do
{
XBT_INFO("Wait for my first message");
for (bool cont = true; cont;) {
- std::string* received = static_cast<std::string*>(mbox->get());
+ const std::string* received = static_cast<std::string*>(mbox->get());
XBT_INFO("I got a '%s'.", received->c_str());
cont = (*received != "finalize"); // If it's a finalize message, we're done
// Receiving the message was all we were supposed to do
XBT_INFO("Wait for my first message");
for (bool cont = true; cont;) {
- std::string* received = static_cast<std::string*>(mbox->get());
+ const std::string* received = static_cast<std::string*>(mbox->get());
XBT_INFO("I got a '%s'.", received->c_str());
if (*received == "finalize")
cont = false; // If it's a finalize message, we're done.
static void vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm)
{
- simgrid::s4u::Host* src_pm = vm->get_pm();
+ const simgrid::s4u::Host* src_pm = vm->get_pm();
double mig_sta = simgrid::s4u::Engine::get_clock();
sg_vm_migrate(vm, dst_pm);
double mig_end = simgrid::s4u::Engine::get_clock();
const char* host_name = simgrid::s4u::this_actor::get_host()->get_cname();
simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(args.at(0));
- struct s_payload* payload = static_cast<struct s_payload*>(mbox->get());
+ const s_payload* payload = static_cast<struct s_payload*>(mbox->get());
double clock_end = simgrid::s4u::Engine::get_clock();
XBT_INFO("%s:%s to %s:%s => %g sec", payload->tx_host->get_cname(), payload->tx_actor_name, host_name, actor_name,
try {
comm->wait_for(timeout);
- ChordMessage* answer = static_cast<ChordMessage*>(data);
+ const ChordMessage* answer = static_cast<ChordMessage*>(data);
XBT_DEBUG("Received the answer to my 'Get Predecessor' request: the predecessor of node %d is %d", ask_to,
answer->answer_id);
predecessor_id = answer->answer_id;
try {
comm->wait_for(timeout);
- ChordMessage* answer = static_cast<ChordMessage*>(data);
+ const ChordMessage* answer = static_cast<ChordMessage*>(data);
XBT_DEBUG("Received the answer to my 'Find Successor' request for id %d: the successor of key %d is %d",
answer->request_id, id_, answer->answer_id);
successor = answer->answer_id;
namespace kademlia {
static void destroy(void* message)
{
- Message* msg = static_cast<Message*>(message);
+ const Message* msg = static_cast<Message*>(message);
delete msg->answer_;
delete msg;
}
*/
bool Node::join(unsigned int known_id)
{
- Answer* node_list;
+ const Answer* node_list;
unsigned int i;
bool got_answer = false;
static void wizard()
{
- simgrid::s4u::Host* fafard = simgrid::s4u::Host::by_name("Fafard");
+ const simgrid::s4u::Host* fafard = simgrid::s4u::Host::by_name("Fafard");
simgrid::s4u::Host* ginette = simgrid::s4u::Host::by_name("Ginette");
simgrid::s4u::Host* boivin = simgrid::s4u::Host::by_name("Boivin");
try {
exec->wait_for(3);
XBT_INFO("Execution complete");
- } catch (simgrid::TimeoutException&) {
+ } catch (const simgrid::TimeoutException&) {
XBT_INFO("Execution Timeout!");
}
try {
exec->wait_for(6);
XBT_INFO("Execution complete");
- } catch (simgrid::TimeoutException&) {
+ } catch (const simgrid::TimeoutException&) {
XBT_INFO("Execution Timeout!");
}
try {
exec->wait_for(2);
XBT_INFO("Parallel Execution complete");
- } catch (simgrid::TimeoutException&) {
+ } catch (const simgrid::TimeoutException&) {
XBT_INFO("Parallel Execution Timeout!");
}
}
simgrid::s4u::IoPtr activity = disk->write_async(size);
try {
activity->wait_for(0.5);
- } catch (simgrid::TimeoutException&) {
+ } catch (const simgrid::TimeoutException&) {
XBT_INFO("Asynchronous write: Timeout!");
}
/* - Attach some user data to disk1 */
XBT_INFO("*** Get/set data for storage element: Disk1 ***");
- std::string* data = static_cast<std::string*>(disk->get_data());
+ const std::string* data = static_cast<std::string*>(disk->get_data());
XBT_INFO("Get storage data: '%s'", data ? data->c_str() : "No user data");
// Test attaching some user data to the file
file->set_data(new std::string("777"));
- std::string* file_data = static_cast<std::string*>(file->get_data());
+ const std::string* file_data = static_cast<std::string*>(file->get_data());
XBT_INFO("User data attached to the file: %s", file_data->c_str());
delete file_data;
{
ensure_other_tid();
- std::string* payload = static_cast<std::string*>(simgrid::s4u::Mailbox::by_name("some mailbox")->get());
+ const std::string* payload = static_cast<std::string*>(simgrid::s4u::Mailbox::by_name("some mailbox")->get());
XBT_INFO("Task received");
delete payload;
}
int value_got = -1;
simgrid::s4u::Mailbox* mb = simgrid::s4u::Mailbox::by_name("server");
for (int count = 0; count < worker_amount; count++) {
- int* msg = static_cast<int*>(mb->get());
+ const int* msg = static_cast<int*>(mb->get());
value_got = *msg;
delete msg;
}
xbt_assert(argc == 2, "Expecting one parameter");
long id = xbt_str_parse_int(argv[1], "Invalid argument %s");
simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::string("worker-") + std::to_string(id));
- double* payload = nullptr;
+ const double* payload = nullptr;
double comp_size = -1;
while (1) {
try {
/* Main function of the Yielder process */
static void watcher()
{
- simgrid::s4u::Host* jupiter = simgrid::s4u::Host::by_name("Jupiter");
- simgrid::s4u::Host* fafard = simgrid::s4u::Host::by_name("Fafard");
- simgrid::s4u::Link* link1 = simgrid::s4u::Link::by_name("1");
- simgrid::s4u::Link* link2 = simgrid::s4u::Link::by_name("2");
+ const simgrid::s4u::Host* jupiter = simgrid::s4u::Host::by_name("Jupiter");
+ const simgrid::s4u::Host* fafard = simgrid::s4u::Host::by_name("Fafard");
+ const simgrid::s4u::Link* link1 = simgrid::s4u::Link::by_name("1");
+ const simgrid::s4u::Link* link2 = simgrid::s4u::Link::by_name("2");
for (int i = 0; i < 10; i++) {
XBT_INFO("Fafard: %.0fGflops, Jupiter: % 3.0fGflops, Link1: (%.2fMB/s %.0fms), Link2: (%.2fMB/s %.0fms)",
static void bob(std::vector<std::string> /*args*/)
{
/* this host also tests the properties of the AS*/
- simgrid::s4u::NetZone* root = simgrid::s4u::Engine::get_instance()->get_netzone_root();
+ const simgrid::s4u::NetZone* root = simgrid::s4u::Engine::get_instance()->get_netzone_root();
XBT_INFO("== Print the properties of the root zone");
XBT_INFO(" Zone property: filename -> %s", root->get_property("filename"));
XBT_INFO(" Zone property: date -> %s", root->get_property("date"));