xref: /libCEED/tests/t105-vector.c (revision 600b7929b98f3d8efad5f619bace308a359a46af)
1 /// @file
2 /// Test creation, setting, reading, restoring, and destroying of a vector using CEED_MEM_DEVICE
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   CeedVector y;
10   CeedInt n;
11   CeedScalar a[10];
12   const CeedScalar *b, *c;
13 
14   CeedInit(argv[1], &ceed);
15 
16   n = 10;
17   CeedVectorCreate(ceed, n, &x);
18   CeedVectorCreate(ceed, n, &y);
19   for (CeedInt i=0; i<n; i++)
20     a[i] = 10 + i;
21   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
22 
23   CeedVectorGetArrayRead(x, CEED_MEM_DEVICE, &b);
24   CeedVectorSetArray(y, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)b);
25   CeedVectorRestoreArrayRead(x, &b);
26 
27   CeedVectorGetArrayRead(y, CEED_MEM_HOST, &c);
28   for (CeedInt i=0; i<n; i++)
29     if (c[i] != 10+i)
30       // LCOV_EXCL_START
31       printf("Error reading array c[%" CeedInt_FMT
32              "] = %f\n", i, (CeedScalar)c[i]);
33   // LCOV_EXCL_STOP
34   CeedVectorRestoreArrayRead(y, &c);
35 
36   CeedVectorDestroy(&x);
37   CeedVectorDestroy(&y);
38   CeedDestroy(&ceed);
39   return 0;
40 }
41