xref: /libCEED/tests/t114-vector.c (revision cdf95791513f7c35170bef3ba2e19f272fe04533)
1 /// @file
2 /// Test CeedVector readers counter
3 /// \test Test CeedVector readers counter
4 #include <ceed.h>
5 
6 int main(int argc, char **argv) {
7   Ceed ceed;
8   CeedVector x;
9   CeedInt n = 10;
10   CeedScalar a[10];
11   const CeedScalar *b;
12 
13   CeedInit(argv[1], &ceed);
14 
15   CeedVectorCreate(ceed, n, &x);
16   for (CeedInt i=0; i<n; i++)
17     a[i] = 10 + i;
18   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, a);
19 
20   CeedVectorGetArrayRead(x, CEED_MEM_HOST, &b);
21   for (CeedInt i=0; i<n; i++)
22     if (b[i] != 10+i)
23       // LCOV_EXCL_START
24       printf("Error reading array b[%d] = %f",i,(CeedScalar)b[i]);
25   // LCOV_EXCL_STOP
26 
27   // Try to set vector again (should fail)
28   for (CeedInt i=0; i<n; i++)
29     a[i] = 20 + i;
30   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
31 
32   // LCOV_EXCL_START
33   CeedVectorRestoreArrayRead(x, &b);
34 
35   CeedVectorDestroy(&x);
36   CeedDestroy(&ceed);
37   return 0;
38   // LCOV_EXCL_STOP
39 }
40