xref: /libCEED/tests/t114-vector.c (revision 2ba3f748b44edc091d4082cfe571655b6bd7a424)
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[%" CeedInt_FMT
25              "] = %f\n",i,(CeedScalar)b[i]);
26   // LCOV_EXCL_STOP
27 
28   // Try to set vector again (should fail)
29   for (CeedInt i=0; i<n; i++)
30     a[i] = 20 + i;
31   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
32 
33   // LCOV_EXCL_START
34   CeedVectorRestoreArrayRead(x, &b);
35 
36   CeedVectorDestroy(&x);
37   CeedDestroy(&ceed);
38   return 0;
39   // LCOV_EXCL_STOP
40 }
41