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