| [01e53c03] | 1 | /* Testing for bundle pack and unpack which invloves a flexible way of
|
|---|
| 2 | reading and writing arrays. This example may still not cover all possible
|
|---|
| 3 | cases. Anyone can add more send and receive pairs for different cases.
|
|---|
| 4 | */
|
|---|
| 5 | #include <civlc.cvh>
|
|---|
| 6 | #include <bundle.cvh>
|
|---|
| 7 | #include <stdlib.h>
|
|---|
| 8 |
|
|---|
| 9 | $input int N;
|
|---|
| 10 | $input int inputs1[3][N];
|
|---|
| 11 | $input int inputs2[N][3];
|
|---|
| 12 | $input int inputs3[2 * N];
|
|---|
| 13 | $assume(N > 4);
|
|---|
| 14 |
|
|---|
| 15 | void main(){
|
|---|
| 16 | int * p;
|
|---|
| 17 | int * p2;
|
|---|
| 18 | double ** pp;
|
|---|
| 19 |
|
|---|
| 20 | p = (int *)malloc(sizeof(int) * 3 * N);
|
|---|
| 21 | p2 = (int *)malloc(sizeof(int) * 2 * N);
|
|---|
| 22 | pp = (double **)malloc(sizeof(double *) * 2);
|
|---|
| 23 | for (int i = 0; i < 2; i++) {
|
|---|
| 24 | pp[i] = (double *)malloc(sizeof(double) * 10);
|
|---|
| 25 | for (int j = 0; j < 10; j++) pp[i][j] = i + 1;
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | $bundle bun;
|
|---|
| 29 | /*
|
|---|
| 30 | bun = $bundle_pack(&inputs1, sizeof(int) * 3 * N);
|
|---|
| 31 | $bundle_unpack(bun, p);
|
|---|
| 32 | $bundle_unpack_apply(bun, p, 3 * N, _SUM);
|
|---|
| 33 | $assert(p[N-1] == inputs1[0][N-1] * 2);
|
|---|
| 34 |
|
|---|
| 35 | bun = $bundle_pack(&inputs3, sizeof(int) * 2 * N);
|
|---|
| 36 | $bundle_unpack(bun, p2);
|
|---|
| 37 | $bundle_unpack_apply(bun, p2, N, _MINLOC);
|
|---|
| 38 | $assert(p2[0] == inputs3[0] && p2[1] == inputs3[1]);
|
|---|
| 39 | */
|
|---|
| 40 | bun = $bundle_pack(pp[0], sizeof(double) * 10);
|
|---|
| 41 | $bundle_unpack_apply(bun, pp[1], 10, _SUM);
|
|---|
| 42 | for (int j = 0; j < 10; j++) $assert(pp[1][j] == 3);
|
|---|
| 43 |
|
|---|
| 44 | $bundle_unpack_apply(bun, pp[1], 5, _MAXLOC);
|
|---|
| 45 | for (int j = 0; j < 10; j++) $assert(pp[1][j] == 3);
|
|---|
| 46 |
|
|---|
| 47 | free(p);
|
|---|
| 48 | free(p2);
|
|---|
| 49 | free(pp[0]);
|
|---|
| 50 | free(pp[1]);
|
|---|
| 51 | free(pp);
|
|---|
| 52 | }
|
|---|