xref: /libCEED/tests/t106-vector.c (revision 600b7929b98f3d8efad5f619bace308a359a46af)
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++)
20     a[i] = 10 + i;
21   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
22 
23   for (CeedInt i=0; i<n; i++)
24     b[i] = 0;
25   CeedVectorSetArray(y, CEED_MEM_HOST, CEED_USE_POINTER, b);
26 
27   CeedVectorGetArrayRead(x, CEED_MEM_DEVICE, &c);
28   CeedVectorSetArray(y, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)c);
29   CeedVectorRestoreArrayRead(x, &c);
30 
31   CeedVectorSyncArray(y, CEED_MEM_HOST);
32   for (CeedInt i=0; i<n; i++)
33     if (b[i] != 10+i)
34       // LCOV_EXCL_START
35       printf("Error reading array b[%" CeedInt_FMT
36              "] = %f\n", i, (CeedScalar)b[i]);
37   // LCOV_EXCL_STOP
38 
39   CeedVectorDestroy(&x);
40   CeedVectorDestroy(&y);
41   CeedDestroy(&ceed);
42   return 0;
43 }
44