Actual source code: ex217.c
1: static char help[] = "Tests MatGetCurrentMemType for gpu type matrices both bound and unbound to cpu";
3: #include <petscmat.h>
4: #include <../src/mat/impls/aij/mpi/mpiaij.h>
6: int main(int argc, char **argv)
7: {
8: Mat A;
9: PetscMemType memtype;
10: MatType mattype;
11: PetscBool ishypre, iskokkos, iscuda, iship;
13: PetscFunctionBeginUser;
14: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
15: PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
16: PetscCall(MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, 1, 1));
17: PetscCall(MatSetFromOptions(A));
18: PetscCall(MatGetType(A, &mattype));
19: PetscCall(PetscObjectTypeCompareAny((PetscObject)A, &iscuda, MATMPIAIJCUSPARSE, MATSEQAIJCUSPARSE, ""));
20: PetscCall(PetscObjectTypeCompareAny((PetscObject)A, &iship, MATMPIAIJHIPSPARSE, MATSEQAIJHIPSPARSE, ""));
21: PetscCall(PetscObjectTypeCompareAny((PetscObject)A, &iskokkos, MATMPIAIJKOKKOS, MATSEQAIJKOKKOS, ""));
22: PetscCall(PetscObjectTypeCompare((PetscObject)A, MATHYPRE, &ishypre));
23: #if defined(PETSC_HAVE_HYPRE)
24: PetscCall(MatHYPRESetPreallocation(A, 1, NULL, 1, NULL));
25: #endif
26: PetscCall(MatSeqAIJSetPreallocation(A, 1, NULL));
27: PetscCall(MatMPIAIJSetPreallocation(A, 1, NULL, 1, NULL));
29: PetscCall(MatGetCurrentMemType(A, &memtype));
30: if (iscuda) PetscCheck(memtype == PETSC_MEMTYPE_CUDA, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "wrong memory type");
31: else if (iship) PetscCheck(memtype == PETSC_MEMTYPE_HIP, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "wrong memory type");
32: else if (iskokkos) PetscCheck(memtype == PETSC_MEMTYPE_KOKKOS, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "wrong memory type");
33: else if (ishypre) PetscCheck(PetscDefined(HAVE_HYPRE_DEVICE) ? memtype == PETSC_MEMTYPE_DEVICE : memtype == PETSC_MEMTYPE_HOST, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "wrong memory type");
34: else PetscCheck(memtype == PETSC_MEMTYPE_HOST, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "wrong memory type");
36: // Kokkos doesn't currently implement MatBindToCPU
37: if (!iskokkos) {
38: PetscCall(MatBindToCPU(A, PETSC_TRUE));
39: PetscCall(MatGetCurrentMemType(A, &memtype));
40: PetscCheck(memtype == PETSC_MEMTYPE_HOST, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "wrong memory type");
41: }
42: PetscCall(MatDestroy(&A));
43: PetscCall(PetscFinalize());
44: return 0;
45: }
47: /*TEST
49: test:
50: suffix: seqaij
51: args: -mat_type aij
52: output_file: output/empty.out
54: test:
55: suffix: mpiaij
56: nsize: 2
57: args: -mat_type aij
58: output_file: output/empty.out
60: test:
61: requires: cuda
62: suffix: seqaijcusparse
63: args: -mat_type aijcusparse
64: output_file: output/empty.out
66: test:
67: requires: cuda
68: suffix: mpiaijcusparse
69: nsize: 2
70: args: -mat_type aijcusparse
71: output_file: output/empty.out
73: test:
74: requires: hip
75: suffix: seqaijhipsparse
76: args: -mat_type aijhipsparse
77: output_file: output/empty.out
79: test:
80: requires: hip
81: suffix: mpiaijhipsparse
82: nsize: 2
83: args: -mat_type aijhipsparse
84: output_file: output/empty.out
86: test:
87: requires: kokkos_kernels
88: suffix: seqaijkokkos
89: args: -mat_type aijkokkos
90: output_file: output/empty.out
92: test:
93: requires: kokkos_kernels
94: suffix: mpiaijkokkos
95: nsize: 2
96: args: -mat_type aijkokkos
97: output_file: output/empty.out
99: test:
100: requires: hypre
101: suffix: hypre
102: args: -mat_type hypre
103: output_file: output/empty.out
105: test:
106: requires: hypre
107: suffix: hypre_parallel
108: nsize: 2
109: args: -mat_type hypre
110: output_file: output/empty.out
112: TEST*/