1 /// @file 2 /// Test summing of a pair of vectors 3 /// \test Test summing of a pair of vectors 4 #include <ceed.h> 5 #include <math.h> 6 7 int main(int argc, char **argv) { 8 Ceed ceed; 9 CeedVector x, y; 10 CeedInt n; 11 CeedScalar a[10]; 12 const CeedScalar *b; 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_COPY_VALUES, a); 21 CeedVectorSetArray(y, CEED_MEM_HOST, CEED_COPY_VALUES, a); 22 23 { 24 // Sync memtype to device for GPU backends 25 CeedMemType type = CEED_MEM_HOST; 26 CeedGetPreferredMemType(ceed, &type); 27 CeedVectorSyncArray(y, type); 28 } 29 CeedVectorAXPY(y, -0.5, x); 30 31 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &b); 32 for (CeedInt i = 0; i < n; i++) { 33 if (fabs(b[i] - (10.0 + i) / 2) > 1e-14) { 34 // LCOV_EXCL_START 35 printf("Error in alpha x + y at index %" CeedInt_FMT ", computed: %f actual: %f\n", i, b[i], (10.0 + i) / 2); 36 // LCOV_EXCL_STOP 37 } 38 } 39 CeedVectorRestoreArrayRead(y, &b); 40 41 CeedVectorDestroy(&x); 42 CeedVectorDestroy(&y); 43 CeedDestroy(&ceed); 44 return 0; 45 } 46