xref: /libCEED/tests/t103-vector.c (revision 151157ab1cfc57bfbb9fa07ee95eb9b023c32737)
1 /// @file
2 /// Test setting one vector from array of another vector
3 /// \test Test setting one vector from array of another vector
4 #include <ceed.h>
5 
6 int main(int argc, char **argv) {
7   Ceed ceed;
8   CeedVector X, Y;
9   CeedInt n;
10   CeedScalar a[10];
11   CeedScalar *x;
12   const CeedScalar *y;
13 
14   CeedInit(argv[1], &ceed);
15 
16   n = 10;
17   CeedVectorCreate(ceed, n, &X);
18   CeedVectorCreate(ceed, n, &Y);
19 
20   for (CeedInt i=0; i<n; i++)
21     a[i] = 10 + i;
22   CeedVectorSetArray(X, CEED_MEM_HOST, CEED_USE_POINTER, a);
23 
24   CeedVectorGetArray(X, CEED_MEM_HOST, &x);
25   CeedVectorSetArray(Y, CEED_MEM_HOST, CEED_COPY_VALUES, x);
26   CeedVectorRestoreArray(X, &x);
27 
28   CeedVectorGetArrayRead(Y, CEED_MEM_HOST, &y);
29   for (CeedInt i=0; i<n; i++)
30     if (y[i] != 10+i)
31       // LCOV_EXCL_START
32       printf("Error reading array y[%" CeedInt_FMT
33              "] = %f\n",i,(CeedScalar)y[i]);
34   // LCOV_EXCL_STOP
35   CeedVectorRestoreArrayRead(Y, &y);
36 
37   CeedVectorDestroy(&X);
38   CeedVectorDestroy(&Y);
39   CeedDestroy(&ceed);
40   return 0;
41 }
42