xref: /libCEED/tests/t104-vector.c (revision d310b3d31eeeddd20725517a3a61881a36d919f0)
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++) a[i] = 0;
17   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
18 
19   CeedVectorGetArray(x, CEED_MEM_HOST, &b);
20   b[3] = -3.14;
21   CeedVectorRestoreArray(x, &b);
22 
23   if (a[3] != (CeedScalar)(-3.14)) printf("Error writing array a[3] = %f\n", (CeedScalar)a[3]);
24 
25   CeedVectorDestroy(&x);
26   CeedDestroy(&ceed);
27   return 0;
28 }
29