xref: /libCEED/tests/t119-vector.c (revision edab612303ce5c583510db4ec9520fcda426d3c1)
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   CeedVectorReciprocal(x);
22 
23   CeedVectorGetArrayRead(x, CEED_MEM_HOST, &b);
24   for (CeedInt i=0; i<n; i++)
25     if (fabs(b[i] - 1./(10+i)) > 1e-15)
26       // LCOV_EXCL_START
27       printf("Error reading array b[%d] = %f",i,(double)b[i]);
28   // LCOV_EXCL_STOP
29   CeedVectorRestoreArrayRead(x, &b);
30 
31   CeedVectorDestroy(&x);
32   CeedDestroy(&ceed);
33   return 0;
34 }
35