1 /// @file 2 /// Test pointwise muliplication of a pair of vectors 3 /// \test Test pointwise muliplication 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, w; 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 CeedVectorCreate(ceed, n, &w); 20 for (CeedInt i=0; i<n; i++) 21 a[i] = i; 22 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, a); 23 CeedVectorSetArray(y, CEED_MEM_HOST, CEED_COPY_VALUES, a); 24 25 // Test multiplying two vectors into third 26 CeedVectorPointwiseMult(w, x, y); 27 CeedVectorGetArrayRead(w, CEED_MEM_HOST, &b); 28 for (CeedInt i=0; i<n; i++) 29 if (fabs(b[i] - i*i ) > 1e-14) 30 // LCOV_EXCL_START 31 printf("Error in w = x .* y, computed: %f actual: %f\n", b[i], 1.0*i*i); 32 // LCOV_EXCL_STOP 33 CeedVectorRestoreArrayRead(w, &b); 34 35 // Test multiplying two vectors into one of the two 36 CeedVectorPointwiseMult(w, w, y); 37 CeedVectorGetArrayRead(w, CEED_MEM_HOST, &b); 38 for (CeedInt i=0; i<n; i++) 39 if (fabs(b[i] - i*i*i ) > 1e-14) 40 // LCOV_EXCL_START 41 printf("Error in w = w .* y, computed: %f actual: %f\n", b[i], 1.0*i*i*i); 42 // LCOV_EXCL_STOP 43 CeedVectorRestoreArrayRead(w, &b); 44 45 // Test multiplying two vectors into one of the two 46 CeedVectorPointwiseMult(w, x, w); 47 CeedVectorGetArrayRead(w, CEED_MEM_HOST, &b); 48 for (CeedInt i=0; i<n; i++) 49 if (fabs(b[i] - i*i*i*i ) > 1e-14) 50 // LCOV_EXCL_START 51 printf("Error in w = x .* w, computed: %f actual: %f\n", b[i], 1.0*i*i*i*i); 52 // LCOV_EXCL_STOP 53 CeedVectorRestoreArrayRead(w, &b); 54 55 // Test multiplying vector by itself and putting product into self 56 { 57 // Sync memtype to device for GPU backends 58 CeedMemType type = CEED_MEM_HOST; 59 CeedGetPreferredMemType(ceed, &type); 60 CeedVectorSyncArray(y, type); 61 } 62 CeedVectorPointwiseMult(y, y, y); 63 CeedVectorGetArrayRead(y, CEED_MEM_HOST, &b); 64 for (CeedInt i=0; i<n; i++) 65 if (fabs(b[i] - i*i ) > 1e-14) 66 // LCOV_EXCL_START 67 printf("Error in y = y .* y, computed: %f actual: %f\n", b[i], 1.0*i*i); 68 // LCOV_EXCL_STOP 69 CeedVectorRestoreArrayRead(y, &b); 70 71 CeedVectorDestroy(&x); 72 CeedVectorDestroy(&y); 73 CeedVectorDestroy(&w); 74 CeedDestroy(&ceed); 75 return 0; 76 } 77