Skip to content
Snippets Groups Projects
Commit 27f8f56c authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Print date and time in front of messages and errors

parent 82950d54
Branches
Tags
2 merge requests!136Master,!107Code timing and verbosity
......@@ -83,7 +83,8 @@ double clocks_diff(struct clocks_time *start, struct clocks_time *end) {
}
return (double)temp.tv_sec * 1000.0 + (double)temp.tv_nsec * 1.0E-6;
#else
return elapsed(end->time, start->time) / clocks_get_cpufreq() * clocks_units_scale;
return elapsed(end->time, start->time) / clocks_get_cpufreq() *
clocks_units_scale;
#endif
}
......@@ -219,6 +220,20 @@ double clocks_from_ticks(ticks tics) {
*
* @result the current time units.
*/
const char *clocks_getunit() {
return clocks_units[clocks_units_index];
const char *clocks_getunit() { return clocks_units[clocks_units_index]; }
const char *clocks_get_timeofday() {
struct timeval time;
struct tm *local_time;
static char buffer[40];
/* Get the local time of day */
gettimeofday(&time, NULL);
local_time = localtime(&time.tv_sec);
/* Make it a string */
strftime(buffer, 40, "[%F %T]", local_time);
return buffer;
}
......@@ -39,5 +39,6 @@ void clocks_set_cpufreq(unsigned long long freq);
unsigned long long clocks_get_cpufreq();
double clocks_from_ticks(ticks tics);
double clocks_diff_ticks(ticks tic, ticks toc);
const char *clocks_get_timeofday();
#endif /* SWIFT_CLOCKS_H */
......@@ -1116,7 +1116,8 @@ int engine_marktasks(struct engine *e) {
}
}
// message( "took %.3f %s." , clocks_from_ticks(getticks() - tic), clocks_getunit());
// message( "took %.3f %s." , clocks_from_ticks(getticks() - tic),
// clocks_getunit());
/* All is well... */
return 0;
......@@ -1142,10 +1143,11 @@ void engine_print(struct engine *e) {
else
counts[task_type_count] += 1;
#ifdef WITH_MPI
printf("[%03i] engine_print: task counts are [ %s=%i", e->nodeID,
taskID_names[0], counts[0]);
printf("[%03i] %s engine_print: task counts are [ %s=%i", e->nodeID,
clocks_get_timeofday(), taskID_names[0], counts[0]);
#else
printf("engine_print: task counts are [ %s=%i", taskID_names[0], counts[0]);
printf("%s engine_print: task counts are [ %s=%i", clocks_get_timeofday(),
taskID_names[0], counts[0]);
#endif
for (k = 1; k < task_type_count; k++)
printf(" %s=%i", taskID_names[k], counts[k]);
......@@ -1167,29 +1169,29 @@ void engine_rebuild(struct engine *e) {
/* Re-build the space. */
// tic = getticks();
space_rebuild(e->s, 0.0, e->nodeID == 0);
// message( "space_rebuild took %.3f %s." ,
//clocks_from_ticks(getticks() - tic), clocks_getunit());
// message( "space_rebuild took %.3f %s." ,
// clocks_from_ticks(getticks() - tic), clocks_getunit());
/* If in parallel, exchange the cell structure. */
#ifdef WITH_MPI
// tic = getticks();
engine_exchange_cells(e);
// message( "engine_exchange_cells took %.3f %s." ,
//clocks_from_ticks(getticks() - tic), clocks_getunit());
// message( "engine_exchange_cells took %.3f %s." ,
// clocks_from_ticks(getticks() - tic), clocks_getunit());
#endif
/* Re-build the tasks. */
// tic = getticks();
engine_maketasks(e);
// message( "engine_maketasks took %.3f %s." ,
//clocks_from_ticks(getticks() - tic), clocks_getunit());
// clocks_from_ticks(getticks() - tic), clocks_getunit());
/* Run through the tasks and mark as skip or not. */
// tic = getticks();
if (engine_marktasks(e))
error("engine_marktasks failed after space_rebuild.");
// message( "engine_marktasks took %.3f %s." ,
//clocks_from_ticks(getticks() - tic), clocks_getunit());
// clocks_from_ticks(getticks() - tic), clocks_getunit());
/* Print the status of the system */
engine_print(e);
......@@ -1210,8 +1212,8 @@ void engine_prepare(struct engine *e) {
/* Run through the tasks and mark as skip or not. */
// tic = getticks();
rebuild = (e->forcerebuild || engine_marktasks(e));
// message( "space_marktasks took %.3f %s." ,
//clocks_from_ticks(getticks() - tic), clocks_getunit());
// message( "space_marktasks took %.3f %s." ,
// clocks_from_ticks(getticks() - tic), clocks_getunit());
/* Collect the values of rebuild from all nodes. */
#ifdef WITH_MPI
......@@ -1221,8 +1223,8 @@ void engine_prepare(struct engine *e) {
MPI_SUCCESS)
error("Failed to aggregate the rebuild flag across nodes.");
rebuild = buff;
// message( "rebuild allreduce took %.3f %s." ,
//clocks_from_ticks(getticks() - tic), clocks_getunit());
// message( "rebuild allreduce took %.3f %s." ,
// clocks_from_ticks(getticks() - tic), clocks_getunit());
#endif
e->tic_step = getticks();
......@@ -1231,7 +1233,7 @@ void engine_prepare(struct engine *e) {
// tic = getticks();
engine_rebuild(e);
// message( "engine_rebuild took %.3f %s." ,
//clocks_from_ticks(getticks() - tic), clocks_getunit());
// clocks_from_ticks(getticks() - tic), clocks_getunit());
}
/* Re-rank the tasks every now and then. */
......@@ -1239,7 +1241,7 @@ void engine_prepare(struct engine *e) {
// tic = getticks();
scheduler_reweight(&e->sched);
// message( "scheduler_reweight took %.3f %s." ,
//clocks_from_ticks(getticks() -tic), clocks_getunit());
// clocks_from_ticks(getticks() -tic), clocks_getunit());
}
e->tasks_age += 1;
......@@ -1625,7 +1627,7 @@ void engine_step(struct engine *e) {
clocks_gettime(&time2);
e->wallclock_time = (float) clocks_diff(&time1, &time2);
e->wallclock_time = (float)clocks_diff(&time1, &time2);
// printParticle(e->s->parts, e->s->xparts,1000, e->s->nr_parts);
// printParticle(e->s->parts, e->s->xparts,515050, e->s->nr_parts);
}
......@@ -1874,9 +1876,10 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
if (nodeID == 0) {
#ifdef WITH_MPI
printf("[%03i] engine_init: cpu map is [ ", nodeID);
printf("[%03i] %s engine_init: cpu map is [ ", nodeID,
clocks_get_timeofday());
#else
printf("engine_init: cpu map is [ ");
printf("%s engine_init: cpu map is [ ", clocks_get_timeofday());
#endif
for (i = 0; i < nr_cores; i++) printf("%i ", cpuid[i]);
printf("].\n");
......@@ -2082,16 +2085,17 @@ void engine_print_policy(struct engine *e) {
#ifdef WITH_MPI
if (e->nodeID == 0) {
printf("[000] engine_policy: engine policies are [ ");
printf("[000] %s engine_policy: engine policies are [ ",
clocks_get_timeofday());
for (int k = 1; k < 32; k++)
if (e->policy & (1 << k)) printf(" %s,", engine_policy_names[k + 1]);
if (e->policy & (1 << k)) printf(" %s ", engine_policy_names[k + 1]);
printf(" ]\n");
fflush(stdout);
}
#else
printf("engine_policy: engine policies are [ ");
printf("%s engine_policy: engine policies are [ ", clocks_get_timeofday());
for (int k = 1; k < 32; k++)
if (e->policy & (1 << k)) printf(" %s,", engine_policy_names[k + 1]);
if (e->policy & (1 << k)) printf(" %s ", engine_policy_names[k + 1]);
printf(" ]\n");
fflush(stdout);
#endif
......
......@@ -24,6 +24,8 @@
/* Some standard headers. */
#include <stdio.h>
#include "clocks.h"
/* MPI headers. */
#ifdef WITH_MPI
#include <mpi.h>
......@@ -35,18 +37,18 @@
*/
#ifdef WITH_MPI
extern int engine_rank;
#define error(s, ...) \
{ \
fprintf(stderr, "[%04i] %s:%s():%i: " s "\n", engine_rank, __FILE__, \
__FUNCTION__, __LINE__, ##__VA_ARGS__); \
MPI_Abort(MPI_COMM_WORLD, -1); \
}
#else
#define error(s, ...) \
{ \
fprintf(stderr, "%s:%s():%i: " s "\n", __FILE__, __FUNCTION__, __LINE__, \
##__VA_ARGS__); \
abort(); \
fprintf(stderr, "[%04i] %s %s:%s():%i: " s "\n", clocks_get_timeofday(), \
engine_rank, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
MPI_Abort(MPI_COMM_WORLD, -1); \
}
#else
#define error(s, ...) \
{ \
fprintf(stderr, "%s %s:%s():%i: " s "\n", clocks_get_timeofday(), \
__FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
abort(); \
}
#endif
......@@ -56,25 +58,27 @@ extern int engine_rank;
* followed by the MPI error string and aborts.
*
*/
#define mpi_error(res, s, ...) \
{ \
fprintf(stderr, "[%04i] %s:%s():%i: " s "\n", engine_rank, __FILE__, \
__FUNCTION__, __LINE__, ##__VA_ARGS__); \
int len = 1024; \
char buf[len]; \
MPI_Error_string(res, buf, &len); \
fprintf(stderr, "%s\n\n", buf); \
MPI_Abort(MPI_COMM_WORLD, -1); \
#define mpi_error(res, s, ...) \
{ \
fprintf(stderr, "[%04i] %s %s:%s():%i: " s "\n", engine_rank, \
clocks_get_timeofday(), __FILE__, __FUNCTION__, __LINE__, \
##__VA_ARGS__); \
int len = 1024; \
char buf[len]; \
MPI_Error_string(res, buf, &len); \
fprintf(stderr, "%s\n\n", buf); \
MPI_Abort(MPI_COMM_WORLD, -1); \
}
#define mpi_error_string(res, s, ...) \
{ \
fprintf(stderr, "[%04i] %s:%s():%i: " s "\n", engine_rank, __FILE__, \
__FUNCTION__, __LINE__, ##__VA_ARGS__); \
int len = 1024; \
char buf[len]; \
MPI_Error_string(res, buf, &len); \
fprintf(stderr, "%s\n\n", buf); \
#define mpi_error_string(res, s, ...) \
{ \
fprintf(stderr, "[%04i] %s %s:%s():%i: " s "\n", engine_rank, \
clocks_get_timeofday(), __FILE__, __FUNCTION__, __LINE__, \
##__VA_ARGS__); \
int len = 1024; \
char buf[len]; \
MPI_Error_string(res, buf, &len); \
fprintf(stderr, "%s\n\n", buf); \
}
#endif
......@@ -84,10 +88,12 @@ extern int engine_rank;
*/
#ifdef WITH_MPI
extern int engine_rank;
#define message(s, ...) \
printf("[%04i] %s: " s "\n", engine_rank, __FUNCTION__, ##__VA_ARGS__)
#define message(s, ...) \
printf("[%04i] %s %s: " s "\n", engine_rank, clocks_get_timeofday(), \
__FUNCTION__, ##__VA_ARGS__)
#else
#define message(s, ...) printf("%s: " s "\n", __FUNCTION__, ##__VA_ARGS__)
#define message(s, ...) \
printf("%s %s: " s "\n", clocks_get_timeofday(), __FUNCTION__, ##__VA_ARGS__)
#endif
/**
......@@ -96,25 +102,26 @@ extern int engine_rank;
*/
#ifdef WITH_MPI
extern int engine_rank;
#define assert(expr) \
{ \
if (!(expr)) { \
fprintf(stderr, "[%04i] %s:%s():%i: FAILED ASSERTION: " #expr " \n", \
engine_rank, __FILE__, __FUNCTION__, __LINE__); \
fflush(stderr); \
MPI_Abort(MPI_COMM_WORLD, -1); \
} \
}
#else
#define assert(expr) \
{ \
if (!(expr)) { \
fprintf(stderr, "%s:%s():%i: FAILED ASSERTION: " #expr " \n", __FILE__, \
__FUNCTION__, __LINE__); \
fprintf(stderr, "[%04i] %s %s:%s():%i: FAILED ASSERTION: " #expr " \n", \
engine_rank, clocks_get_timeofday(), __FILE__, __FUNCTION__, \
__LINE__); \
fflush(stderr); \
abort(); \
MPI_Abort(MPI_COMM_WORLD, -1); \
} \
}
#else
#define assert(expr) \
{ \
if (!(expr)) { \
fprintf(stderr, "%s %s:%s():%i: FAILED ASSERTION: " #expr " \n", \
clocks_get_timeofday(), __FILE__, __FUNCTION__, __LINE__); \
fflush(stderr); \
abort(); \
} \
}
#endif
#endif /* SWIFT_ERROR_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment