Newer
Older
#include <stdio.h>
#include <mpi.h>
#include <assert.h>
#include <string.h>
#include "../dispatch.h"
#include "../envelope.h"
#define INDEX_2D_TO_1D(y, x, nb_columns) ((y) * (nb_columns) + (x))
void init_chunk_data(chunk_info_t *ci) {
for (int y = 0; y < ci->dimensions[0]; ++y) {
for (int x = 0; x < ci->dimensions[1]; ++x) {
((int *) ci->data)[INDEX_2D_TO_1D(y, x, ci->dimensions[1])] = y + x;
}
}
}
void tests_1_process(struct futhark_context *fc) {
printf("Testing dispatch_context_new with 1 process. Dimensions = 1x15...\n");
{
int dimensions[1] = {15};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 1);
chunk_info_t ci = get_chunk_info(dc);
assert(ci.dimensions[0] == 1 && ci.dimensions[1] == 15);
assert(ci.data != NULL);
assert(ci.count == 15);
assert(ci.y == 0 && ci.x == 0);
init_chunk_data(&ci);
printf("\tTesting get_inner_envelope. Thickness = 1...\n");
{
envelope_t inner_envelope = get_inner_envelope(dc, fc, 1);
int *west = inner_envelope.front->west->data;
int *east = inner_envelope.front->east->data;
assert(west[0] == data[0]);
assert(east[0] == data[14]);
envelope_free(&inner_envelope);
}
printf("\tTesting get_inner_envelope. Thickness = 2...\n");
{
envelope_t inner_envelope = get_inner_envelope(dc, fc, 2);
envelope_init_accessors(&inner_envelope);
int *west = inner_envelope.front->west->data;
int *east = inner_envelope.front->east->data;
assert(west[0] == 0 && west[1] == 1);
assert(east[0] == 13 && east[1] == 14);
envelope_free(&inner_envelope);
printf("\tTesting get_inner_envelope. Thickness = 16...\n");
inner_envelope = get_inner_envelope(dc, fc, 16);
assert(memcmp(inner_envelope.front->west->data, ci.data, (size_t) ci.count * sizeof(int)) == 0);
assert(memcmp(inner_envelope.front->east->data, ci.data, (size_t) ci.count * sizeof(int)) == 0);
envelope_free(&inner_envelope);
}
printf("\tTesting get_outer_envelope. Thickness = 1...\n");
{
envelope_t outer_envelope = get_outer_envelope(dc, fc, 1);
int *west = outer_envelope.front->west->data;
int *east = outer_envelope.front->east->data;
assert(west[0] == data[14]);
assert(east[0] == data[0]);
envelope_free(&outer_envelope);
}
printf("\tTesting get_outer_envelope. Thickness = 2...\n");
{
envelope_t outer_envelope = get_outer_envelope(dc, fc, 2);
int *west = outer_envelope.front->west->data;
int *east = outer_envelope.front->east->data;
assert(west[0] == data[13] && west[1] == data[14]);
assert(east[0] == data[0] && east[1] == data[1]);
envelope_free(&outer_envelope);
}
dispatch_context_free(dc);
}
printf("Testing dispatch_context_new with 1 process. Dimensions = 10x15...\n");
{
int dimensions[2] = {10, 15};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 2);
chunk_info_t ci = get_chunk_info(dc);
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 15);
assert(ci.data != NULL);
assert(ci.count == 150);
assert(ci.y == 0 && ci.x == 0);
init_chunk_data(&ci);
printf("\tTesting get_inner_envelope. Thickness = 1...\n");
{
envelope_t inner_envelope = get_inner_envelope(dc, fc, 1);
int expected_north[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
int expected_east[] = {14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
int expected_south[] = {9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
int expected_west[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int expected_nw[] = {0};
int expected_ne[] = {14};
int expected_se[] = {23};
int expected_sw[] = {9};
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
assert(memcmp(expected_north, inner_envelope.front->north->data, sizeof(expected_north)) == 0);
assert(memcmp(expected_east, inner_envelope.front->east->data, sizeof(expected_east)) == 0);
assert(memcmp(expected_south, inner_envelope.front->south->data, sizeof(expected_south)) == 0);
assert(memcmp(expected_west, inner_envelope.front->west->data, sizeof(expected_west)) == 0);
assert(memcmp(expected_nw, inner_envelope.front->north_west->data, sizeof(expected_nw)) == 0);
assert(memcmp(expected_ne, inner_envelope.front->north_east->data, sizeof(expected_ne)) == 0);
assert(memcmp(expected_se, inner_envelope.front->south_east->data, sizeof(expected_se)) == 0);
assert(memcmp(expected_sw, inner_envelope.front->south_west->data, sizeof(expected_sw)) == 0);
envelope_free(&inner_envelope);
}
printf("\tTesting get_outer_envelope. Thickness = 1...\n");
{
envelope_t outer_envelope = get_outer_envelope(dc, fc, 1);
envelope_init_accessors(&outer_envelope);
int expected_south[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
int expected_west[] = {14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
int expected_north[] = {9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
int expected_east[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int expected_se[] = {0};
int expected_sw[] = {14};
int expected_nw[] = {23};
int expected_ne[] = {9};
assert(memcmp(expected_north, outer_envelope.front->north->data, sizeof(expected_north)) == 0);
assert(memcmp(expected_east, outer_envelope.front->east->data, sizeof(expected_east)) == 0);
assert(memcmp(expected_south, outer_envelope.front->south->data, sizeof(expected_south)) == 0);
assert(memcmp(expected_west, outer_envelope.front->west->data, sizeof(expected_west)) == 0);
assert(memcmp(expected_nw, outer_envelope.front->north_west->data, sizeof(expected_nw)) == 0);
assert(memcmp(expected_ne, outer_envelope.front->north_east->data, sizeof(expected_ne)) == 0);
assert(memcmp(expected_se, outer_envelope.front->south_east->data, sizeof(expected_se)) == 0);
assert(memcmp(expected_sw, outer_envelope.front->south_west->data, sizeof(expected_sw)) == 0);
envelope_free(&outer_envelope);
}
dispatch_context_free(dc);
}
printf("Testing dispatch_context_new with 1 process. Dimensions = 10x15x1...\n");
{
int dimensions[3] = {10, 15, 1};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 3);
chunk_info_t ci = get_chunk_info(dc);
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 15 && ci.dimensions[2] == 1);
assert(ci.data != NULL);
assert(ci.count == 150);
assert(ci.y == 0 && ci.x == 0 && ci.z == 0);
init_chunk_data(&ci);
printf("\tTesting get_inner_envelope. Thickness = 1...\n");
{
envelope_t inner_envelope = get_inner_envelope(dc, fc, 1);
envelope_init_accessors(&inner_envelope);
int expected_north[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
int expected_east[] = {14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
int expected_south[] = {9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
int expected_west[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int expected_nw[] = {0};
int expected_ne[] = {14};
int expected_se[] = {23};
int expected_sw[] = {9};
assert(memcmp(expected_north, inner_envelope.front->north->data, sizeof(expected_north)) == 0);
assert(memcmp(expected_east, inner_envelope.front->east->data, sizeof(expected_east)) == 0);
assert(memcmp(expected_south, inner_envelope.front->south->data, sizeof(expected_south)) == 0);
assert(memcmp(expected_west, inner_envelope.front->west->data, sizeof(expected_west)) == 0);
assert(memcmp(expected_nw, inner_envelope.front->north_west->data, sizeof(expected_nw)) == 0);
assert(memcmp(expected_ne, inner_envelope.front->north_east->data, sizeof(expected_ne)) == 0);
assert(memcmp(expected_se, inner_envelope.front->south_east->data, sizeof(expected_se)) == 0);
assert(memcmp(expected_sw, inner_envelope.front->south_west->data, sizeof(expected_sw)) == 0);
envelope_free(&inner_envelope);
}
printf("\tTesting get_outer_envelope. Thickness = 1...\n");
{
envelope_t outer_envelope = get_outer_envelope(dc, fc, 1);
int expected_south[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
int expected_west[] = {14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
int expected_north[] = {9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
int expected_east[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int expected_se[] = {0};
int expected_sw[] = {14};
int expected_nw[] = {23};
int expected_ne[] = {9};
assert(memcmp(expected_north, outer_envelope.top->north->data, sizeof(expected_north)) == 0);
assert(memcmp(expected_east, outer_envelope.front->east->data, sizeof(expected_east)) == 0);
assert(memcmp(expected_south, outer_envelope.bottom->south->data, sizeof(expected_south)) == 0);
assert(memcmp(expected_west, outer_envelope.front->west->data, sizeof(expected_west)) == 0);
assert(memcmp(expected_nw, outer_envelope.top->north_west->data, sizeof(expected_nw)) == 0);
assert(memcmp(expected_ne, outer_envelope.top->north_east->data, sizeof(expected_ne)) == 0);
assert(memcmp(expected_se, outer_envelope.bottom->south_east->data, sizeof(expected_se)) == 0);
assert(memcmp(expected_sw, outer_envelope.bottom->south_west->data, sizeof(expected_sw)) == 0);
envelope_free(&outer_envelope);
}
dispatch_context_free(dc);
}
}
void tests_2_processes(int my_rank, struct futhark_context *fc) {
printf("Testing dispatch_context_new with 2 processes. Dimensions = 1x16...\n");
{
int dimensions[1] = {16};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 1);
chunk_info_t ci = get_chunk_info(dc);
if (my_rank == 0) {
assert(ci.dimensions[0] == 1 && ci.dimensions[1] == 8);
assert(ci.data != NULL);
assert(ci.count == 8);
assert(ci.y == 0 && ci.x == 0);
} else {
assert(ci.dimensions[0] == 1 && ci.dimensions[1] == 8);
assert(ci.data != NULL);
assert(ci.count == 8);
assert(ci.y == 0 && ci.x == 8);
}
init_chunk_data(&ci);
printf("\tTesting get_inner_envelope. Thickness = 1...\n");
{
envelope_t inner_envelope = get_inner_envelope(dc, fc, 1);
int *data = (int *) ci.data;
int *west = inner_envelope.front->west->data;
int *east = inner_envelope.front->east->data;
assert(west[0] == data[0]);
assert(east[0] == data[ci.dimensions[1] - 1]);
envelope_free(&inner_envelope);
}
printf("\tTesting get_outer_envelope. Thickness = 9...\n");
{
envelope_t outer_envelope = get_outer_envelope(dc, fc, 9);
int expected_west[] = {0, 1, 2, 3, 4, 5, 6, 7};
int expected_east[] = {0, 1, 2, 3, 4, 5, 6, 7};
assert(memcmp(expected_east, outer_envelope.front->east->data, sizeof(expected_east)) == 0);
assert(memcmp(expected_west, outer_envelope.front->west->data, sizeof(expected_west)) == 0);
envelope_free(&outer_envelope);
}
dispatch_context_free(dc);
}
printf("Testing dispatch_context_new with 2 processes. Dimensions = 1x15...\n");
{
int dimensions[1] = {15};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 1);
chunk_info_t ci = get_chunk_info(dc);
if (my_rank == 0) {
assert(ci.dimensions[0] == 1 && ci.dimensions[1] == 8);
assert(ci.data != NULL);
assert(ci.count == 8);
assert(ci.y == 0 && ci.x == 0);
} else {
assert(ci.dimensions[0] == 1 && ci.dimensions[1] == 7);
assert(ci.data != NULL);
assert(ci.count == 7);
assert(ci.y == 0 && ci.x == 8);
}
init_chunk_data(&ci);
printf("\tTesting get_inner_envelope. Thickness = 1...\n");
{
envelope_t inner_envelope = get_inner_envelope(dc, fc, 1);
int *data = (int *) ci.data;
int *west = inner_envelope.front->west->data;
int *east = inner_envelope.front->east->data;
assert(west[0] == data[0]);
assert(east[0] == data[ci.dimensions[1] - 1]);
envelope_free(&inner_envelope);
}
printf("\tTesting get_inner_envelope. Thickness = 8...\n");
{
envelope_t inner_envelope = get_inner_envelope(dc, fc, 8);
assert(memcmp(inner_envelope.front->west->data, ci.data, (size_t) ci.count * sizeof(int)) == 0);
assert(memcmp(inner_envelope.front->east->data, ci.data, (size_t) ci.count * sizeof(int)) == 0);
envelope_free(&inner_envelope);
}
printf("\tTesting get_outer_envelope. Thickness = 9...\n");
{
envelope_t outer_envelope = get_outer_envelope(dc, fc, 9);
if(my_rank == 0) {
int expected_west[] = {0, 1, 2, 3, 4, 5, 6};
int expected_east[] = {0, 1, 2, 3, 4, 5, 6};
assert(memcmp(expected_east, outer_envelope.front->east->data, sizeof(expected_east)) == 0);
assert(memcmp(expected_west, outer_envelope.front->west->data, sizeof(expected_west)) == 0);
} else {
int expected_west[] = {0, 1, 2, 3, 4, 5, 6, 7};
int expected_east[] = {0, 1, 2, 3, 4, 5, 6, 7};
}
envelope_free(&outer_envelope);
}
dispatch_context_free(dc);
}
printf("Testing dispatch_context_new with 2 processes. Dimensions = 20x40...\n");
{
int dimensions[2] = {20, 40};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 2);
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
chunk_info_t ci = get_chunk_info(dc);
if (my_rank == 0) {
assert(ci.dimensions[0] == 20 && ci.dimensions[1] == 20);
assert(ci.data != NULL);
assert(ci.count == 400);
assert(ci.y == 0 && ci.x == 0);
} else {
assert(ci.dimensions[0] == 20 && ci.dimensions[1] == 20);
assert(ci.data != NULL);
assert(ci.count == 400);
assert(ci.y == 0 && ci.x == 20);
}
init_chunk_data(&ci);
printf("\tTesting get_inner_envelope. Thickness = 4...\n");
{
envelope_t inner_envelope = get_inner_envelope(dc, fc, 4);
if (my_rank == 0) {
int expected_north[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
};
int expected_south[] = {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38
};
int expected_west[] = {0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8,
9, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 12,
13, 14, 15, 13, 14, 15, 16, 14, 15, 16, 17, 15, 16, 17, 18, 16, 17, 18, 19, 17,
18, 19, 20, 18, 19, 20, 21,
19, 20, 21, 22};
int expected_east[] = {
16, 17, 18, 19, 17, 18, 19, 20, 18, 19, 20, 21, 19, 20, 21, 22, 20, 21, 22, 23,
21, 22, 23, 24, 22, 23, 24, 25, 23, 24, 25, 26, 24, 25, 26, 27, 25, 26, 27, 28,
26, 27, 28, 29, 27, 28, 29, 30, 28, 29, 30, 31, 29, 30, 31, 32, 30, 31, 32, 33,
31, 32, 33, 34, 32, 33, 34, 35, 33, 34, 35, 36, 34, 35, 36, 37, 35, 36, 37, 38,
};
int expected_nw[] = {0, 1, 2, 3,
1, 2, 3, 4,
2, 3, 4, 5,
3, 4, 5, 6};
int expected_sw[] = {16, 17, 18, 19,
17, 18, 19, 20,
18, 19, 20, 21,
19, 20, 21, 22};
int expected_se[] = {32, 33, 34, 35,
33, 34, 35, 36,
34, 35, 36, 37,
35, 36, 37, 38};
int expected_ne[] = {
16, 17, 18, 19,
17, 18, 19, 20,
18, 19, 20, 21,
19, 20, 21, 22
};
assert(memcmp(expected_north, inner_envelope.front->north->data, sizeof(expected_north)) == 0);
assert(memcmp(expected_east, inner_envelope.front->east->data, sizeof(expected_east)) == 0);
assert(memcmp(expected_south, inner_envelope.front->south->data, sizeof(expected_south)) == 0);
assert(memcmp(expected_west, inner_envelope.front->west->data, sizeof(expected_west)) == 0);
assert(memcmp(expected_nw, inner_envelope.front->north_west->data, sizeof(expected_nw)) == 0);
assert(memcmp(expected_ne, inner_envelope.front->north_east->data, sizeof(expected_ne)) == 0);
assert(memcmp(expected_se, inner_envelope.front->south_east->data, sizeof(expected_se)) == 0);
assert(memcmp(expected_sw, inner_envelope.front->south_west->data, sizeof(expected_sw)) == 0);
}
envelope_free(&inner_envelope);
}
printf("\tTesting get_outer_envelope. Thickness = 4...\n");
{
envelope_t outer_envelope = get_outer_envelope(dc, fc, 4);
envelope_free(&outer_envelope);
}
dispatch_context_free(dc);
}
printf("Testing dispatch_context_new with 2 processes. Dimensions = 21x41...\n");
{
int dimensions[2] = {21, 41};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 2);
chunk_info_t ci = get_chunk_info(dc);
if (my_rank == 0) {
assert(ci.dimensions[0] == 21 && ci.dimensions[1] == 21);
assert(ci.data != NULL);
assert(ci.count == 441);
assert(ci.y == 0 && ci.x == 0);
} else {
assert(ci.dimensions[0] == 21 && ci.dimensions[1] == 20);
assert(ci.data != NULL);
assert(ci.count == 420);
assert(ci.y == 0 && ci.x == 21);
}
dispatch_context_free(dc);
}
}
void tests_3_processes(int my_rank, struct futhark_context *fc) {
printf("Testing dispatch_context_new with 3 processes. Dimensions = 20x40...\n");
{
int dimensions[2] = {20, 40};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 2);
chunk_info_t ci = get_chunk_info(dc);
if (my_rank == 0) {
assert(ci.dimensions[0] == 20 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 280);
assert(ci.y == 0 && ci.x == 0);
} else if (my_rank == 1) {
assert(ci.dimensions[0] == 20 && ci.dimensions[1] == 13);
assert(ci.data != NULL);
assert(ci.count == 260);
assert(ci.y == 0 && ci.x == 14);
} else {
assert(ci.dimensions[0] == 20 && ci.dimensions[1] == 13);
assert(ci.data != NULL);
assert(ci.count == 260);
assert(ci.y == 0 && ci.x == 27);
}
dispatch_context_free(dc);
}
printf("Testing dispatch_context_new with 2 processes. Dimensions = 21x42...\n");
{
int dimensions[2] = {21, 42};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 2);
chunk_info_t ci = get_chunk_info(dc);
if (my_rank == 0) {
assert(ci.dimensions[0] == 21 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 294);
assert(ci.y == 0 && ci.x == 0);
} else if (my_rank == 1) {
assert(ci.dimensions[0] == 21 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 294);
assert(ci.y == 0 && ci.x == 14);
} else {
assert(ci.dimensions[0] == 21 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 294);
assert(ci.y == 0 && ci.x == 28);
}
dispatch_context_free(dc);
}
}
void tests_4_processes(int my_rank, struct futhark_context *fc) {
printf("Testing dispatch_context_new with 4 processes. Dimensions = 20x40...\n");
{
int dimensions[2] = {20, 40};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 2);
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
chunk_info_t ci = get_chunk_info(dc);
if (my_rank == 0) {
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 20);
assert(ci.data != NULL);
assert(ci.count == 200);
assert(ci.y == 0 && ci.x == 0);
} else if (my_rank == 1) {
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 20);
assert(ci.data != NULL);
assert(ci.count == 200);
assert(ci.y == 0 && ci.x == 20);
} else if (my_rank == 2) {
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 20);
assert(ci.data != NULL);
assert(ci.count == 200);
assert(ci.y == 10 && ci.x == 0);
} else {
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 20);
assert(ci.data != NULL);
assert(ci.count == 200);
assert(ci.y == 10 && ci.x == 20);
}
printf("\tTesting get_inner_envelope. Thickness = 4...\n");
{
envelope_t inner_envelope = get_inner_envelope(dc, fc, 4);
envelope_free(&inner_envelope);
envelope_t outer_envelope = get_outer_envelope(dc, fc, 4);
envelope_free(&outer_envelope);
}
dispatch_context_free(dc);
}
printf("Testing dispatch_context_new with 4 processes. Dimensions = 21x42...\n");
{
int dimensions[2] = {21, 42};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 2);
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
chunk_info_t ci = get_chunk_info(dc);
if (my_rank == 0) {
assert(ci.dimensions[0] == 11 && ci.dimensions[1] == 21);
assert(ci.data != NULL);
assert(ci.count == 231);
assert(ci.y == 0 && ci.x == 0);
} else if (my_rank == 1) {
assert(ci.dimensions[0] == 11 && ci.dimensions[1] == 21);
assert(ci.data != NULL);
assert(ci.count == 231);
assert(ci.y == 0 && ci.x == 21);
} else if (my_rank == 2) {
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 21);
assert(ci.data != NULL);
assert(ci.count == 210);
assert(ci.y == 11 && ci.x == 0);
} else {
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 21);
assert(ci.data != NULL);
assert(ci.count == 210);
assert(ci.y == 11 && ci.x == 21);
}
dispatch_context_free(dc);
}
}
void tests_6_processes(int my_rank, struct futhark_context *fc) {
printf("Testing dispatch_context_new with 6 processes. Dimensions = 20x40...\n");
{
int dimensions[2] = {20, 40};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 2);
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
chunk_info_t ci = get_chunk_info(dc);
switch (my_rank) {
case 0:
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 140);
assert(ci.y == 0 && ci.x == 0);
break;
case 1:
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 13);
assert(ci.data != NULL);
assert(ci.count == 130);
assert(ci.y == 0 && ci.x == 14);
break;
case 2:
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 13);
assert(ci.data != NULL);
assert(ci.count == 130);
assert(ci.y == 0 && ci.x == 27);
break;
case 3:
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 140);
assert(ci.y == 10 && ci.x == 0);
break;
case 4:
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 13);
assert(ci.data != NULL);
assert(ci.count == 130);
assert(ci.y == 10 && ci.x == 14);
break;
case 5:
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 13);
assert(ci.data != NULL);
assert(ci.count == 130);
assert(ci.y == 10 && ci.x == 27);
break;
default:
break;
}
envelope_t inner_envelope = get_inner_envelope(dc, fc, 4);
envelope_free(&inner_envelope);
envelope_t outer_envelope = get_outer_envelope(dc, fc, 4);
envelope_free(&outer_envelope);
dispatch_context_free(dc);
}
printf("Testing dispatch_context_new with 4 processes. Dimensions = 21x42...\n");
{
int dimensions[2] = {21, 42};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 2);
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
chunk_info_t ci = get_chunk_info(dc);
switch (my_rank) {
case 0:
assert(ci.dimensions[0] == 11 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 154);
assert(ci.y == 0 && ci.x == 0);
break;
case 1:
assert(ci.dimensions[0] == 11 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 154);
assert(ci.y == 0 && ci.x == 14);
break;
case 2:
assert(ci.dimensions[0] == 11 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 154);
assert(ci.y == 0 && ci.x == 28);
break;
case 3:
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 140);
assert(ci.y == 11 && ci.x == 0);
break;
case 4:
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 140);
assert(ci.y == 11 && ci.x == 14);
break;
case 5:
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 140);
assert(ci.y == 11 && ci.x == 28);
break;
default:
break;
}
dispatch_context_free(dc);
}
}
int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
struct futhark_context_config *fcc = futhark_context_config_new();
struct futhark_context *fc = futhark_context_new(fcc);
int my_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
switch (world_size) {
case 1:
tests_1_process(fc);
break;
case 2:
tests_2_processes(my_rank, fc);
break;
case 3:
tests_3_processes(my_rank, fc);
break;
case 4:
tests_4_processes(my_rank, fc);
break;
case 6:
tests_6_processes(my_rank, fc);
break;
default:
break;
}
futhark_context_config_free(fcc);
futhark_context_free(fc);
MPI_Finalize();
}