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++) 20 a[i] = 10 + i; 21 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, a); 22 CeedVectorSetArray(y, CEED_MEM_HOST, CEED_COPY_VALUES, a); 23 24 { 25 // Sync memtype to device for GPU backends 26 CeedMemType type = CEED_MEM_HOST; 27 CeedGetPreferredMemType(ceed, &type); 28 CeedVectorSyncArray(y, type); 29 } 30 CeedVectorAXPY(y, -0.5, x); 31 32 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &b); 33 for (CeedInt i=0; i<n; i++) 34 if (fabs(b[i] - (10.0 + i)/2 ) > 1e-14) 35 // LCOV_EXCL_START 36 printf("Error in alpha x + y, computed: %f actual: %f\n", b[i], 37 (10.0 + i)/2); 38 // LCOV_EXCL_STOP 39 CeedVectorRestoreArrayRead(y, &b); 40 41 CeedVectorDestroy(&x); 42 CeedVectorDestroy(&y); 43 CeedDestroy(&ceed); 44 return 0; 45 } 46