1 /// @file
2 /// Test strided setting and copying of vectors
3 /// \test Test strided setting and copying of vectors
4 #include <ceed.h>
5 #include <stdio.h>
6
main(int argc,char ** argv)7 int main(int argc, char **argv) {
8 Ceed ceed;
9 CeedSize start = 2, step = 3;
10 CeedVector x, y;
11 CeedInt len = 10;
12
13 CeedInit(argv[1], &ceed);
14
15 CeedVectorCreate(ceed, len, &x);
16 CeedVectorCreate(ceed, len, &y);
17
18 // Set strided
19 CeedVectorSetValue(x, 1.0);
20 CeedVectorSetValueStrided(x, start, -1, step, 42.0);
21 {
22 const CeedScalar *read_array;
23
24 CeedVectorGetArrayRead(x, CEED_MEM_HOST, &read_array);
25 for (CeedInt i = 0; i < len; i++) {
26 CeedScalar value = (i - start) % step == 0 ? 42.0 : 1.0;
27
28 if (read_array[i] != value) {
29 // LCOV_EXCL_START
30 printf("Error in setting value in x at index %" CeedInt_FMT ", computed: %f actual: %f\n", i, read_array[i], value);
31 // LCOV_EXCL_STOP
32 }
33 }
34 CeedVectorRestoreArrayRead(x, &read_array);
35 }
36
37 // Copy strided
38 CeedVectorSetValue(y, 0.0);
39 CeedVectorCopyStrided(x, start, -1, step, y);
40 {
41 const CeedScalar *read_array;
42
43 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &read_array);
44 for (CeedInt i = 0; i < len; i++) {
45 CeedScalar value = (i - start) % step == 0 ? 42.0 : 0.0;
46
47 if (read_array[i] != value) {
48 // LCOV_EXCL_START
49 printf("Error in copying value to y at index %" CeedInt_FMT ", computed: %f actual: %f\n", i, read_array[i], value);
50 // LCOV_EXCL_STOP
51 }
52 }
53 CeedVectorRestoreArrayRead(y, &read_array);
54 }
55
56 CeedVectorDestroy(&x);
57 CeedVectorDestroy(&y);
58 CeedDestroy(&ceed);
59 return 0;
60 }
61