xref: /libCEED/tests/t104-vector.c (revision 9df49d7ef0a77c7a3baec2427d8a7274681409b6)
1 /// @file
2 /// Test CeedVectorGetArray to modify array
3 /// \test Test CeedVectorGetArray to modify array
4 #include <ceed.h>
5 
6 int main(int argc, char **argv) {
7   Ceed ceed;
8   CeedVector x;
9   const CeedInt n = 10;
10   CeedScalar a[n];
11   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] = 0;
18   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
19 
20   CeedVectorGetArray(x, CEED_MEM_HOST, &b);
21   b[3] = -3.14;
22   CeedVectorRestoreArray(x, &b);
23 
24   if (a[3] != -3.14)
25     // LCOV_EXCL_START
26     printf("Error writing array a[3] = %f", (double)a[3]);
27   // LCOV_EXCL_STOP
28 
29   CeedVectorDestroy(&x);
30   CeedDestroy(&ceed);
31   return 0;
32 }
33