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> 5*49aac155SJeremy L Thompson #include <stdio.h> 69c774eddSJeremy L Thompson 79c774eddSJeremy L Thompson int main(int argc, char **argv) { 89c774eddSJeremy L Thompson Ceed ceed; 99c774eddSJeremy L Thompson CeedVector x; 104fee36f0SJeremy L Thompson const CeedInt len = 10; 119c774eddSJeremy L Thompson 129c774eddSJeremy L Thompson CeedInit(argv[1], &ceed); 139c774eddSJeremy L Thompson 144fee36f0SJeremy L Thompson CeedVectorCreate(ceed, len, &x); 154fee36f0SJeremy L Thompson { 164fee36f0SJeremy L Thompson CeedScalar *writable_array; 179c774eddSJeremy L Thompson 184fee36f0SJeremy L Thompson CeedVectorGetArrayWrite(x, CEED_MEM_HOST, &writable_array); 194fee36f0SJeremy L Thompson for (CeedInt i = 0; i < len; i++) writable_array[i] = 3 * i; 204fee36f0SJeremy L Thompson CeedVectorRestoreArray(x, &writable_array); 212b730f8bSJeremy L Thompson } 224fee36f0SJeremy L Thompson { 234fee36f0SJeremy L Thompson const CeedScalar *read_array; 244fee36f0SJeremy L Thompson 254fee36f0SJeremy L Thompson CeedVectorGetArrayRead(x, CEED_MEM_HOST, (const CeedScalar **)&read_array); 264fee36f0SJeremy L Thompson for (CeedInt i = 0; i < len; i++) { 274fee36f0SJeremy L Thompson if (read_array[i] != (CeedScalar)(3 * i)) printf("Error writing array[%" CeedInt_FMT "] = %f\n", i, read_array[i]); 284fee36f0SJeremy L Thompson } 294fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(x, (const CeedScalar **)&read_array); 304fee36f0SJeremy L Thompson } 319c774eddSJeremy L Thompson 329c774eddSJeremy L Thompson CeedVectorDestroy(&x); 339c774eddSJeremy L Thompson CeedDestroy(&ceed); 349c774eddSJeremy L Thompson return 0; 359c774eddSJeremy L Thompson } 36