Skip to content

Commit 68c1ecd

Browse files
committed
Muzzle -Wdeclaration-after-statement in check*_collectives.c
1 parent 3a0d3bc commit 68c1ecd

2 files changed

Lines changed: 95 additions & 65 deletions

File tree

tests/check_buffer_collectives.c

Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ extern void teardown_comm(void);
2828
#define ABS_DIFF(a, b) fabs((double)(b - a))
2929
#define MAX_ABS_DIFF(A, B, N, res) \
3030
do { \
31-
res = 0; \
3231
double locdelta; \
3332
int loci; \
33+
res = 0; \
3434
for (loci = 0; loci < N; ++loci) { \
3535
locdelta = ABS_DIFF(A[loci], B[loci]); \
3636
if (locdelta > res) \
@@ -42,8 +42,8 @@ typedef unsigned long ulong;
4242

4343
#define PRINTV(ar, N, t) \
4444
do { \
45-
printf("%s\n", STR(ar)); \
4645
int li; \
46+
printf("%s\n", STR(ar)); \
4747
for (li = 0; li < (N); ++li) { \
4848
printf(STR(t) " ", ar[li]); \
4949
} \
@@ -81,18 +81,21 @@ END_TEST
8181

8282
#define INIT_ARRAYS(insize, outsize) \
8383
int err; \
84-
void* Av = calloc((insize), sizeof(char)); \
84+
void* Av, * RESv, * EXPv; \
85+
gpudata* Adev, *RESdev; \
86+
\
87+
Av = calloc((insize), sizeof(char)); \
8588
if (Av == NULL) \
8689
ck_abort_msg("system memory allocation failed"); \
87-
void* RESv = calloc((outsize), sizeof(char)); \
90+
RESv = calloc((outsize), sizeof(char)); \
8891
if (RESv == NULL) \
8992
ck_abort_msg("system memory allocation failed"); \
90-
void* EXPv = calloc((outsize), sizeof(char)); \
93+
EXPv = calloc((outsize), sizeof(char)); \
9194
if (EXPv == NULL) \
9295
ck_abort_msg("system memory allocation failed"); \
93-
gpudata* Adev = gpudata_alloc(ctx, (insize), NULL, 0, &err); \
96+
Adev = gpudata_alloc(ctx, (insize), NULL, 0, &err); \
9497
ck_assert_ptr_ne(Adev, NULL); \
95-
gpudata* RESdev = gpudata_alloc(ctx, (outsize), NULL, 0, &err); \
98+
RESdev = gpudata_alloc(ctx, (outsize), NULL, 0, &err); \
9699
ck_assert_ptr_ne(RESdev, NULL);
97100

98101
#define DESTROY_ARRAYS() \
@@ -104,13 +107,15 @@ END_TEST
104107

105108
#define TEST_REDUCE(systype, gatype, mpitype, coloptype, epsilon, print) \
106109
START_TEST(test_gpucomm_reduce_##gatype##_##coloptype) { \
110+
systype* A, * RES, * EXP; \
111+
int i, count; \
107112
INIT_ARRAYS(SIZE, SIZE) \
108113
\
109-
systype* A = (systype*)Av; \
110-
systype* RES = (systype*)RESv; \
111-
systype* EXP = (systype*)EXPv; \
114+
A = (systype*)Av; \
115+
RES = (systype*)RESv; \
116+
EXP = (systype*)EXPv; \
112117
\
113-
int i, count = SIZE / sizeof(systype); \
118+
count = SIZE / sizeof(systype); \
114119
for (i = 0; i < count; ++i) \
115120
A[i] = comm_rank + 2; \
116121
err = gpudata_write(Adev, 0, A, SIZE); \
@@ -128,9 +133,9 @@ END_TEST
128133
"openmpi error: cannot produced expected"); \
129134
\
130135
if (comm_rank == ROOT_RANK) { \
136+
systype res; \
131137
err = gpudata_read(RES, RESdev, 0, SIZE); \
132138
ck_assert_int_eq(err, GA_NO_ERROR); \
133-
systype res; \
134139
MAX_ABS_DIFF(RES, EXP, count, res); \
135140
if (!(res <= epsilon)) { \
136141
print(RES, count); \
@@ -197,13 +202,16 @@ TEST_REDUCE_FAIL(elemcount, (size_t)INT_MAX + 1, GA_INT, GA_SUM, 0,
197202

198203
#define TEST_ALL_REDUCE(systype, gatype, mpitype, coloptype, epsilon, print) \
199204
START_TEST(test_gpucomm_all_reduce_##gatype##_##coloptype) { \
205+
systype* A, * RES, * EXP; \
206+
systype res; \
207+
int i, count; \
200208
INIT_ARRAYS(SIZE, SIZE) \
201209
\
202-
systype* A = (systype*)Av; \
203-
systype* RES = (systype*)RESv; \
204-
systype* EXP = (systype*)EXPv; \
210+
A = (systype*)Av; \
211+
RES = (systype*)RESv; \
212+
EXP = (systype*)EXPv; \
205213
\
206-
int i, count = SIZE / sizeof(systype); \
214+
count = SIZE / sizeof(systype); \
207215
for (i = 0; i < count; ++i) \
208216
A[i] = comm_rank + 2; \
209217
err = gpudata_write(Adev, 0, A, SIZE); \
@@ -222,7 +230,6 @@ TEST_REDUCE_FAIL(elemcount, (size_t)INT_MAX + 1, GA_INT, GA_SUM, 0,
222230
\
223231
err = gpudata_read(RES, RESdev, 0, SIZE); \
224232
ck_assert_int_eq(err, GA_NO_ERROR); \
225-
systype res; \
226233
MAX_ABS_DIFF(RES, EXP, count, res); \
227234
if (!(res <= epsilon)) { \
228235
print(RES, count); \
@@ -294,26 +301,31 @@ TEST_ALL_REDUCE_FAIL(elemcount, (size_t)INT_MAX + 1, GA_INT, GA_SUM, 0, 0,
294301
#define TEST_REDUCE_SCATTER(systype, gatype, mpitype, coloptype, epsilon, \
295302
print) \
296303
START_TEST(test_gpucomm_reduce_scatter_##gatype##_##coloptype) { \
304+
systype* A, * RES, * EXP; \
305+
systype res; \
306+
int i, count; \
307+
int recvcount; \
308+
int* recvcounts; \
297309
INIT_ARRAYS(SIZE, SIZE / comm_ndev) \
298310
\
299-
systype* A = (systype*)Av; \
300-
systype* RES = (systype*)RESv; \
301-
systype* EXP = (systype*)EXPv; \
311+
A = (systype*)Av; \
312+
RES = (systype*)RESv; \
313+
EXP = (systype*)EXPv; \
302314
\
303-
int i, count = SIZE / sizeof(systype); \
315+
count = SIZE / sizeof(systype); \
304316
for (i = 0; i < count; ++i) \
305317
A[i] = comm_rank + 2; \
306318
err = gpudata_write(Adev, 0, A, SIZE); \
307319
ck_assert_int_eq(err, GA_NO_ERROR); \
308320
\
309-
int recvcount = count / comm_ndev; \
321+
recvcount = count / comm_ndev; \
310322
err = gpucomm_reduce_scatter(Adev, 0, RESdev, 0, recvcount, GA_##gatype, \
311323
GA_##coloptype, comm); \
312324
ck_assert_int_eq(err, GA_NO_ERROR); \
313325
gpudata_sync(RESdev); \
314326
gpudata_sync(Adev); \
315327
\
316-
int* recvcounts = (int*)malloc(comm_ndev * sizeof(int)); \
328+
recvcounts = (int*)malloc(comm_ndev * sizeof(int)); \
317329
if (recvcounts == NULL) \
318330
ck_abort_msg("system memory allocation failed"); \
319331
for (i = 0; i < comm_ndev; ++i) \
@@ -326,7 +338,6 @@ TEST_ALL_REDUCE_FAIL(elemcount, (size_t)INT_MAX + 1, GA_INT, GA_SUM, 0, 0,
326338
\
327339
err = gpudata_read(RES, RESdev, 0, SIZE / comm_ndev); \
328340
ck_assert_int_eq(err, GA_NO_ERROR); \
329-
systype res; \
330341
MAX_ABS_DIFF(RES, EXP, recvcount, res); \
331342
if (!(res <= epsilon)) { \
332343
print(RES, recvcount); \
@@ -396,12 +407,15 @@ TEST_REDUCE_SCATTER_FAIL(elemcount, (size_t)INT_MAX + 1, GA_INT, GA_SUM, 0, 0,
396407

397408
#define TEST_BROADCAST(systype, gatype, mpitype, epsilon, print) \
398409
START_TEST(test_gpucomm_broadcast_##gatype) { \
410+
systype* RES, * EXP; \
411+
systype res; \
412+
int i, count; \
399413
INIT_ARRAYS(SIZE, SIZE) \
400414
\
401-
systype* RES = (systype*)RESv; \
402-
systype* EXP = (systype*)EXPv; \
415+
RES = (systype*)RESv; \
416+
EXP = (systype*)EXPv; \
403417
\
404-
int i, count = SIZE / sizeof(systype); \
418+
count = SIZE / sizeof(systype); \
405419
for (i = 0; i < count; ++i) { \
406420
RES[i] = comm_rank + 1; \
407421
EXP[i] = RES[i]; \
@@ -419,7 +433,6 @@ TEST_REDUCE_SCATTER_FAIL(elemcount, (size_t)INT_MAX + 1, GA_INT, GA_SUM, 0, 0,
419433
\
420434
err = gpudata_read(RES, RESdev, 0, SIZE); \
421435
ck_assert_int_eq(err, GA_NO_ERROR); \
422-
systype res; \
423436
MAX_ABS_DIFF(RES, EXP, count, res); \
424437
if (!(res <= epsilon)) { \
425438
print(RES, count); \
@@ -463,14 +476,17 @@ TEST_BROADCAST_FAIL(elemcount, (size_t)INT_MAX + 1, GA_INT, 0,
463476

464477
#define TEST_ALL_GATHER(systype, gatype, mpitype, epsilon, print) \
465478
START_TEST(test_gpucomm_all_gather_##gatype) { \
479+
systype* A, * RES, * EXP; \
480+
systype res; \
481+
int i, count, sendcount; \
466482
INIT_ARRAYS(SIZE / comm_ndev, SIZE) \
467483
\
468-
systype* A = (systype*)Av; \
469-
systype* RES = (systype*)RESv; \
470-
systype* EXP = (systype*)EXPv; \
484+
A = (systype*)Av; \
485+
RES = (systype*)RESv; \
486+
EXP = (systype*)EXPv; \
471487
\
472-
int i, count = SIZE / sizeof(systype); \
473-
int sendcount = count / comm_ndev; \
488+
count = SIZE / sizeof(systype); \
489+
sendcount = count / comm_ndev; \
474490
for (i = 0; i < sendcount; ++i) \
475491
A[i] = comm_rank + 1; \
476492
err = gpudata_write(Adev, 0, A, SIZE / comm_ndev); \
@@ -489,7 +505,6 @@ TEST_BROADCAST_FAIL(elemcount, (size_t)INT_MAX + 1, GA_INT, 0,
489505
\
490506
err = gpudata_read(RES, RESdev, 0, SIZE); \
491507
ck_assert_int_eq(err, GA_NO_ERROR); \
492-
systype res; \
493508
MAX_ABS_DIFF(RES, EXP, count, res); \
494509
if (!(res <= epsilon)) { \
495510
print(RES, count); \
@@ -536,14 +551,27 @@ TEST_ALL_GATHER_FAIL(elemcount, (size_t)INT_MAX + 1, GA_INT, 0, 0,
536551
GA_XLARGE_ERROR)
537552

538553
Suite* get_suite(void) {
539-
Suite* s = suite_create("buffer_collectives_API");
540-
541-
TCase* helps = tcase_create("test_helpers");
554+
Suite* s;
555+
TCase* helps;
556+
TCase* reds;
557+
TCase* redf;
558+
TCase* areds;
559+
TCase* aredf;
560+
TCase* redscs;
561+
TCase* redscf;
562+
TCase* bcasts;
563+
TCase* bcastf;
564+
TCase* agats;
565+
TCase* agatf;
566+
567+
s = suite_create("buffer_collectives_API");
568+
569+
helps = tcase_create("test_helpers");
542570
tcase_add_unchecked_fixture(helps, setup_comm, teardown_comm);
543571
tcase_add_test(helps, test_gpucomm_get_count);
544572
tcase_add_test(helps, test_gpucomm_get_rank);
545573

546-
TCase* reds = tcase_create("test_reduce");
574+
reds = tcase_create("test_reduce");
547575
tcase_add_unchecked_fixture(reds, setup_comm, teardown_comm);
548576
tcase_add_test(reds, test_gpucomm_reduce_INT_SUM);
549577
tcase_add_test(reds, test_gpucomm_reduce_INT_PROD);
@@ -570,14 +598,14 @@ Suite* get_suite(void) {
570598
tcase_add_test(reds, test_gpucomm_reduce_ULONG_MAX);
571599
tcase_add_test(reds, test_gpucomm_reduce_ULONG_MIN);
572600

573-
TCase* redf = tcase_create("test_reduce_fail");
601+
redf = tcase_create("test_reduce_fail");
574602
tcase_add_unchecked_fixture(redf, setup_comm, teardown_comm);
575603
tcase_add_test(redf, test_gpucomm_reduce_fail_datatype);
576604
tcase_add_test(redf, test_gpucomm_reduce_fail_optype);
577605
tcase_add_test(redf, test_gpucomm_reduce_fail_src_offset);
578606
tcase_add_test(redf, test_gpucomm_reduce_fail_elemcount);
579607

580-
TCase* areds = tcase_create("test_all_reduce");
608+
areds = tcase_create("test_all_reduce");
581609
tcase_add_unchecked_fixture(areds, setup_comm, teardown_comm);
582610
tcase_add_test(areds, test_gpucomm_all_reduce_INT_SUM);
583611
tcase_add_test(areds, test_gpucomm_all_reduce_INT_PROD);
@@ -604,15 +632,15 @@ Suite* get_suite(void) {
604632
tcase_add_test(areds, test_gpucomm_all_reduce_ULONG_MAX);
605633
tcase_add_test(areds, test_gpucomm_all_reduce_ULONG_MIN);
606634

607-
TCase* aredf = tcase_create("test_all_reduce_fail");
635+
aredf = tcase_create("test_all_reduce_fail");
608636
tcase_add_unchecked_fixture(aredf, setup_comm, teardown_comm);
609637
tcase_add_test(aredf, test_gpucomm_all_reduce_fail_datatype);
610638
tcase_add_test(aredf, test_gpucomm_all_reduce_fail_optype);
611639
tcase_add_test(aredf, test_gpucomm_all_reduce_fail_src_offset);
612640
tcase_add_test(aredf, test_gpucomm_all_reduce_fail_dest_offset);
613641
tcase_add_test(aredf, test_gpucomm_all_reduce_fail_elemcount);
614642

615-
TCase* redscs = tcase_create("test_reduce_scatter");
643+
redscs = tcase_create("test_reduce_scatter");
616644
tcase_add_unchecked_fixture(redscs, setup_comm, teardown_comm);
617645
tcase_add_test(redscs, test_gpucomm_reduce_scatter_INT_SUM);
618646
tcase_add_test(redscs, test_gpucomm_reduce_scatter_INT_PROD);
@@ -639,15 +667,15 @@ Suite* get_suite(void) {
639667
tcase_add_test(redscs, test_gpucomm_reduce_scatter_ULONG_MAX);
640668
tcase_add_test(redscs, test_gpucomm_reduce_scatter_ULONG_MIN);
641669

642-
TCase* redscf = tcase_create("test_reduce_scatter_fail");
670+
redscf = tcase_create("test_reduce_scatter_fail");
643671
tcase_add_unchecked_fixture(redscf, setup_comm, teardown_comm);
644672
tcase_add_test(redscf, test_gpucomm_reduce_scatter_fail_datatype);
645673
tcase_add_test(redscf, test_gpucomm_reduce_scatter_fail_optype);
646674
tcase_add_test(redscf, test_gpucomm_reduce_scatter_fail_src_offset);
647675
tcase_add_test(redscf, test_gpucomm_reduce_scatter_fail_dest_offset);
648676
tcase_add_test(redscf, test_gpucomm_reduce_scatter_fail_elemcount);
649677

650-
TCase* bcasts = tcase_create("test_broadcast");
678+
bcasts = tcase_create("test_broadcast");
651679
tcase_add_unchecked_fixture(bcasts, setup_comm, teardown_comm);
652680
tcase_add_test(bcasts, test_gpucomm_broadcast_INT);
653681
tcase_add_test(bcasts, test_gpucomm_broadcast_BYTE);
@@ -656,13 +684,13 @@ Suite* get_suite(void) {
656684
tcase_add_test(bcasts, test_gpucomm_broadcast_LONG);
657685
tcase_add_test(bcasts, test_gpucomm_broadcast_ULONG);
658686

659-
TCase* bcastf = tcase_create("test_broadcast_fail");
687+
bcastf = tcase_create("test_broadcast_fail");
660688
tcase_add_unchecked_fixture(bcastf, setup_comm, teardown_comm);
661689
tcase_add_test(bcastf, test_gpucomm_broadcast_fail_datatype);
662690
tcase_add_test(bcastf, test_gpucomm_broadcast_fail_src_offset);
663691
tcase_add_test(bcastf, test_gpucomm_broadcast_fail_elemcount);
664692

665-
TCase* agats = tcase_create("test_all_gather");
693+
agats = tcase_create("test_all_gather");
666694
tcase_add_unchecked_fixture(agats, setup_comm, teardown_comm);
667695
tcase_add_test(agats, test_gpucomm_all_gather_INT);
668696
tcase_add_test(agats, test_gpucomm_all_gather_BYTE);
@@ -671,7 +699,7 @@ Suite* get_suite(void) {
671699
tcase_add_test(agats, test_gpucomm_all_gather_LONG);
672700
tcase_add_test(agats, test_gpucomm_all_gather_ULONG);
673701

674-
TCase* agatf = tcase_create("test_all_gather_fail");
702+
agatf = tcase_create("test_all_gather_fail");
675703
tcase_add_unchecked_fixture(agatf, setup_comm, teardown_comm);
676704
tcase_add_test(agatf, test_gpucomm_all_gather_fail_datatype);
677705
tcase_add_test(agatf, test_gpucomm_all_gather_fail_src_offset);

0 commit comments

Comments
 (0)