Commit 7bb7239f authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Safer versions of the error() and message() macros that can be used in if/else...

Safer versions of the error() and message() macros that can be used in if/else statements without braces.
parent 476a3d69
......@@ -38,19 +38,19 @@
#ifdef WITH_MPI
extern int engine_rank;
#define error(s, ...) \
{ \
({ \
fprintf(stderr, "[%04i] %s %s:%s():%i: " s "\n", engine_rank, \
clocks_get_timesincestart(), __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_timesincestart(), \
__FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
abort(); \
}
})
#endif
#ifdef WITH_MPI
......@@ -60,7 +60,7 @@ extern int engine_rank;
*
*/
#define mpi_error(res, s, ...) \
{ \
({ \
fprintf(stderr, "[%04i] %s %s:%s():%i: " s "\n", engine_rank, \
clocks_get_timesincestart(), __FILE__, __FUNCTION__, __LINE__, \
##__VA_ARGS__); \
......@@ -69,10 +69,10 @@ extern int engine_rank;
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:%s():%i: " s "\n", engine_rank, \
clocks_get_timesincestart(), __FILE__, __FUNCTION__, __LINE__, \
##__VA_ARGS__); \
......@@ -80,7 +80,7 @@ extern int engine_rank;
char buf[len]; \
MPI_Error_string(res, buf, &len); \
fprintf(stderr, "%s\n\n", buf); \
}
})
#endif
/**
......@@ -89,13 +89,17 @@ extern int engine_rank;
*/
#ifdef WITH_MPI
extern int engine_rank;
#define message(s, ...) \
printf("[%04i] %s %s: " s "\n", engine_rank, clocks_get_timesincestart(), \
__FUNCTION__, ##__VA_ARGS__)
#define message(s, ...) \
({ \
printf("[%04i] %s %s: " s "\n", engine_rank, clocks_get_timesincestart(), \
__FUNCTION__, ##__VA_ARGS__); \
})
#else
#define message(s, ...) \
printf("%s %s: " s "\n", clocks_get_timesincestart(), __FUNCTION__, \
##__VA_ARGS__)
#define message(s, ...) \
({ \
printf("%s %s: " s "\n", clocks_get_timesincestart(), __FUNCTION__, \
##__VA_ARGS__); \
})
#endif
/**
......@@ -105,7 +109,7 @@ extern int engine_rank;
#ifdef WITH_MPI
extern int engine_rank;
#define assert(expr) \
{ \
({ \
if (!(expr)) { \
fprintf(stderr, "[%04i] %s %s:%s():%i: FAILED ASSERTION: " #expr " \n", \
engine_rank, clocks_get_timesincestart(), __FILE__, \
......@@ -113,17 +117,17 @@ extern int engine_rank;
fflush(stderr); \
MPI_Abort(MPI_COMM_WORLD, -1); \
} \
}
})
#else
#define assert(expr) \
{ \
({ \
if (!(expr)) { \
fprintf(stderr, "%s %s:%s():%i: FAILED ASSERTION: " #expr " \n", \
clocks_get_timesincestart(), __FILE__, __FUNCTION__, __LINE__); \
fflush(stderr); \
abort(); \
} \
}
})
#endif
#endif /* SWIFT_ERROR_H */
......@@ -226,7 +226,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_vec_density(
error(
"The Gadget2 serial version of runner_iact_density was called when the "
"vectorised version should have been used.")
"vectorised version should have been used.");
#endif
}
......@@ -377,7 +377,7 @@ runner_iact_nonsym_vec_density(float *R2, float *Dx, float *Hi, float *Hj,
error(
"The Gadget2 serial version of runner_iact_nonsym_density was called "
"when the vectorised version should have been used.")
"when the vectorised version should have been used.");
#endif
}
......@@ -656,7 +656,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_vec_force(
error(
"The Gadget2 serial version of runner_iact_nonsym_force was called when "
"the vectorised version should have been used.")
"the vectorised version should have been used.");
#endif
}
......@@ -917,7 +917,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_vec_force(
error(
"The Gadget2 serial version of runner_iact_nonsym_force was called when "
"the vectorised version should have been used.")
"the vectorised version should have been used.");
#endif
}
......
......@@ -1291,6 +1291,8 @@ void *runner_main(void *data) {
runner_dopair2_force(r, ci, cj);
else if (t->subtype == task_subtype_grav)
runner_dopair_grav(r, ci, cj, 1);
else if (t->subtype == task_subtype_external_grav)
error("Found a pair/external-gravity task...");
else
error("Unknown task subtype.");
break;
......@@ -1323,6 +1325,8 @@ void *runner_main(void *data) {
runner_dosub_pair2_force(r, ci, cj, t->flags, 1);
else if (t->subtype == task_subtype_grav)
runner_dosub_grav(r, ci, cj, 1);
else if (t->subtype == task_subtype_external_grav)
error("Found a sub-pair/external-gravity task...");
else
error("Unknown task subtype.");
break;
......
Supports Markdown
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