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