}
}
-void Peer::sendHandshake(simgrid::s4u::MailboxPtr mailbox)
+void Peer::sendMessage(simgrid::s4u::MailboxPtr mailbox, e_message_type type, uint64_t size)
{
- XBT_DEBUG("Sending a HANDSHAKE to %s", mailbox->getName());
- mailbox->put_init(new Message(MESSAGE_HANDSHAKE, id, mailbox_), MESSAGE_HANDSHAKE_SIZE)->detach();
+ const char* type_names[6] = {"HANDSHAKE", "CHOKE", "UNCHOKE", "INTERESTED", "NOTINTERESTED", "CANCEL"};
+ XBT_DEBUG("Sending %s to %s", type_names[type], mailbox->getName());
+ mailbox->put_init(new Message(type, id, bitfield_, mailbox_), size)->detach();
}
void Peer::sendBitfield(simgrid::s4u::MailboxPtr mailbox)
->detach();
}
-void Peer::sendInterested(simgrid::s4u::MailboxPtr mailbox)
-{
- XBT_DEBUG("Sending INTERESTED to %s", mailbox->getName());
- mailbox->put_init(new Message(MESSAGE_INTERESTED, id, bitfield_, mailbox_), MESSAGE_INTERESTED_SIZE)->detach();
-}
-
-void Peer::sendNotInterested(simgrid::s4u::MailboxPtr mailbox)
-{
- XBT_DEBUG("Sending NOTINTERESTED to %s", mailbox->getName());
- mailbox->put_init(new Message(MESSAGE_NOTINTERESTED, id, bitfield_, mailbox_), MESSAGE_NOTINTERESTED_SIZE)->detach();
-}
-
-void Peer::sendChoked(simgrid::s4u::MailboxPtr mailbox)
-{
- XBT_DEBUG("Sending CHOKE to %s", mailbox->getName());
- mailbox->put_init(new Message(MESSAGE_CHOKE, id, mailbox_), MESSAGE_CHOKE_SIZE)->detach();
-}
-
-/** Send a "unchoked" message to a peer */
-void Peer::sendUnchoked(simgrid::s4u::MailboxPtr mailbox)
-{
- XBT_DEBUG("Sending UNCHOKE to %s", mailbox->getName());
- mailbox->put_init(new Message(MESSAGE_UNCHOKE, id, mailbox_), MESSAGE_UNCHOKE_SIZE)->detach();
-}
-
void Peer::sendPiece(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length)
{
- xbt_assert(!hasNotPiece(piece), "Tried to send a unavailable piece.");
+ xbt_assert(not hasNotPiece(piece), "Tried to send a unavailable piece.");
XBT_DEBUG("Sending the PIECE %u (%d,%d) to %s", piece, block_index, block_length, mailbox->getName());
mailbox->put_init(new Message(MESSAGE_PIECE, id, mailbox_, piece, block_index, block_length), BLOCK_SIZE)->detach();
}
-void Peer::sendRequest(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length)
-{
- XBT_DEBUG("Sending a REQUEST to %s for piece %u (%d,%d)", mailbox->getName(), piece, block_index, block_length);
- mailbox->put_init(new Message(MESSAGE_REQUEST, id, mailbox_, piece, block_index, block_length), MESSAGE_REQUEST_SIZE)
- ->detach();
-}
-
void Peer::sendHaveToAllPeers(unsigned int piece)
{
XBT_DEBUG("Sending HAVE message to all my peers");
int block_index = getFirstMissingBlockFrom(piece);
if (block_index != -1) {
int block_length = MIN(BLOCKS_REQUESTED, PIECES_BLOCKS - block_index);
- sendRequest(remote_peer->mailbox_, piece, block_index, block_length);
+ XBT_DEBUG("Sending a REQUEST to %s for piece %u (%d,%d)", remote_peer->mailbox_->getName(), piece, block_index,
+ block_length);
+ remote_peer->mailbox_
+ ->put_init(new Message(MESSAGE_REQUEST, id, mailbox_, piece, block_index, block_length), MESSAGE_REQUEST_SIZE)
+ ->detach();
}
}
return remote_peer->bitfield & (bitfield_ ^ ((1 << FILE_PIECES) - 1));
}
+bool Peer::isInterestedByFree(Connection* remote_peer)
+{
+ for (unsigned int i = 0; i < FILE_PIECES; i++)
+ if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i))
+ return true;
+ return false;
+}
+
void Peer::updatePiecesCountFromBitfield(unsigned int bitfield)
{
for (unsigned int i = 0; i < FILE_PIECES; i++)
void Peer::updateActivePeersSet(Connection* remote_peer)
{
- if (remote_peer->interested && not remote_peer->choked_upload) {
- // add in the active peers set
+ if (remote_peer->interested && not remote_peer->choked_upload)
active_peers.insert(remote_peer);
- } else if (active_peers.find(remote_peer) != active_peers.end()) {
+ else
active_peers.erase(remote_peer);
- }
}
void Peer::handleMessage()
auto known_peer = connected_peers.find(message->peer_id);
Connection* remote_peer = (known_peer == connected_peers.end()) ? nullptr : known_peer->second;
+ xbt_assert(remote_peer != nullptr || message->type == MESSAGE_HANDSHAKE,
+ "The impossible did happened: A not-in-our-list peer sent us a message.");
+
switch (message->type) {
case MESSAGE_HANDSHAKE:
// Check if the peer is in our connection list.
if (remote_peer == nullptr) {
XBT_DEBUG("This peer %d was unknown, answer to its handshake", message->peer_id);
connected_peers[message->peer_id] = new Connection(message->peer_id);
- sendHandshake(message->return_mailbox);
+ sendMessage(message->return_mailbox, MESSAGE_HANDSHAKE, MESSAGE_HANDSHAKE_SIZE);
}
// Send our bitfield to the peer
sendBitfield(message->return_mailbox);
updatePiecesCountFromBitfield(message->bitfield);
// Store the bitfield
remote_peer->bitfield = message->bitfield;
- xbt_assert(!remote_peer->am_interested, "Should not be interested at first");
+ xbt_assert(not remote_peer->am_interested, "Should not be interested at first");
if (isInterestedBy(remote_peer)) {
remote_peer->am_interested = true;
- sendInterested(message->return_mailbox);
+ sendMessage(message->return_mailbox, MESSAGE_INTERESTED, MESSAGE_INTERESTED_SIZE);
}
break;
case MESSAGE_INTERESTED:
- xbt_assert((remote_peer != nullptr), "The impossible did happened: A not-in-our-list peer sent us a message.");
// Update the interested state of the peer.
remote_peer->interested = true;
updateActivePeersSet(remote_peer);
break;
case MESSAGE_NOTINTERESTED:
- xbt_assert((remote_peer != nullptr), "The impossible did happened: A not-in-our-list peer sent us a message.");
remote_peer->interested = false;
updateActivePeersSet(remote_peer);
break;
case MESSAGE_UNCHOKE:
- xbt_assert((remote_peer != nullptr), "The impossible did happened: A not-in-our-list peer sent us a message.");
xbt_assert(remote_peer->choked_download);
remote_peer->choked_download = false;
// Send requests to the peer, since it has unchoked us
- // if (remote_peer->am_interested)
- requestNewPieceTo(remote_peer);
+ if (remote_peer->am_interested)
+ requestNewPieceTo(remote_peer);
break;
case MESSAGE_CHOKE:
- xbt_assert((remote_peer != nullptr), "The impossible did happened: A not-in-our-list peer sent us a message.");
xbt_assert(not remote_peer->choked_download);
remote_peer->choked_download = true;
if (remote_peer->current_piece != -1)
// If the piece is in our pieces, we tell the peer that we are interested.
if (not remote_peer->am_interested && hasNotPiece(message->piece)) {
remote_peer->am_interested = true;
- sendInterested(message->return_mailbox);
+ sendMessage(message->return_mailbox, MESSAGE_INTERESTED, MESSAGE_INTERESTED_SIZE);
if (not remote_peer->choked_download)
requestNewPieceTo(remote_peer);
}
message->block_index + message->block_length);
xbt_assert(not remote_peer->choked_download);
xbt_assert(remote_peer->am_interested || ENABLE_END_GAME_MODE,
- "Can't received a piece if I'm not interested wihtout end-game mode!"
+ "Can't received a piece if I'm not interested without end-game mode!"
"piece (%d) bitfield (%u) remote bitfield (%u)",
message->piece, bitfield_, remote_peer->bitfield);
xbt_assert(not remote_peer->choked_download, "Can't received a piece if I'm choked !");
int current_index = 0;
// compute the smallest number of copies of available pieces
for (unsigned int i = 0; i < FILE_PIECES; i++) {
- if (pieces_count[i] < min)
- if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i))
- min = pieces_count[i];
+ if (pieces_count[i] < min && hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i))
+ min = pieces_count[i];
}
xbt_assert(min != SHRT_MAX || not isInterestedByFree(remote_peer));
if (choked_peer != chosen_peer) {
if (choked_peer != nullptr) {
- xbt_assert((!choked_peer->choked_upload), "Tries to choked a choked peer");
+ xbt_assert(not choked_peer->choked_upload, "Tries to choked a choked peer");
choked_peer->choked_upload = true;
updateActivePeersSet(choked_peer);
XBT_DEBUG("(%d) Sending a CHOKE to %d", id, choked_peer->id);
- sendChoked(choked_peer->mailbox_);
+ sendMessage(choked_peer->mailbox_, MESSAGE_CHOKE, MESSAGE_CHOKE_SIZE);
}
if (chosen_peer != nullptr) {
xbt_assert((chosen_peer->choked_upload), "Tries to unchoked an unchoked peer");
chosen_peer->last_unchoke = simgrid::s4u::Engine::getClock();
XBT_DEBUG("(%d) Sending a UNCHOKE to %d", id, chosen_peer->id);
updateActivePeersSet(chosen_peer);
- sendUnchoked(chosen_peer->mailbox_);
+ sendMessage(chosen_peer->mailbox_, MESSAGE_UNCHOKE, MESSAGE_UNCHOKE_SIZE);
}
}
}
if (not interested) { // no more piece to download from connection
remote_peer->am_interested = false;
- sendNotInterested(remote_peer->mailbox_);
+ sendMessage(remote_peer->mailbox_, MESSAGE_NOTINTERESTED, MESSAGE_NOTINTERESTED_SIZE);
}
}
}
bool Peer::hasCompletedPiece(unsigned int piece)
{
for (unsigned int i = 0; i < PIECES_BLOCKS; i++)
- if (!(bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i)))
+ if (not(bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i)))
return false;
return true;
}
return -1;
}
-bool Peer::isInterestedByFree(Connection* remote_peer)
-{
- for (unsigned int i = 0; i < FILE_PIECES; i++)
- if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i))
- return true;
- return false;
-}
-
/** Returns a piece that is partially downloaded and stored by the remote peer if any -1 otherwise. */
int Peer::partiallyDownloadedPiece(Connection* remote_peer)
{
bool choked_upload = true; // Indicates if the peer is choked for the current peer
bool choked_download = true; // Indicates if the peer has choked the current peer
- Connection(int id) : id(id), mailbox_(simgrid::s4u::Mailbox::byName(std::to_string(id))){};
+ explicit Connection(int id) : id(id), mailbox_(simgrid::s4u::Mailbox::byName(std::to_string(id))){};
~Connection() = default;
void addSpeedValue(double speed) { peer_speed = peer_speed * 0.6 + speed * 0.4; }
bool hasPiece(unsigned int piece) { return bitfield & 1U << piece; }
double deadline;
RngStream stream;
simgrid::s4u::MailboxPtr mailbox_;
+ std::unordered_map<int, Connection*> connected_peers;
std::set<Connection*> active_peers; // active peers list
unsigned int bitfield_ = 0; // list of pieces the peer has.
double begin_receive_time = 0; // time when the receiving communication has begun, useful for calculating host speed.
int round_ = 0; // current round for the chocking algorithm.
- std::unordered_map<int, Connection*> connected_peers;
simgrid::s4u::CommPtr comm_received = nullptr; // current comm
Message* message = nullptr; // current message being received
public:
void requestNewPieceTo(Connection* remote_peer);
bool getPeersFromTracker();
- void sendHandshake(simgrid::s4u::MailboxPtr mailbox);
+ void sendMessage(simgrid::s4u::MailboxPtr mailbox, e_message_type type, uint64_t size);
void sendBitfield(simgrid::s4u::MailboxPtr mailbox);
void sendPiece(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length);
- void sendInterested(simgrid::s4u::MailboxPtr mailbox);
- void sendChoked(simgrid::s4u::MailboxPtr mailbox);
- void sendUnchoked(simgrid::s4u::MailboxPtr mailbox);
- void sendNotInterested(simgrid::s4u::MailboxPtr mailbox);
void sendHandshakeToAllPeers();
- void sendRequest(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length);
void sendHaveToAllPeers(unsigned int piece);
void sendRequestTo(Connection* remote_peer, unsigned int piece);
simgrid::s4u::this_actor::sleep_for(1);
}
}
- // TODO See if some cleanup is needed
XBT_INFO("Tracker is leaving");
}
public:
explicit Tracker(std::vector<std::string> args);
+ Tracker(const Tracker&) = delete;
void operator()();
};
XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", (std::string("Task_") + std::to_string(i)).c_str(),
number_of_tasks, mailbox->getName());
- /* - Send the task to the @ref worker */
- char* payload = bprintf("%f", comp_size);
- mailbox->put(payload, comm_size);
+ /* - Send the computation amount to the @ref worker */
+ mailbox->put(static_cast<void*>(&comp_size), comm_size);
}
XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over.");
for (int i = 0; i < workers_count; i++) {
/* - Eventually tell all the workers to stop by sending a "finalize" task */
mailbox = simgrid::s4u::Mailbox::byName(std::string("worker-") + std::to_string(i % workers_count));
- mailbox->put(xbt_strdup("finalize"), 0);
+ double finalize = -1;
+ mailbox->put(static_cast<void*>(&finalize), 0);
}
+ simgrid::s4u::this_actor::sleep_for(.1); // Grace time to ensure everyone finishes.
}
};
void operator()()
{
while (1) { /* The worker waits in an infinite loop for tasks sent by the \ref master */
- char* res = static_cast<char*>(mailbox->get());
- xbt_assert(res != nullptr, "MSG_task_get failed");
-
- if (strcmp(res, "finalize") == 0) { /* - Exit if 'finalize' is received */
- xbt_free(res);
+ double* comp_size = static_cast<double*>(mailbox->get());
+ xbt_assert(comp_size != nullptr, "MSG_task_get failed");
+ if (*comp_size < 0) { /* - Exit if 'finalize' is received */
+ XBT_INFO("I'm done. See you!");
break;
}
/* - Otherwise, process the task */
- double comp_size = std::stod(res);
- xbt_free(res);
- simgrid::s4u::this_actor::execute(comp_size);
+ simgrid::s4u::this_actor::execute(*comp_size);
}
- XBT_INFO("I'm done. See you!");
}
};
> [ 4.057541] (worker@Jupiter) I'm done. See you!
> [ 4.083249] (worker@Fafard) I'm done. See you!
> [ 4.931805] (worker@Ginette) I'm done. See you!
-> [ 5.094868] (maestro@) Simulation time 5.09487
> [ 5.094868] (worker@Bourassa) I'm done. See you!
+> [ 5.194868] (maestro@) Simulation time 5.19487
#include "jmsg.h"
#include <simgrid/msg.h>
+#include <string>
+
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
SG_BEGIN_DECL()
}
if (not comm) {
- jxbt_throw_null(env, bprintf("comm is null"));
+ jxbt_throw_null(env, "comm is null");
return JNI_FALSE;
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, jobject jcomm, jdouble timeout) {
msg_comm_t comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
if (not comm) {
- jxbt_throw_null(env, bprintf("comm is null"));
+ jxbt_throw_null(env, "comm is null");
return;
}
comms[i] = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
if (not comms[i]) {
- jxbt_throw_null(env, bprintf("comm at rank %d is null", i));
+ jxbt_throw_null(env, std::string("comm at rank ") + std::to_string(i) + " is null");
return nullptr;
}
/* get the C string from the java string */
if (jname == nullptr) {
- jxbt_throw_null(env,bprintf("No host can have a null name"));
+ jxbt_throw_null(env, "No host can have a null name");
return nullptr;
}
const char *name = env->GetStringUTFChars(jname, 0);
/* get the C string from the java string */
if (jname == nullptr) {
- jxbt_throw_null(env,bprintf("No host can have a null name"));
+ jxbt_throw_null(env, "No host can have a null name");
return nullptr;
}
const char *name = env->GetStringUTFChars(jname, 0);
/* get the C string from the java string */
if (jname == nullptr) {
- jxbt_throw_null(env, bprintf("No VM can have a null name"));
+ jxbt_throw_null(env, "No VM can have a null name");
return nullptr;
}
const char* name = env->GetStringUTFChars(jname, 0);
this->nodesByLevel_[0] *= this->lowerLevelNodesNumber_[i];
if (this->nodesByLevel_[0] != this->nodes_.size()) {
- surf_parse_error("The number of provided nodes does not fit with the wanted topology."
- " Please check your platform description (We need %u nodes, we got %zu)",
- this->nodesByLevel_[0], this->nodes_.size());
+ surf_parse_error(std::string("The number of provided nodes does not fit with the wanted topology.") +
+ " Please check your platform description (We need " + std::to_string(this->nodesByLevel_[0]) +
+ "nodes, we got " + std::to_string(this->nodes_.size()));
return;
}
char *pr_rx_name = get_mig_process_rx_name(vm, src_pm, dst_pm);
char *pr_tx_name = get_mig_process_tx_name(vm, src_pm, dst_pm);
- char** argv = xbt_new(char*, 2);
- argv[0] = pr_rx_name;
- argv[1] = nullptr;
- MSG_process_create_with_arguments(pr_rx_name, migration_rx_fun, ms, dst_pm, 1, argv);
-
- argv = xbt_new(char*, 2);
- argv[0] = pr_tx_name;
- argv[1] = nullptr;
- MSG_process_create_with_arguments(pr_tx_name, migration_tx_fun, ms, src_pm, 1, argv);
+ MSG_process_create(pr_rx_name, migration_rx_fun, ms, dst_pm);
+
+ MSG_process_create(pr_tx_name, migration_tx_fun, ms, src_pm);
/* wait until the migration have finished or on error has occurred */
XBT_DEBUG("wait for reception of the final ACK (i.e. migration has been correctly performed");
std::unordered_map<std::string, local_data_t*> samples; /* Allocated on first use */
-static char *sample_location(int global, const char *file, int line) {
+static std::string sample_location(int global, const char* file, int line)
+{
if (global) {
- return bprintf("%s:%d", file, line);
+ return std::string(file) + ":" + std::to_string(line);
} else {
- return bprintf("%s:%d:%d", file, line, smpi_process()->index());
+ return std::string(file) + ":" + std::to_string(line) + ":" + std::to_string(smpi_process()->index());
}
}
void smpi_sample_1(int global, const char *file, int line, int iters, double threshold)
{
- char *loc = sample_location(global, file, line);
+ std::string loc = sample_location(global, file, line);
smpi_bench_end(); /* Take time from previous, unrelated computation into account */
smpi_process()->set_sampling(1);
data->benching = 1; // If we have no data, we need at least one
data->mean = 0;
samples[loc] = data;
- XBT_DEBUG("XXXXX First time ever on benched nest %s.",loc);
+ XBT_DEBUG("XXXXX First time ever on benched nest %s.", loc.c_str());
} else {
data = ld->second;
if (data->iters != iters || data->threshold != threshold) {
XBT_ERROR("Asked to bench block %s with different settings %d, %f is not %d, %f. "
"How did you manage to give two numbers at the same line??",
- loc, data->iters, data->threshold, iters, threshold);
+ loc.c_str(), data->iters, data->threshold, iters, threshold);
THROW_IMPOSSIBLE;
}
// if we already have some data, check whether sample_2 should get one more bench or whether it should emulate
// the computation instead
data->benching = (sample_enough_benchs(data) == 0);
- XBT_DEBUG("XXXX Re-entering the benched nest %s. %s", loc,
+ XBT_DEBUG("XXXX Re-entering the benched nest %s. %s", loc.c_str(),
(data->benching ? "more benching needed" : "we have enough data, skip computes"));
}
- xbt_free(loc);
}
int smpi_sample_2(int global, const char *file, int line)
{
- char *loc = sample_location(global, file, line);
+ std::string loc = sample_location(global, file, line);
int res;
xbt_assert(not samples.empty(),
"Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
local_data_t* data = samples.at(loc);
- XBT_DEBUG("sample2 %s",loc);
- xbt_free(loc);
+ XBT_DEBUG("sample2 %s", loc.c_str());
if (data->benching==1) {
// we need to run a new bench
void smpi_sample_3(int global, const char *file, int line)
{
- char *loc = sample_location(global, file, line);
+ std::string loc = sample_location(global, file, line);
xbt_assert(not samples.empty(),
"Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
local_data_t* data = samples.at(loc);
- XBT_DEBUG("sample3 %s",loc);
- xbt_free(loc);
+ XBT_DEBUG("sample3 %s", loc.c_str());
if (data->benching==0)
THROW_IMPOSSIBLE;
auto as_cluster = static_cast<simgrid::kernel::routing::ClusterZone*>(current_routing);
if (as_cluster->privateLinks_.find(netpoint->id()) != as_cluster->privateLinks_.end())
- surf_parse_error("Host_link for '%s' is already defined!",hostlink->id);
+ surf_parse_error(std::string("Host_link for '") + hostlink->id + "' is already defined!");
XBT_DEBUG("Push Host_link for host '%s' to position %u", netpoint->cname(), netpoint->id());
as_cluster->privateLinks_.insert({netpoint->id(), {linkUp, linkDown}});
for (auto s : *simgrid::surf::StorageImpl::storagesMap()) {
simgrid::kernel::routing::NetPoint* host_elm = sg_netpoint_by_name_or_null(s.second->getHost().c_str());
if (not host_elm)
- surf_parse_error("Unable to attach storage %s: host %s does not exist.", s.second->cname(),
- s.second->getHost().c_str());
+ surf_parse_error(std::string("Unable to attach storage ") + s.second->cname() + ": host " + s.second->getHost() +
+ " does not exist.");
else
s.second->piface_.attached_to_ = sg_host_by_name(s.second->getHost().c_str());
}
XBT_PUBLIC(void) surf_parse_open(const char *file);
XBT_PUBLIC(void) surf_parse_close();
-XBT_PUBLIC(void) surf_parse_assert(bool cond, const char *fmt, ...) XBT_ATTRIB_PRINTF(2,3);
-XBT_PUBLIC(void) XBT_ATTRIB_NORETURN surf_parse_error(const char *msg,...) XBT_ATTRIB_PRINTF(1,2);
+XBT_PUBLIC(void) surf_parse_assert(bool cond, std::string msg);
+XBT_PUBLIC(void) XBT_ATTRIB_NORETURN surf_parse_error(std::string msg);
XBT_PUBLIC(void) surf_parse_assert_netpoint(char* hostname, const char* pre, const char* post);
XBT_PUBLIC(void) surf_parse_warn(const char *msg,...) XBT_ATTRIB_PRINTF(1,2);
trace_connect_list_link_lat.insert({trace_connect->trace, trace_connect->element});
break;
default:
- surf_parse_error("Cannot connect trace %s to %s: kind of trace unknown", trace_connect->trace,
- trace_connect->element);
+ surf_parse_error(std::string("Cannot connect trace ") + trace_connect->trace + " to " + trace_connect->element +
+ ": unknown kind of trace");
break;
}
}
surf_parse_close();
if (parse_status)
- surf_parse_error("Parse error in %s", file);
+ surf_parse_error(std::string("Parse error in ") + file);
}
}
/*
* Helping functions
*/
-void surf_parse_assert(bool cond, const char *fmt, ...) {
+void surf_parse_assert(bool cond, std::string msg)
+{
if (not cond) {
- va_list va;
- va_start(va,fmt);
int lineno = surf_parse_lineno;
- char *msg = bvprintf(fmt,va);
- va_end(va);
cleanup();
- XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
+ XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
surf_exit();
xbt_die("Exiting now");
}
}
-void surf_parse_error(const char *fmt, ...) {
- va_list va;
- va_start(va,fmt);
+void surf_parse_error(std::string msg)
+{
int lineno = surf_parse_lineno;
- char *msg = bvprintf(fmt,va);
- va_end(va);
cleanup();
- XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
+ XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
surf_exit();
xbt_die("Exiting now");
}
+
void surf_parse_assert_netpoint(char* hostname, const char* pre, const char* post)
{
if (sg_netpoint_by_name_or_null(hostname) != nullptr) // found
break;
}
}
- surf_parse_error("%s", msg.c_str());
+ surf_parse_error(msg);
}
void surf_parse_warn(const char *fmt, ...) {
double res;
int ret = sscanf(string, "%lg", &res);
if (ret != 1)
- surf_parse_error("%s is not a double", string);
+ surf_parse_error(std::string(string) + " is not a double");
return res;
}
int res;
int ret = sscanf(string, "%d", &res);
if (ret != 1)
- surf_parse_error("%s is not an integer", string);
+ surf_parse_error(std::string(string) + " is not an integer");
return res;
}
end = surf_parse_get_int((radical_ends.back()).c_str());
break;
default:
- surf_parse_error("Malformed radical: %s", group.c_str());
+ surf_parse_error(std::string("Malformed radical: ") + group);
break;
}
for (int i = start; i <= end; i++)
errno = 0;
double res = strtod(string, &ptr);
if (errno == ERANGE)
- surf_parse_error("value out of range: %s", string);
+ surf_parse_error(std::string("value out of range: ") + string);
if (ptr == string)
- surf_parse_error("cannot parse number: %s", string);
+ surf_parse_error(std::string("cannot parse number:") + string);
if (ptr[0] == '\0') {
if (res == 0)
return res; // Ok, 0 can be unit-less
if (units[i].unit != nullptr)
res *= units[i].scale;
else
- surf_parse_error("unknown unit: %s", ptr);
+ surf_parse_error(std::string("unknown unit: ") + ptr);
return res;
}
cluster.topology= SURF_CLUSTER_DRAGONFLY ;
break;
default:
- surf_parse_error("Invalid cluster topology for cluster %s",
- cluster.id);
+ surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
break;
}
cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
cluster.sharing_policy = SURF_LINK_FATPIPE;
break;
default:
- surf_parse_error("Invalid cluster sharing policy for cluster %s", cluster.id);
+ surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
break;
}
switch (AX_surfxml_cluster_bb___sharing___policy) {
cluster.bb_sharing_policy = SURF_LINK_SHARED;
break;
default:
- surf_parse_error("Invalid bb sharing policy in cluster %s", cluster.id);
+ surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
break;
}
link.policy = SURF_LINK_FULLDUPLEX;
break;
default:
- surf_parse_error("Invalid sharing policy in link %s", link.id.c_str());
+ surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
break;
}
link = simgrid::surf::LinkImpl::byName(link_name);
break;
default:
- surf_parse_error("Invalid direction for link %s", link_name);
+ surf_parse_error(std::string("Invalid direction for link ") + link_name);
break;
}
xbt_free(link_name); // no-op if it's already nullptr
default:
dirname = "";
}
- surf_parse_assert(link != nullptr, "No such link: '%s'%s", A_surfxml_link___ctn_id, dirname);
+ surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
parsed_link_list.push_back(link);
}
XBT_INFO("Sender spec: %s", args[0].c_str());
for (unsigned int test = 1; test <= args[0].size(); test++) {
this_actor::sleep_until(test * 5 - 5);
- char* mboxName = bprintf("Test #%u", test);
+ const char* mboxName = (std::string("Test #") + std::to_string(test)).c_str();
simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName);
switch (args[0][test - 1]) {
XBT_INFO("Receiver spec: %s", args[0].c_str());
for (unsigned int test = 1; test <= args[0].size(); test++) {
this_actor::sleep_until(test * 5 - 5);
- char* mboxName = bprintf("Test #%u", test);
+ const char* mboxName = (std::string("Test #") + std::to_string(test)).c_str();
simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName);
void* received = nullptr;
}
xbt_assert(strcmp(static_cast<char*>(received), mboxName) == 0);
- xbt_free(received);
- xbt_free(mboxName);
XBT_INFO("Test %u OK", test);
}
simgrid::s4u::this_actor::sleep_for(0.5);