Actual source code: ex58.c
2: static char help[] = "Test VecCreate{Seq|MPI}CUDAWithArrays.\n\n";
4: #include "petsc.h"
6: int main(int argc, char **argv)
7: {
8: Vec x, y;
9: PetscMPIInt size;
10: PetscInt n = 5;
11: PetscScalar xHost[5] = {0., 1., 2., 3., 4.};
14: PetscInitialize(&argc, &argv, (char *)0, help);
15: MPI_Comm_size(PETSC_COMM_WORLD, &size);
17: if (size == 1) VecCreateSeqCUDAWithArrays(PETSC_COMM_WORLD, 1, n, xHost, NULL, &x);
18: else VecCreateMPICUDAWithArrays(PETSC_COMM_WORLD, 1, n, PETSC_DECIDE, xHost, NULL, &x);
20: /* print x should be equivalent too xHost */
21: VecView(x, PETSC_VIEWER_STDOUT_WORLD);
22: VecSet(x, 42.0);
23: /* print x should be all 42 */
24: VecView(x, PETSC_VIEWER_STDOUT_WORLD);
26: if (size == 1) VecCreateSeqWithArray(PETSC_COMM_WORLD, 1, n, xHost, &y);
27: else VecCreateMPIWithArray(PETSC_COMM_WORLD, 1, n, PETSC_DECIDE, xHost, &y);
29: /* print y should be all 42 */
30: VecView(y, PETSC_VIEWER_STDOUT_WORLD);
32: VecDestroy(&y);
33: VecDestroy(&x);
34: PetscFinalize();
35: return 0;
36: }
38: /*TEST
40: build:
41: requires: cuda
43: test:
44: nsize: 1
45: suffix: 1
47: test:
48: nsize: 2
49: suffix: 2
51: TEST*/