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[%d] = %f", i, (CeedScalar)b[i]); 36 // LCOV_EXCL_STOP 37 38 CeedVectorDestroy(&x); 39 CeedVectorDestroy(&y); 40 CeedDestroy(&ceed); 41 return 0; 42 } 43