1 /// @file 2 /// Test creation, setting, reading, restoring, and destroying of a vector using CEED_MEM_DEVICE 3 /// \test Test creation, setting, reading, restoring, and destroying of a vector 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]; 12 const CeedScalar *b, *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 CeedVectorGetArrayRead(x, CEED_MEM_DEVICE, &b); 23 CeedVectorSetArray(y, CEED_MEM_DEVICE, CEED_COPY_VALUES, (CeedScalar *)b); 24 CeedVectorRestoreArrayRead(x, &b); 25 26 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &c); 27 for (CeedInt i = 0; i < n; i++) { 28 if (c[i] != 10 + i) printf("Error reading array c[%" CeedInt_FMT "] = %f\n", i, (CeedScalar)c[i]); 29 } 30 CeedVectorRestoreArrayRead(y, &c); 31 32 CeedVectorDestroy(&x); 33 CeedVectorDestroy(&y); 34 CeedDestroy(&ceed); 35 return 0; 36 } 37