xref: /libCEED/tests/t100-vector.c (revision a9e65696a8c8214eb82d2dcf9ed1f28a32d2c94e)
1 /// @file
2 /// Test creation, setting, reading, restoring, and destroying of a vector
3 /// \test Test creation, setting, reading, restoring, and destroying of a vector
4 #include <ceed.h>
5 
6 int main(int argc, char **argv) {
7   Ceed              ceed;
8   CeedVector        x;
9   CeedInt           n;
10   CeedScalar        a[10];
11   const CeedScalar *b;
12 
13   CeedInit(argv[1], &ceed);
14 
15   n = 10;
16   CeedVectorCreate(ceed, n, &x);
17   for (CeedInt i = 0; i < n; i++) a[i] = 10 + i;
18   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
19 
20   CeedVectorGetArrayRead(x, CEED_MEM_HOST, &b);
21   for (CeedInt i = 0; i < n; i++) {
22     if (b[i] != 10 + i) printf("Error reading array b[%" CeedInt_FMT "] = %f\n", i, (CeedScalar)b[i]);
23   }
24   CeedVectorRestoreArrayRead(x, &b);
25 
26   CeedVectorDestroy(&x);
27   CeedDestroy(&ceed);
28   return 0;
29 }
30