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