xref: /libCEED/tests/t124-vector.c (revision 4fee36f0a30516a0b5ad51bf7eb3b32d83efd623)
19c774eddSJeremy L Thompson /// @file
29c774eddSJeremy L Thompson /// Test CeedVectorGetArrayWrite to modify array
39c774eddSJeremy L Thompson /// \test Test CeedVectorGetArrayWrite to modify array
49c774eddSJeremy L Thompson #include <ceed.h>
59c774eddSJeremy L Thompson 
69c774eddSJeremy L Thompson int main(int argc, char **argv) {
79c774eddSJeremy L Thompson   Ceed          ceed;
89c774eddSJeremy L Thompson   CeedVector    x;
9*4fee36f0SJeremy L Thompson   const CeedInt len = 10;
109c774eddSJeremy L Thompson 
119c774eddSJeremy L Thompson   CeedInit(argv[1], &ceed);
129c774eddSJeremy L Thompson 
13*4fee36f0SJeremy L Thompson   CeedVectorCreate(ceed, len, &x);
14*4fee36f0SJeremy L Thompson   {
15*4fee36f0SJeremy L Thompson     CeedScalar *writable_array;
169c774eddSJeremy L Thompson 
17*4fee36f0SJeremy L Thompson     CeedVectorGetArrayWrite(x, CEED_MEM_HOST, &writable_array);
18*4fee36f0SJeremy L Thompson     for (CeedInt i = 0; i < len; i++) writable_array[i] = 3 * i;
19*4fee36f0SJeremy L Thompson     CeedVectorRestoreArray(x, &writable_array);
202b730f8bSJeremy L Thompson   }
21*4fee36f0SJeremy L Thompson   {
22*4fee36f0SJeremy L Thompson     const CeedScalar *read_array;
23*4fee36f0SJeremy L Thompson 
24*4fee36f0SJeremy L Thompson     CeedVectorGetArrayRead(x, CEED_MEM_HOST, (const CeedScalar **)&read_array);
25*4fee36f0SJeremy L Thompson     for (CeedInt i = 0; i < len; i++) {
26*4fee36f0SJeremy L Thompson       if (read_array[i] != (CeedScalar)(3 * i)) printf("Error writing array[%" CeedInt_FMT "] = %f\n", i, read_array[i]);
27*4fee36f0SJeremy L Thompson     }
28*4fee36f0SJeremy L Thompson     CeedVectorRestoreArrayRead(x, (const CeedScalar **)&read_array);
29*4fee36f0SJeremy L Thompson   }
309c774eddSJeremy L Thompson 
319c774eddSJeremy L Thompson   CeedVectorDestroy(&x);
329c774eddSJeremy L Thompson   CeedDestroy(&ceed);
339c774eddSJeremy L Thompson   return 0;
349c774eddSJeremy L Thompson }
35