Some remain and should be hunted down. atol and atof will follow.
<process host="Boivin" function="peer">
<argument value="00000002"/> <!-- my id -->
<argument value="5000" /> <!-- end time -->
- <argument value="1" /> <!-- indicates if the peer is a seed at the begining of the simulation -->
+ <argument value="1" /> <!-- indicates if the peer is a seed at the beginning of the simulation -->
</process>
<process host="Jean_Yves" function="peer">
<argument value="00000003"/> <!-- my id -->
<process host="Geoff" function="peer">
<argument value="00000005"/> <!-- my id -->
<argument value="5000" /> <!-- end time -->
- <argument value="1" /> <!-- indicates if the peer is a seed at the begining of the simulation -->
+ <argument value="1" /> <!-- indicates if the peer is a seed at the beginning of the simulation -->
</process>
<process host="Disney" function="peer">
<argument value="00000006"/> <!-- my id -->
xbt_assert(argc == 3 || argc == 4, "Wrong number of arguments");
//Build peer object
if (argc == 4) {
- peer_init(&peer, atoi(argv[1]), 1);
+ peer_init(&peer, xbt_str_parse_int(argv[1],"Invalid ID: %s"), 1);
} else {
- peer_init(&peer, atoi(argv[1]), 0);
+ peer_init(&peer, xbt_str_parse_int(argv[1],"Invalid ID: %s"), 0);
}
//Retrieve deadline
- double deadline = atof(argv[2]);
+ double deadline = xbt_str_parse_double(argv[2],"Invalid deadline: %s");
xbt_assert(deadline > 0, "Wrong deadline supplied");
XBT_INFO("Hi, I'm joining the network with id %d", peer.id);
//Getting peer data from the tracker.
XBT_DEBUG("broadcaster");
/* Add every mailbox given by the hostcount in argv[1] to a dynamic array */
- host_list = build_hostlist_from_hostcount(atoi(argv[1]));
+ host_list = build_hostlist_from_hostcount(xbt_str_parse_int(argv[1], "Invalid number of peers: %s"));
/* argv[2] is the number of pieces */
if (argc > 2) {
- piece_count = atoi(argv[2]);
+ piece_count = xbt_str_parse_int(argv[2], "Invalid number of pieces: %s");
XBT_DEBUG("piece_count set to %d", piece_count);
} else {
XBT_DEBUG("No piece_count specified, defaulting to %d", piece_count);
// initialize my node
s_node_t node = {0};
- node.id = atoi(argv[1]);
- node.stream =
- (RngStream)MSG_host_get_property_value(MSG_host_self(), "stream");
+ node.id = xbt_str_parse_int(argv[1],"Invalid ID: %s");
+ node.stream = (RngStream)MSG_host_get_property_value(MSG_host_self(), "stream");
get_mailbox(node.id, node.mailbox);
node.next_finger_to_fix = 0;
node.fingers = xbt_new0(s_finger_t, nb_bits);
}
if (argc == 3) { // first ring
- deadline = atof(argv[2]);
+ deadline = xbt_str_parse_double(argv[2],"Invalid deadline: %s");
create(&node);
join_success = 1;
- }
- else {
- int known_id = atoi(argv[2]);
+
+ } else {
+ int known_id = xbt_str_parse_int(argv[2],"Invalid root ID: %s");
//double sleep_time = atof(argv[3]);
- deadline = atof(argv[4]);
+ deadline = xbt_str_parse_double(argv[4],"Invalid deadline: %s");
/*
// sleep before starting
int length = strlen("-nb_bits=");
if (!strncmp(options[0], "-nb_bits=", length) && strlen(options[0]) > length) {
- nb_bits = atoi(options[0] + length);
+ nb_bits = xbt_str_parse_int(options[0] + length, "Invalid nb_bits parameter: %s");
XBT_DEBUG("Set nb_bits to %d", nb_bits);
}
else {
length = strlen("-timeout=");
if (!strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) {
- timeout = atoi(options[0] + length);
+ timeout = xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s");
XBT_DEBUG("Set timeout to %d", timeout);
}
else {
static int worker_main(int argc, char *argv[])
{
- double computation_amount = atof(argv[1]);
- int use_bound = atoi(argv[2]);
- double bound = atof(argv[3]);
+ double computation_amount = xbt_str_parse_double(argv[1], "Invalid computation amount: %s");
+ int use_bound = xbt_str_parse_int(argv[2], "Second parameter (use_bound) should be 0 or 1 but is: %s");
+ double bound = xbt_str_parse_double(argv[3], "Invalid bound: %s");
{
double clock_sta = MSG_get_clock();
msg_host_t src, dest;
src= MSG_host_self();
dest = MSG_host_by_name(argv[3]);
- if (atoi(argv[5])){
+ if (xbt_str_parse_int(argv[5], "Argument 5 (move or copy) must be an int, not '%s'")) {
XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename,
MSG_file_get_size(file), MSG_host_get_name(src),
argv[3]);
MSG_task_receive(&task, "mymailbox");
count++;
}
- MC_assert(atoi(MSG_task_get_name(task)) == 3);
+ MC_assert(xbt_str_parse_int(MSG_task_get_name(task), "Task names must be integers, not '%s'") == 3);
XBT_INFO("OK");
return 0;
int client(int argc, char *argv[])
{
- msg_task_t task1 =
- MSG_task_create("task", 0, 10000, (void *) atol(argv[1]));
- msg_task_t task2 =
- MSG_task_create("task", 0, 10000, (void *) atol(argv[1]));
+ int ID = xbt_str_parse_int(argv[1], "Arg 1 is not a numerical ID: %s");
+ msg_task_t task1 = MSG_task_create("task", 0, 10000, (void *) ID);
+ msg_task_t task2 = MSG_task_create("task", 0, 10000, (void *) ID);
- XBT_INFO("Send %d!", atoi(argv[1]));
+ XBT_INFO("Send %d!", ID);
MSG_task_send(task1, "mymailbox");
- XBT_INFO("Send %d!", atoi(argv[1]));
+ XBT_INFO("Send %d!", ID);
MSG_task_send(task2, "mymailbox");
return 0;
int client(int argc, char *argv[])
{
- msg_comm_t comm;
- char *mbox;
- msg_task_t task1 =
- MSG_task_create("task", 0, 10000, (void *) atol(argv[1]));
+ int ID = xbt_str_parse_int(argv[1], "Arg 1 is not a numerical ID: %s");
+ msg_task_t task1 = MSG_task_create("task", 0, 10000, (void *) ID);
- mbox = bprintf("mymailbox%s", argv[1]);
+ char *mbox = bprintf("mymailbox%s", argv[1]);
- XBT_INFO("Send %d!", atoi(argv[1]));
- comm = MSG_task_isend(task1, mbox);
+ XBT_INFO("Send %d!", ID);
+ msg_comm_t comm = MSG_task_isend(task1, mbox);
MSG_comm_wait(comm, -1);
xbt_free(mbox);
MSG_create_environment("platform.xml");
MSG_function_register("server", server);
-
MSG_function_register("client", client);
-
MSG_launch_application("deploy_bugged3.xml");
MSG_main();
/** master */
int master(int argc, char *argv[])
{
- double task_comm_size = 0;
msg_task_t todo;
xbt_assert(argc==4,"Strange number of arguments expected 3 got %d", argc - 1);
XBT_DEBUG ("Master started");
/* data size */
- int read;
- read = sscanf(argv[1], "%lg", &task_comm_size);
- xbt_assert(read, "Invalid argument %s\n", argv[1]);
+ double task_comm_size = xbt_str_parse_double(argv[1], "Invalid task communication size: %s");
/* slave name */
char *slavename = argv[2];
- int id = atoi(argv[3]); //unique id to control statistics
+ int id = xbt_str_parse_int(argv[3], "Invalid ID as argument 3: %s"); //unique id to control statistics
char *id_alias = bprintf("flow_%d", id);
slavenames[id] = slavename;
TRACE_category(id_alias);
}
{ /* Process organization */
- MSG_get_host_by_name(slavename);
+ MSG_host_by_name(slavename);
}
count_finished++;
XBT_DEBUG ("Slave started");
- id = atoi(argv[1]);
+ id = xbt_str_parse_int(argv[1], "Invalid id: %s");
sprintf(id_alias, "%d", id);
a = MSG_task_receive(&(task), id_alias);
double deadline;
xbt_assert(argc == 3 || argc == 5, "Wrong number of arguments for this node");
s_node_t node = {0};
- node.id = atoi(argv[1]);
+ node.id = xbt_str_parse_int(argv[1], "Invalid ID: %s");
node.known_id = -1;
node.ready = -1;
node.pending_tasks = xbt_fifo_new();
if (argc == 3) { // first ring
XBT_DEBUG("Hey! Let's create the system.");
- deadline = atof(argv[2]);
+ deadline = xbt_str_parse_double(argv[2], "Invalid deadline: %s");
create(&node);
join_success = 1;
}
else {
- node.known_id = atoi(argv[2]);
- double sleep_time = atof(argv[3]);
- deadline = atof(argv[4]);
+ node.known_id = xbt_str_parse_int(argv[2], "Invalid known ID: %s");
+ double sleep_time = xbt_str_parse_double(argv[3], "Invalid sleep time: %s");
+ deadline = xbt_str_parse_double(argv[4], "Invalid deadline: %s");
// sleep before starting
XBT_DEBUG("Let's sleep during %f", sleep_time);
int length = strlen("-nb_bits=");
if (!strncmp(options[0], "-nb_bits=", length) && strlen(options[0]) > length) {
- nb_bits = atoi(options[0] + length);
+ nb_bits = xbt_str_parse_int(options[0] + length, "Invalid nb_bits parameter: %s");
XBT_DEBUG("Set nb_bits to %d", nb_bits);
}
else {
length = strlen("-timeout=");
if (!strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) {
- timeout = atoi(options[0] + length);
+ timeout = xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s");
XBT_DEBUG("Set timeout to %d", timeout);
}
else {
xbt_assert(argc != 1, "Wrong number of arguments for this node");
/* Initialize the node's data-structures */
- myid = atoi(argv[1]);
+ myid = xbt_str_parse_int(argv[1], "Invalid ID received as first node parameter: %s");
snprintf(my_mbox, MAILBOX_NAME_SIZE - 1, "%d", myid);
sC = xbt_matrix_double_new_zeros(NODE_MATRIX_SIZE, NODE_MATRIX_SIZE);
XBT_INFO("Hello! I go to sleep.");
MSG_process_on_exit(my_onexit, NULL);
- MSG_process_sleep(atoi(argv[1]));
+ MSG_process_sleep(xbt_str_parse_int(argv[1], "sleeper process expects an integer parameter but got %s"));
XBT_INFO("Done sleeping.");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include "simgrid/msg.h"
-#include "src/surf/surf_private.h"
int host(int argc, char *argv[]);
unsigned int task_comp_size = 50000000;
int host(int argc, char *argv[])
{
- int host_number = atoi(MSG_process_get_name(MSG_process_self()));
+ int host_number = xbt_str_parse_int(MSG_process_get_name(MSG_process_self()), "Process name must be an integer but is: %s");
char mailbox[256];
msg_task_t task = NULL;
XBT_ATTRIB_UNUSED int res;
" -M I M size (default: %zu)\n"
" -N I N size (default: %zu)\n"
" -K I K size (default: %zu)\n"
- " -B I Block size on the k dimension(default: %zu)\n"
- " -G I Number of processor groups(default: %zu)\n"
- " -g I group index(default: %zu)\n"
- " -k I group rank(default: %zu)\n"
+ " -B I Block size on the k dimension (default: %zu)\n"
+ " -G I Number of processor groups (default: %zu)\n"
+ " -g I group index (default: %zu)\n"
+ " -k I group rank (default: %zu)\n"
" -r I processor row size (default: %zu)\n"
" -c I processor col size (default: %zu)\n"
" -h help\n",
m, n, k, Block_size, NB_groups, group, key, row, col);
return 0;
case 'M':
- m = atoi(optarg);
+ m = xbt_str_parse_int(optarg, "Invalid M size: %s");
break;
case 'N':
- n = atoi(optarg);
+ n = xbt_str_parse_int(optarg, "Invalid N size: %s");
break;
case 'K':
- k = atoi(optarg);
+ k = xbt_str_parse_int(optarg, "Invalid K size: %s");
break;
case 'B':
- Block_size = atoi(optarg);
+ Block_size = xbt_str_parse_int(optarg, "Invalid block size: %s");
break;
case 'G':
- NB_groups = atoi(optarg);
+ NB_groups = xbt_str_parse_int(optarg, "Invalid number of processor groups: %s");
break;
case 'g':
- group = atoi(optarg);
+ group = xbt_str_parse_int(optarg, "Invalid group index: %s");
break;
case 'k':
- key = atoi(optarg);
+ key = xbt_str_parse_int(optarg, "Invalid group rank: %s");
break;
case 'r':
- size_row = atoi(optarg);
+ size_row = xbt_str_parse_int(optarg, "Invalid processor row size: %s");
break;
case 'c':
- size_col = atoi(optarg);
+ size_col = xbt_str_parse_int(optarg, "Invalid processor col size: %s");
break;
/*case 'P':
str_mask = strdup(optarg);
exit(USAGE_ERROR);
}
- N = atoi(argv[1]);
+ N = xbt_str_parse_int(argv[1], "Invalid size: %s");
start_time = (struct timeval *) malloc(sizeof(struct timeval));
stop_time = (struct timeval *) malloc(sizeof(struct timeval));
const char** line_char= xbt_dynar_to_array(elems);
instance_id = line_char[0];
- instance_size = atoi(line_char[2]);
+ instance_size = xbt_str_parse_int(line_char[2], "Invalid size: %s");
XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size);
SMPI_app_instance_register(instance_id, smpi_replay,instance_size);
exit(EXIT_FAILURE);
}
-
- size = atoi(argv[1]);
+ size = xbt_str_parse_int(argv[1], "Invalid size: %s");
/* create a new scheduler */
sched = sched_new(size);
__argv = xbt_new0(char *, MAX_ARGS);
for (i = 0; i < MAX_ARGS; i++) {
- sprintf(arg, "arg_%d", i);
- __argv[i] = strdup(arg);
- memset(arg, 0, MAX_ARG);
-
+ __argv[i] = bprintf("arg_%d", i);
}
for (i = 0; i < size; i++)
nb_ids = xbt_dynar_length(id_list);
id_ar = xbt_new0(int,nb_ids);
xbt_dynar_foreach(id_list, iter, id_str) {
- id_ar[iter] = atoi(id_str);
+ id_ar[iter] = xbt_str_parse_int(id_str, "Parse error: not a number: %s");
}
qsort (id_ar, nb_ids, sizeof(int), &compare_ids);
struct dirent* fd_number;
while ((fd_number = readdir(fd_dir))) {
- int fd_value = atoi(fd_number->d_name);
+ int fd_value = xbt_str_parse_int(fd_number->d_name, "Found a non-numerical FD: %s. Freaking out!");
if(fd_value < 3)
continue;
if (!fd_env)
xbt_die("MC socket not found");
- int fd = atoi(fd_env);
+ int fd = xbt_str_parse_int(fd_env,bprintf("Variable %s should contain a number but contains '%%s'", MC_ENV_SOCKET_FD));
XBT_DEBUG("Model-checked application found socket FD %i", fd);
int type;
//FIXME: dirty cleanup method to avoid using msg cleanup functions on these processes when using MSG+SMPI
SIMIX_process_set_cleanup_function(proc, SIMIX_process_cleanup);
char* instance_id = (*argv)[1];
- int rank = atoi((*argv)[2]);
+ int rank = xbt_str_parse_int((*argv)[2], "Invalid rank: %s");
index = smpi_process_index_of_smx_process(proc);
if(!index_to_process_data){
int smpi_global_size(void)
{
char *value = getenv("SMPI_GLOBAL_SIZE");
+ xbt_assert(value,"Please set env var SMPI_GLOBAL_SIZE to the expected number of processes.");
- if (!value) {
- fprintf(stderr,
- "Please set env var SMPI_GLOBAL_SIZE to expected number of processes.\n");
- xbt_abort();
- }
- return atoi(value);
+ return xbt_str_parse_int(value, "SMPI_GLOBAL_SIZE contains a non-numerical value: %s");
}
smpi_process_data_t smpi_process_data(void)
}
// The first parts of topo_parameters should be the levels number
- this->levels = std::atoi(parameters[0].c_str()); // stoi() only in C++11...
+ this->levels = xbt_str_parse_int(parameters[0].c_str(), "First parameter is not the amount of levels: %s");
// Then, a l-sized vector standing for the childs number by level
boost::split(tmp, parameters[1], boost::is_any_of(","));
", see the documentation for more informations");
}
for(size_t i = 0 ; i < tmp.size() ; i++){
- this->lowerLevelNodesNumber.push_back(std::atoi(tmp[i].c_str()));
+ this->lowerLevelNodesNumber.push_back(xbt_str_parse_int(tmp[i].c_str(), "Invalid lower level node number: %s"));
}
// Then, a l-sized vector standing for the parents number by level
", see the documentation for more informations");
}
for(size_t i = 0 ; i < tmp.size() ; i++){
- this->upperLevelNodesNumber.push_back(std::atoi(tmp[i].c_str()));
+ this->upperLevelNodesNumber.push_back(xbt_str_parse_int(tmp[i].c_str(), "Invalid upper level node number: %s"));
}
// Finally, a l-sized vector standing for the ports number with the lower level
}
for(size_t i = 0 ; i < tmp.size() ; i++){
- this->lowerLevelPortsNumber.push_back(std::atoi(tmp[i].c_str()));
+ this->lowerLevelPortsNumber.push_back(xbt_str_parse_int(tmp[i].c_str(), "Invalid lower level node number: %s"));
}
this->cluster = cluster;
}