/// @file /// Test CeedVectorSetArray to remove array access /// \test Test CeedVectorSetArray to remove array access #include #include int main(int argc, char **argv) { Ceed ceed; CeedVector x; const CeedInt n = 10; CeedScalar a[n]; CeedScalar *b, *c; const CeedScalar *d; CeedInit(argv[1], &ceed); CeedVectorCreate(ceed, n, &x); for (CeedInt i=0; i 10.*CEED_EPSILON) // LCOV_EXCL_START printf("Error taking array c[3] = %f", (CeedScalar)c[3]); // LCOV_EXCL_STOP // Getting array should not modify a CeedVectorGetArrayWrite(x, CEED_MEM_HOST, &b); b[5] = -3.14; CeedVectorRestoreArray(x, &b); if (fabs(a[5] + 3.14) < 10.*CEED_EPSILON) // LCOV_EXCL_START printf("Error protecting array a[3] = %f", (CeedScalar)a[3]); // LCOV_EXCL_STOP // Note: We do not need to free c because c == a was stack allocated. CeedVectorDestroy(&x); // Test with a size zero vector CeedVectorCreate(ceed, 0, &x); CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, NULL); CeedVectorGetArrayRead(x, CEED_MEM_HOST, &d); if (b) printf("CeedVectorGetArrayRead returned non-NULL for zero-sized Vector"); CeedVectorRestoreArrayRead(x, &d); CeedVectorTakeArray(x, CEED_MEM_HOST, &c); if (c) printf("CeedVectorTakeArray returned non-NULL for zero-sized Vector"); CeedVectorDestroy(&x); CeedDestroy(&ceed); return 0; }