1 /// @file 2 /// Test taking the reciprocal of a vector 3 /// \test Test taking the reciprocal of a vector 4 #include <math.h> 5 #include <ceed.h> 6 7 int main(int argc, char **argv) { 8 Ceed ceed; 9 CeedVector x; 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 for (CeedInt i=0; i<n; i++) 19 a[i] = 10 + i; 20 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a); 21 { 22 // Sync memtype to device for GPU backends 23 CeedMemType type = CEED_MEM_HOST; 24 CeedGetPreferredMemType(ceed, &type); 25 CeedVectorSyncArray(x, type); 26 } 27 CeedVectorReciprocal(x); 28 29 CeedVectorGetArrayRead(x, CEED_MEM_HOST, &b); 30 for (CeedInt i=0; i<n; i++) 31 if (fabs(b[i] - 1./(10+i)) > 10.*CEED_EPSILON) 32 // LCOV_EXCL_START 33 printf("Error reading array b[%d] = %f",i,(CeedScalar)b[i]); 34 // LCOV_EXCL_STOP 35 CeedVectorRestoreArrayRead(x, &b); 36 37 CeedVectorDestroy(&x); 38 CeedDestroy(&ceed); 39 return 0; 40 } 41