xref: /libCEED/tests/t105-vector.c (revision 43e1b16f0c7c5dbfae04543c0675e255f265ff67)
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[%d] = %f", i, (CeedScalar)c[i]);
32   // LCOV_EXCL_STOP
33   CeedVectorRestoreArrayRead(y, &c);
34 
35   CeedVectorDestroy(&x);
36   CeedVectorDestroy(&y);
37   CeedDestroy(&ceed);
38   return 0;
39 }
40