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