10b8f3c4eSJeremy L Thompson /// @file 20b8f3c4eSJeremy L Thompson /// Test strided setting and copying of vectors 30b8f3c4eSJeremy L Thompson /// \test Test strided setting and copying of vectors 40b8f3c4eSJeremy L Thompson #include <ceed.h> 50b8f3c4eSJeremy L Thompson #include <stdio.h> 60b8f3c4eSJeremy L Thompson 70b8f3c4eSJeremy L Thompson int main(int argc, char **argv) { 80b8f3c4eSJeremy L Thompson Ceed ceed; 90b8f3c4eSJeremy L Thompson CeedSize start = 2, step = 3; 100b8f3c4eSJeremy L Thompson CeedVector x, y; 110b8f3c4eSJeremy L Thompson CeedInt len = 10; 120b8f3c4eSJeremy L Thompson 130b8f3c4eSJeremy L Thompson CeedInit(argv[1], &ceed); 140b8f3c4eSJeremy L Thompson 150b8f3c4eSJeremy L Thompson CeedVectorCreate(ceed, len, &x); 160b8f3c4eSJeremy L Thompson CeedVectorCreate(ceed, len, &y); 170b8f3c4eSJeremy L Thompson 180b8f3c4eSJeremy L Thompson // Set strided 190b8f3c4eSJeremy L Thompson CeedVectorSetValue(x, 1.0); 20*ff90b007SJeremy L Thompson CeedVectorSetValueStrided(x, start, -1, step, 42.0); 210b8f3c4eSJeremy L Thompson { 220b8f3c4eSJeremy L Thompson const CeedScalar *read_array; 230b8f3c4eSJeremy L Thompson 240b8f3c4eSJeremy L Thompson CeedVectorGetArrayRead(x, CEED_MEM_HOST, &read_array); 250b8f3c4eSJeremy L Thompson for (CeedInt i = 0; i < len; i++) { 260b8f3c4eSJeremy L Thompson CeedScalar value = (i - start) % step == 0 ? 42.0 : 1.0; 270b8f3c4eSJeremy L Thompson 280b8f3c4eSJeremy L Thompson if (read_array[i] != value) { 290b8f3c4eSJeremy L Thompson // LCOV_EXCL_START 300b8f3c4eSJeremy L Thompson printf("Error in setting value in x at index %" CeedInt_FMT ", computed: %f actual: %f\n", i, read_array[i], value); 310b8f3c4eSJeremy L Thompson // LCOV_EXCL_STOP 320b8f3c4eSJeremy L Thompson } 330b8f3c4eSJeremy L Thompson } 340b8f3c4eSJeremy L Thompson CeedVectorRestoreArrayRead(x, &read_array); 350b8f3c4eSJeremy L Thompson } 360b8f3c4eSJeremy L Thompson 370b8f3c4eSJeremy L Thompson // Copy strided 380b8f3c4eSJeremy L Thompson CeedVectorSetValue(y, 0.0); 390b8f3c4eSJeremy L Thompson CeedVectorCopyStrided(x, start, step, y); 400b8f3c4eSJeremy L Thompson { 410b8f3c4eSJeremy L Thompson const CeedScalar *read_array; 420b8f3c4eSJeremy L Thompson 430b8f3c4eSJeremy L Thompson CeedVectorGetArrayRead(y, CEED_MEM_HOST, &read_array); 440b8f3c4eSJeremy L Thompson for (CeedInt i = 0; i < len; i++) { 450b8f3c4eSJeremy L Thompson CeedScalar value = (i - start) % step == 0 ? 42.0 : 0.0; 460b8f3c4eSJeremy L Thompson 470b8f3c4eSJeremy L Thompson if (read_array[i] != value) { 480b8f3c4eSJeremy L Thompson // LCOV_EXCL_START 490b8f3c4eSJeremy L Thompson printf("Error in copying value to y at index %" CeedInt_FMT ", computed: %f actual: %f\n", i, read_array[i], value); 500b8f3c4eSJeremy L Thompson // LCOV_EXCL_STOP 510b8f3c4eSJeremy L Thompson } 520b8f3c4eSJeremy L Thompson } 530b8f3c4eSJeremy L Thompson CeedVectorRestoreArrayRead(y, &read_array); 540b8f3c4eSJeremy L Thompson } 550b8f3c4eSJeremy L Thompson 560b8f3c4eSJeremy L Thompson CeedVectorDestroy(&x); 570b8f3c4eSJeremy L Thompson CeedVectorDestroy(&y); 580b8f3c4eSJeremy L Thompson CeedDestroy(&ceed); 590b8f3c4eSJeremy L Thompson return 0; 600b8f3c4eSJeremy L Thompson } 61