xref: /libCEED/tests/t126-vector.c (revision ba59ac12ef3579eea938de09e332a3a266c3cc08)
1 /// @file
2 /// Test creation, copying, and destroying of a vector
3 /// \test Test creation, copying, and destroying of a vector
4 #include <ceed.h>
5 
6 int main(int argc, char **argv) {
7   Ceed       ceed;
8   CeedVector x, x_copy;
9   CeedInt    len = 10;
10 
11   CeedInit(argv[1], &ceed);
12 
13   CeedVectorCreate(ceed, len, &x);
14   CeedVectorCreate(ceed, len, &x_copy);
15 
16   {
17     CeedScalar array[len], array_copy[len];
18 
19     for (CeedInt i = 0; i < len; i++) {
20       array[i]      = 10 + i;
21       array_copy[i] = i;
22     }
23 
24     CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, array);
25     CeedVectorSetArray(x_copy, CEED_MEM_HOST, CEED_COPY_VALUES, array_copy);
26   }
27 
28   CeedVectorCopy(x, x_copy);
29 
30   {
31     const CeedScalar *read_array;
32     // Check that new array from x_copy is the same as the original input array a
33     CeedVectorGetArrayRead(x_copy, CEED_MEM_HOST, &read_array);
34     for (CeedInt i = 0; i < len; i++) {
35       if ((10 + i) != read_array[i]) printf("Error in copying values of CeedVector\n");
36     }
37     CeedVectorRestoreArrayRead(x_copy, &read_array);
38   }
39   CeedVectorDestroy(&x);
40   CeedVectorDestroy(&x_copy);
41   CeedDestroy(&ceed);
42   return 0;
43 }
44