-#define SMPI_SAMPLE_LOOP(global, iters, thres) \
- for (smpi_sample_1(global, __FILE__, __LINE__, iters, thres); smpi_sample_2(global, __FILE__, __LINE__); \
- smpi_sample_3(global, __FILE__, __LINE__))
-#define SMPI_SAMPLE_LOCAL(iters, thres) SMPI_SAMPLE_LOOP(0, iters, thres)
-#define SMPI_SAMPLE_GLOBAL(iters, thres) SMPI_SAMPLE_LOOP(1, iters, thres)
+#define SMPI_SAMPLE_LOOP(loop_init, loop_end, loop_iter, global, iters, thres, loop_body) \
+ {\
+ loop_init;\
+ for (;;){\
+ if(!(loop_end)) {\
+ smpi_sample_exit(global, __FILE__, __LINE__);\
+ break;\
+ }\
+ for (smpi_sample_1(global, __FILE__, __LINE__, iters, thres); smpi_sample_2(global, __FILE__, __LINE__); \
+ smpi_sample_3(global, __FILE__, __LINE__)){\
+ loop_body\
+ }\
+ loop_iter;\
+ }\
+ }
+
+#define SMPI_SAMPLE_LOCAL(loop_init, loop_end, loop_iter, iters, thres, loop_body) SMPI_SAMPLE_LOOP(loop_init, loop_end, loop_iter, 0, iters, thres, loop_body)
+#define SMPI_SAMPLE_GLOBAL(loop_init, loop_end, loop_iter,iters, thres, loop_body) SMPI_SAMPLE_LOOP(loop_init, loop_end, loop_iter, 1, iters, thres, loop_body)