xref: /petsc/src/mat/tests/ex199.c (revision 609caa7c8c030312b00807b4f015fd827bb80932)
1 static char help[] = "Tests the different MatColoring implementations.\n\n";
2 
3 #include <petscmat.h>
4 
main(int argc,char ** args)5 int main(int argc, char **args)
6 {
7   Mat         C;
8   PetscViewer viewer;
9   char        file[128];
10   PetscBool   flg;
11   MatColoring ctx;
12   ISColoring  coloring;
13   PetscMPIInt size;
14 
15   PetscFunctionBeginUser;
16   PetscCall(PetscInitialize(&argc, &args, NULL, help));
17   PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
18 
19   PetscCall(PetscOptionsGetString(NULL, NULL, "-f", file, sizeof(file), &flg));
20   PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_USER, "Must use -f filename to load sparse matrix");
21   PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD, file, FILE_MODE_READ, &viewer));
22   PetscCall(MatCreate(PETSC_COMM_WORLD, &C));
23   PetscCall(MatLoad(C, viewer));
24   PetscCall(PetscViewerDestroy(&viewer));
25 
26   PetscCall(MatColoringCreate(C, &ctx));
27   PetscCall(MatColoringSetFromOptions(ctx));
28   PetscCall(MatColoringApply(ctx, &coloring));
29   PetscCall(MatColoringTest(ctx, coloring));
30   if (size == 1) {
31     /* jp, power and greedy have bug -- need to be fixed */
32     PetscCall(MatISColoringTest(C, coloring));
33   }
34 
35   /* Free data structures */
36   PetscCall(ISColoringDestroy(&coloring));
37   PetscCall(MatColoringDestroy(&ctx));
38   PetscCall(MatDestroy(&C));
39   PetscCall(PetscFinalize());
40   return 0;
41 }
42 
43 /*TEST
44 
45    test:
46       nsize: {{3}}
47       requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
48       args: -f ${DATAFILESPATH}/matrices/arco1 -mat_coloring_type {{ jp power natural greedy}} -mat_coloring_distance {{ 1 2}}
49       output_file: output/empty.out
50 
51    test:
52       suffix: 2
53       nsize: {{1 2}}
54       requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
55       args: -f ${DATAFILESPATH}/matrices/arco1 -mat_coloring_type {{sl lf id}} -mat_coloring_distance 2
56       output_file: output/empty.out
57 
58 TEST*/
59