xref: /libCEED/tests/t106-vector.c (revision 8ec64e9ae9d5df169dba8c8ee61d8ec8907b8f80)
1 /// @file
2 /// Test syncing device data to host pointer
3 /// \test Test syncing device data to host pointer
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], b[10];
12   const CeedScalar *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++) a[i] = 10 + i;
20   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
21 
22   for (CeedInt i = 0; i < n; i++) b[i] = 0;
23   CeedVectorSetArray(y, CEED_MEM_HOST, CEED_USE_POINTER, b);
24 
25   CeedVectorGetArrayRead(x, CEED_MEM_DEVICE, &c);
26   CeedVectorSetArray(y, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)c);
27   CeedVectorRestoreArrayRead(x, &c);
28 
29   CeedVectorSyncArray(y, CEED_MEM_HOST);
30   for (CeedInt i = 0; i < n; i++) {
31     if (b[i] != 10 + i) printf("Error reading array b[%" CeedInt_FMT "] = %f\n", i, (CeedScalar)b[i]);
32   }
33 
34   CeedVectorDestroy(&x);
35   CeedVectorDestroy(&y);
36   CeedDestroy(&ceed);
37   return 0;
38 }
39