1 /// @file 2 /// Test summing of a pair of vectors 3 /// \test Test y = alpha x + beta y 4 #include <ceed.h> 5 #include <math.h> 6 #include <stdio.h> 7 8 int main(int argc, char **argv) { 9 Ceed ceed; 10 CeedVector x, y; 11 CeedInt len = 10; 12 13 CeedInit(argv[1], &ceed); 14 15 CeedVectorCreate(ceed, len, &x); 16 CeedVectorCreate(ceed, len, &y); 17 { 18 CeedScalar array[len]; 19 20 for (CeedInt i = 0; i < len; i++) array[i] = 10 + i; 21 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, array); 22 CeedVectorSetArray(y, CEED_MEM_HOST, CEED_COPY_VALUES, array); 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 CeedVectorAXPBY(y, -0.5, 1.0, x); 31 32 { 33 const CeedScalar *read_array; 34 35 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &read_array); 36 for (CeedInt i = 0; i < len; i++) { 37 if (fabs(read_array[i] - (10.0 + i) * 1.5) > 1e-14) { 38 // LCOV_EXCL_START 39 printf("Error in alpha x + y at index %" CeedInt_FMT ", computed: %f actual: %f\n", i, read_array[i], (10.0 + i) * 1.5); 40 // LCOV_EXCL_STOP 41 } 42 } 43 CeedVectorRestoreArrayRead(y, &read_array); 44 } 45 46 CeedVectorDestroy(&x); 47 CeedVectorDestroy(&y); 48 CeedDestroy(&ceed); 49 return 0; 50 } 51