Commit a01e9e7e authored by MERCIER Michael's avatar MERCIER Michael
parents ee135ac9 84dc211b
......@@ -37,7 +37,7 @@ static int job_launcher(int argc, char *argv[])
xbt_dynar_foreach(jobs_dynar, job_index, job)
{
int t = MSG_get_clock();
int * res_idxs = (int *) malloc((job->nb_res) * sizeof(int));
int * res_idxs = xbt_new(int, job->nb_res);
for (int i = 0; i < job->nb_res; i++)
res_idxs[i] = i;
......
......@@ -105,7 +105,7 @@ static char *recv_uds()
read(uds_fd, &lg, 4);
//XBT_INFO("Received message length: %d bytes", lg);
xbt_assert(lg > 0, "Invalid message received (size=%d)", lg);
msg = (char *) malloc(sizeof(char)*(lg+1)); /* +1 for null terminator */
msg = xbt_new(char, lg+1); /* +1 for null terminator */
read(uds_fd, msg, lg);
msg[lg] = 0;
XBT_CINFO(network, "Received '%s'", msg);
......@@ -199,7 +199,7 @@ static int requestReplyScheduler(int argc, char *argv[])
for (int i = 1; i < answerParts; ++i)
{
char * eventString = *(char **) xbt_dynar_get_ptr(answer_dynar, i);
xbt_dynar_t * eventDynar = malloc(sizeof(xbt_dynar_t));
xbt_dynar_t * eventDynar = xbt_new(xbt_dynar_t, 1);
*eventDynar = xbt_str_split(eventString, ":");
int eventParts = xbt_dynar_length(*eventDynar);
xbt_assert(eventParts >= 2, "Invalid event received ('%s'): it should be composed of at least 2 parts separated by a ':'", eventString);
......@@ -232,7 +232,7 @@ static int requestReplyScheduler(int argc, char *argv[])
void send_message(const char *dst, e_task_type_t type, int job_id, void *data)
{
msg_task_t task_sent;
s_task_data_t * req_data = malloc(sizeof(s_task_data_t));
s_task_data_t * req_data = xbt_new(s_task_data_t, 1);
req_data->type = type;
req_data->job_id = job_id;
req_data->data = data;
......@@ -345,7 +345,8 @@ static int node(int argc, char *argv[])
s_launch_data_t * launchData = (s_launch_data_t *) task_data->data;
char * launcherName = 0;
asprintf(&launcherName, "launcher %d", launchData->jobID);
int ret = asprintf(&launcherName, "launcher %d", launchData->jobID);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
MSG_process_create(launcherName, launch_job, launchData, MSG_host_self());
free(launcherName);
......@@ -422,9 +423,9 @@ int server(int argc, char *argv[])
int k;
xbt_assert(schedMessageMaxLength > 0);
char *sched_message = malloc(sizeof(char) * (schedMessageMaxLength+1)); // + 1 for NULL-terminated
char *sched_message = xbt_new(char, schedMessageMaxLength+1); // + 1 for NULL-terminated
xbt_assert(sched_message != NULL, "Cannot allocate the send message buffer (requested bytes: %d)", schedMessageMaxLength+1);
snprintf(sched_message, schedMessageMaxLength, "");
sched_message[0] = '\0'; // Empties the string
int lg_sched_message = 0;
// it may avoid the SG deadlock...
......@@ -527,7 +528,7 @@ int server(int argc, char *argv[])
XBT_INFO("head node: %s, id: %d", MSG_host_get_name(nodes[head_node]), head_node);
// Let's create a launch data structure, which will be given to the head_node then used to launch the job
s_launch_data_t * launchData = (s_launch_data_t*) malloc(sizeof(s_launch_data_t));
s_launch_data_t * launchData = xbt_new(s_launch_data_t, 1);
launchData->jobID = jobID;
launchData->reservedNodeCount = xbt_dynar_length(res_dynar);
......@@ -535,7 +536,7 @@ int server(int argc, char *argv[])
"Invalid scheduling algorithm decision: allocation of job %d is done on %d nodes (instead of %d)",
launchData->jobID, launchData->reservedNodeCount, job->nb_res);
launchData->reservedNodesIDs = (int*) malloc(launchData->reservedNodeCount * sizeof(int));
launchData->reservedNodesIDs = xbt_new(int, launchData->reservedNodeCount);
// Let's fill the reserved node IDs from the XBT dynar
xbt_dynar_foreach(res_dynar, j, res_str)
......@@ -568,7 +569,7 @@ int server(int argc, char *argv[])
int strSize = 0;
char * buf = xbt_new(char, bufSize+1);
xbt_assert(sizeof(char) == 1);
sprintf(buf, "");
buf[0] = '\0'; // Empties the string
s_job_t * job;
unsigned int job_index;
......@@ -578,7 +579,8 @@ int server(int argc, char *argv[])
if (job->state == JOB_STATE_SUBMITTED)
{
char * tmp;
asprintf(&tmp, ",%d", job->id);
int ret = asprintf(&tmp, ",%d", job->id);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
strncat(buf, tmp, max(0,bufSize - strSize));
strSize += strlen(tmp);
......@@ -624,8 +626,9 @@ int server(int argc, char *argv[])
{
char * sendBuf;
asprintf(&sendBuf, "0:%f%s", MSG_get_clock(), sched_message);
sprintf(sched_message, "");
int ret = asprintf(&sendBuf, "0:%f%s", MSG_get_clock(), sched_message);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
sched_message[0] = '\0'; // empties the string
lg_sched_message = 0;
MSG_process_create("Sched REQ-REP", requestReplyScheduler, sendBuf, MSG_host_self());
......@@ -691,7 +694,8 @@ msg_error_t deploy_all(const char *platform_file, const char * masterHostName, c
{
XBT_INFO("Create node process %d !", i);
char * pname = NULL;
asprintf(&pname, "node %d", i);
int ret = asprintf(&pname, "node %d", i);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
MSG_process_create(pname, node, NULL, host);
free(pname);
}
......@@ -759,7 +763,8 @@ static int parse_opt (int key, char *arg, struct argp_state *state)
if (mainArgs->connectDelay < 100 || mainArgs->connectDelay > 10000)
{
mainArgs->abort = 1;
asprintf(&tmp, "\n invalid connection delay (%lf): it must be in [100,10000] ms", mainArgs->connectDelay);
int ret = asprintf(&tmp, "\n invalid connection delay (%lf): it must be in [100,10000] ms", mainArgs->connectDelay);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
strcat(mainArgs->abortReason, tmp);
free(tmp);
}
......@@ -778,7 +783,8 @@ static int parse_opt (int key, char *arg, struct argp_state *state)
if (mainArgs->nbConnectTries < 1)
{
mainArgs->abort = 1;
asprintf(&tmp, "\n invalid number of connection tries (%d): it must be greater than or equal to 1", mainArgs->nbConnectTries);
int ret = asprintf(&tmp, "\n invalid number of connection tries (%d): it must be greater than or equal to 1", mainArgs->nbConnectTries);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
strcat(mainArgs->abortReason, tmp);
free(tmp);
}
......@@ -791,7 +797,8 @@ static int parse_opt (int key, char *arg, struct argp_state *state)
if (access(mainArgs->platformFilename, R_OK) == -1)
{
mainArgs->abort = 1;
asprintf(&tmp, "\n invalid PLATFORM_FILE argument: file '%s' cannot be read", mainArgs->platformFilename);
int ret = asprintf(&tmp, "\n invalid PLATFORM_FILE argument: file '%s' cannot be read", mainArgs->platformFilename);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
strcat(mainArgs->abortReason, tmp);
free(tmp);
}
......@@ -801,7 +808,8 @@ static int parse_opt (int key, char *arg, struct argp_state *state)
if (access(mainArgs->workloadFilename, R_OK) == -1)
{
mainArgs->abort = 1;
asprintf(&tmp, "\n invalid WORKLOAD_FILE argument: file '%s' cannot be read", mainArgs->workloadFilename);
int ret = asprintf(&tmp, "\n invalid WORKLOAD_FILE argument: file '%s' cannot be read", mainArgs->workloadFilename);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
strcat(mainArgs->abortReason, tmp);
free(tmp);
}
......@@ -842,8 +850,8 @@ int main(int argc, char *argv[])
mainArgs.masterHostName = "master_host";
mainArgs.exportPrefix = "out";
mainArgs.abort = 0;
mainArgs.abortReason = malloc(4096);
sprintf(mainArgs.abortReason, "");
mainArgs.abortReason = xbt_new(char, 4096);
mainArgs.abortReason[0] = '\0'; // Empties the string
struct argp_option options[] =
{
......@@ -886,9 +894,12 @@ int main(int argc, char *argv[])
char * csvJobsFilename;
char * csvScheduleFilename;
asprintf(&pajeFilename, "%s_schedule.trace", mainArgs.exportPrefix);
asprintf(&csvJobsFilename, "%s_jobs.csv", mainArgs.exportPrefix);
asprintf(&csvScheduleFilename, "%s_schedule.csv", mainArgs.exportPrefix);
int ret = asprintf(&pajeFilename, "%s_schedule.trace", mainArgs.exportPrefix);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
ret = asprintf(&csvJobsFilename, "%s_jobs.csv", mainArgs.exportPrefix);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
ret = asprintf(&csvScheduleFilename, "%s_schedule.csv", mainArgs.exportPrefix);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
msg_error_t res = deploy_all(mainArgs.platformFilename, mainArgs.masterHostName, pajeFilename, csvJobsFilename, csvScheduleFilename);
......
......@@ -14,11 +14,11 @@ WriteBuffer * writeBuffer_create(const char * filename, int bufferSize)
{
xbt_assert(bufferSize > 0, "Invalid buffer size (%d)", bufferSize);
WriteBuffer * wbuf = (WriteBuffer*) malloc(sizeof(WriteBuffer));
WriteBuffer * wbuf = xbt_new(WriteBuffer, 1);
wbuf->f = fopen(filename, "w");
wbuf->bufferSize = bufferSize;
wbuf->buffer = (char *) malloc(sizeof(char) * bufferSize);
wbuf->buffer = xbt_new0(char, bufferSize);
wbuf->bufferPos = 0;
xbt_assert(wbuf->f != NULL, "Cannot write file '%s'", filename);
......@@ -126,7 +126,7 @@ PajeTracer * pajeTracer_create(const char * filename, int logLaunchings, int col
xbt_assert(logLaunchings == 0 || logLaunchings == 1, "logLaunchings must be either 0 or 1");
xbt_assert(colorCount > 0);
PajeTracer * tracer = (PajeTracer *) malloc(sizeof(PajeTracer));
PajeTracer * tracer = xbt_new(PajeTracer, 1);
xbt_assert(tracer != NULL);
tracer->state = PAJE_STATE_UNINITIALIZED;
......@@ -373,13 +373,13 @@ void pajeTracer_private_generateColors(PajeTracer * tracer, int colorCount)
double h, s=1, v=1, r, g, b;
const int bufSize = 32;
tracer->colors = (char**) malloc(colorCount * sizeof(char *));
tracer->colors = xbt_new(char*, colorCount);
xbt_assert(tracer->colors != NULL);
double hueFraction = 360.0 / colorCount;
for (int i = 0; i < colorCount; ++i)
{
tracer->colors[i] = (char*) malloc(bufSize * sizeof(char));
tracer->colors[i] = xbt_new(char, bufSize);
xbt_assert(tracer->colors[i] != NULL);
h = i * hueFraction;
......@@ -596,7 +596,7 @@ void exportJobsToCSV(const char *filename)
if (job->state == JOB_STATE_COMPLETED_SUCCESSFULLY || job->state == JOB_STATE_COMPLETED_KILLED)
{
int success = job->state == JOB_STATE_COMPLETED_SUCCESSFULLY;
asprintf(&buf, "%d,%lf,%d,%lf,%d,%lf,%lf,%lf,%lf,%lf,%lf,", job->id,
int ret = asprintf(&buf, "%d,%lf,%d,%lf,%d,%lf,%lf,%lf,%lf,%lf,%lf,", job->id,
job->submission_time,
job->nb_res,
job->walltime,
......@@ -608,18 +608,21 @@ void exportJobsToCSV(const char *filename)
job->startingTime + job->runtime - job->submission_time, // turnaround_time
(job->startingTime + job->runtime - job->submission_time) / job->runtime // stretch
);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
fputs(buf, f);
free(buf);
if (job->nb_res > 0)
{
asprintf(&buf, "%d", job->alloc_ids[0]);
int ret = asprintf(&buf, "%d", job->alloc_ids[0]);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
fputs(buf, f);
free(buf);
for (int i = 1; i < job->nb_res; ++i)
{
asprintf(&buf," %d", job->alloc_ids[i]);
ret = asprintf(&buf," %d", job->alloc_ids[i]);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
fputs(buf, f);
free(buf);
}
......@@ -690,10 +693,11 @@ void exportScheduleToCSV(const char *filename, double scheduling_time)
}
}
asprintf(&buf, "%d,%d,%d,%d,%lf,%lf,%lf,%lf,%lf\n",
int ret = asprintf(&buf, "%d,%d,%d,%d,%lf,%lf,%lf,%lf,%lf\n",
nb_jobs, nb_jobs_finished, nb_jobs_success, nb_jobs_killed,
(double)nb_jobs_success/nb_jobs, makespan, max_turnaround_time,
scheduling_time, max_job_execution_time / min_job_execution_time);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
fputs(buf, f);
free(buf);
......
......@@ -63,8 +63,8 @@ int profile_exec(const char *profile_str, int job_id, int nb_res, msg_host_t *jo
if (strcmp(profile->type, "msg_par") == 0)
{
// These amounts are deallocated by SG
computation_amount = malloc(nb_res * sizeof(double));
communication_amount = malloc(nb_res * nb_res * sizeof(double));
computation_amount = xbt_new(double, nb_res);
communication_amount = xbt_new(double, nb_res * nb_res);
double *cpu = ((s_msg_par_t *)(profile->data))->cpu;
double *com = ((s_msg_par_t *)(profile->data))->com;
......@@ -73,7 +73,8 @@ int profile_exec(const char *profile_str, int job_id, int nb_res, msg_host_t *jo
memcpy(communication_amount, com, nb_res * nb_res * sizeof(double));
char * tname = NULL;
asprintf(&tname, "p %d", job_id);
int ret = asprintf(&tname, "p %d", job_id);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
XBT_INFO("Creating task '%s'", tname);
ptask = MSG_parallel_task_create(tname,
......@@ -83,7 +84,7 @@ int profile_exec(const char *profile_str, int job_id, int nb_res, msg_host_t *jo
free(tname);
// Let's spawn a process which will wait until walltime and cancel the task if needed
KillerDelayData * killData = malloc(sizeof(KillerDelayData));
KillerDelayData * killData = xbt_new(KillerDelayData, 1);
killData->task = ptask;
killData->walltime = *remainingTime;
......@@ -94,7 +95,7 @@ int profile_exec(const char *profile_str, int job_id, int nb_res, msg_host_t *jo
msg_error_t err = MSG_parallel_task_execute(ptask);
*remainingTime = *remainingTime - (MSG_get_clock() - timeBeforeExecute);
int ret = 1;
ret = 1;
if (err == MSG_OK)
SIMIX_process_throw(killProcess, cancel_error, 0, "wake up");
else if (err == MSG_TASK_CANCELED)
......@@ -113,8 +114,8 @@ int profile_exec(const char *profile_str, int job_id, int nb_res, msg_host_t *jo
double com = ((s_msg_par_hg_t *)(profile->data))->com;
// These amounts are deallocated by SG
computation_amount = malloc(nb_res * sizeof(double));
communication_amount = malloc(nb_res * nb_res * sizeof(double));
computation_amount = xbt_new(double, nb_res);
communication_amount = xbt_new(double, nb_res * nb_res);
//XBT_DEBUG("msg_par_hg: nb_res: %d , cpu: %f , com: %f", nb_res, cpu, com);
......@@ -126,7 +127,8 @@ int profile_exec(const char *profile_str, int job_id, int nb_res, msg_host_t *jo
communication_amount[nb_res * j + i] = com;
char * tname = NULL;
asprintf(&tname, "hg %d", job_id);
int ret = asprintf(&tname, "hg %d", job_id);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
XBT_INFO("Creating task '%s'", tname);
ptask = MSG_parallel_task_create(tname,
......@@ -136,7 +138,7 @@ int profile_exec(const char *profile_str, int job_id, int nb_res, msg_host_t *jo
free(tname);
// Let's spawn a process which will wait until walltime and cancel the task if needed
KillerDelayData * killData = malloc(sizeof(KillerDelayData));
KillerDelayData * killData = xbt_new(KillerDelayData, 1);
killData->task = ptask;
killData->walltime = *remainingTime;
......@@ -147,7 +149,7 @@ int profile_exec(const char *profile_str, int job_id, int nb_res, msg_host_t *jo
msg_error_t err = MSG_parallel_task_execute(ptask);
*remainingTime = *remainingTime - (MSG_get_clock() - timeBeforeExecute);
int ret = 1;
ret = 1;
if (err == MSG_OK)
SIMIX_process_throw(killProcess, cancel_error, 0, "wake up");
else if (err == MSG_TASK_CANCELED)
......@@ -206,7 +208,7 @@ int job_exec(int job_id, int nb_res, int *res_idxs, msg_host_t *nodes, double wa
s_job_t * job = jobFromJobID(job_id);
//XBT_INFO("job_exec: jobID %d, job=%p", job_id, job);
msg_host_t * job_res = (msg_host_t *) malloc(nb_res * sizeof(s_msg_host_t));
msg_host_t * job_res = (msg_host_t *) xbt_new(s_msg_host_t, nb_res);
for(int i = 0; i < nb_res; i++)
job_res[i] = nodes[res_idxs[i]];
......
......@@ -98,7 +98,8 @@ void retrieve_jobs(json_t *root)
job->id = json_integer_value(tmp);
xbt_assert(job->id >= 0, "Invalid JSON file: a job has a negative id (%d)", job->id);
xbt_assert(!jobExists(job->id), "Invalid JSON file: duplication of job %d", job->id);
asprintf(&(job->id_str), "%d", job->id);
int ret = asprintf(&(job->id_str), "%d", job->id);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
// submission time
tmp = json_object_get(j, "subtime");
......@@ -122,7 +123,8 @@ void retrieve_jobs(json_t *root)
tmp = json_object_get(j, "profile");
xbt_assert(tmp != NULL, "Invalid job %d from JSON file: it does not have a 'profile' field.", job->id);
xbt_assert(json_typeof(tmp) == JSON_STRING, "Invalid job %d from JSON file: its 'profile' field must be a string", job->id);
asprintf(&(job->profile), "%s", json_string_value(tmp));
ret = asprintf(&(job->profile), "%s", json_string_value(tmp));
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
job->startingTime = -1;
job->runtime = -1;
......@@ -172,14 +174,15 @@ void retrieve_profiles(json_t *root)
xbt_assert(!profileExists(key), "Invalid JSON file: many profile share the name '%s'", key);
j_profile = json_object_iter_value(iter);
profile = (profile_t) malloc(sizeof(s_profile_t));
profile = xbt_new(s_profile_t, 1);
xbt_dict_set(profiles, key, profile, freeProfile);
const json_t * typeObject = json_object_get(j_profile, "type");
xbt_assert(typeObject != NULL, "The profile '%s' has no 'type' field", key);
xbt_assert(json_typeof(typeObject) == JSON_STRING, "The profile '%s' has a non-textual 'type' field", key);
char * type;
asprintf(&type, "%s", json_string_value(typeObject));
int ret = asprintf(&type, "%s", json_string_value(typeObject));
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
profile->type = type;
profile->data = NULL;
......@@ -257,7 +260,8 @@ void retrieve_profiles(json_t *root)
{
json_t * elem = json_array_get(e,i);
xbt_assert(json_is_string(elem), "Invalid 'seq' field of the composed profile '%s': all its elements must be strings", key);
asprintf(&(seq[i]), "%s", json_string_value(elem));
ret = asprintf(&(seq[i]), "%s", json_string_value(elem));
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
}
composed->lg_seq = lg_seq;
......@@ -377,7 +381,8 @@ void freeJobStructures()
int jobExists(int jobID)
{
char * jobName;
asprintf(&jobName, "%d", jobID);
int ret = asprintf(&jobName, "%d", jobID);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
int * dynarPosition = (int *) xbt_dict_get_or_null(job_id_to_dynar_pos, jobName);
free(jobName);
......@@ -388,7 +393,8 @@ int jobExists(int jobID)
s_job_t * jobFromJobID(int jobID)
{
char * jobName;
asprintf(&jobName, "%d", jobID);
int ret = asprintf(&jobName, "%d", jobID);
xbt_assert(ret != -1, "asprintf failed (not enough memory?)");
int * dynarPosition = (int *) xbt_dict_get_or_null(job_id_to_dynar_pos, jobName);
xbt_assert(dynarPosition != NULL, "Invalid call: jobID %d does NOT exist", jobID);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment