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