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