Actual source code: benchmark_veccreate.c
1: static char help[] = "Benchmark VecCreate() for GPU vectors.\n\
2: -n <length> : vector length\n\n";
4: #include <petscvec.h>
5: #include <petsctime.h>
6: #include <petscdevice_cuda.h>
8: int main(int argc, char **argv)
9: {
10: PetscInt i, n = 5, iter = 10;
11: Vec x;
12: PetscLogDouble v0, v1;
13: PetscMemType memtype;
14: PetscScalar *array;
17: PetscInitialize(&argc, &argv, (char *)0, help);
18: PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL);
19: PetscOptionsGetInt(NULL, NULL, "-iter", &iter, NULL);
21: for (i = 0; i < iter; i++) {
22: PetscTime(&v0);
23: VecCreate(PETSC_COMM_WORLD, &x);
24: VecSetSizes(x, PETSC_DECIDE, n);
25: VecSetFromOptions(x);
26: /* make sure the vector's array exists */
27: VecGetArrayAndMemType(x, &array, &memtype);
28: VecRestoreArrayAndMemType(x, &array);
29: WaitForCUDA();
30: PetscTime(&v1);
31: VecDestroy(&x);
32: PetscPrintf(PETSC_COMM_WORLD, "Iteration %" PetscInt_FMT ": Time= %g\n", i, (double)(v1 - v0));
33: }
34: PetscFinalize();
35: return 0;
36: }
37: /*TEST
38: build:
39: requires: cuda
40: test:
41: args: -vec_type cuda
42: TEST*/