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