xref: /libCEED/tests/t114-vector.c (revision caee03026e6576cbf7a399c2fc51bb918c77f451)
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++) a[i] = 10 + i;
17   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, a);
18 
19   CeedVectorGetArrayRead(x, CEED_MEM_HOST, &b);
20   for (CeedInt i = 0; i < n; i++) {
21     if (b[i] != 10 + i) printf("Error reading array b[%" CeedInt_FMT "] = %f\n", i, (CeedScalar)b[i]);
22   }
23 
24   // Try to set vector again (should fail)
25   for (CeedInt i = 0; i < n; i++) a[i] = 20 + i;
26   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
27 
28   // LCOV_EXCL_START
29   CeedVectorRestoreArrayRead(x, &b);
30 
31   CeedVectorDestroy(&x);
32   CeedDestroy(&ceed);
33   return 0;
34   // LCOV_EXCL_STOP
35 }
36