File: gamg.c.html

package info (click to toggle)
petsc 3.23.1%2Bdfsg1-1exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 515,576 kB
  • sloc: ansic: 751,607; cpp: 51,542; python: 38,598; f90: 17,352; javascript: 3,493; makefile: 3,157; sh: 1,502; xml: 619; objc: 445; java: 13; csh: 1
file content (2101 lines) | stat: -rw-r--r-- 303,858 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
<center><a href="https://gitlab.com/petsc/petsc/-/blob/966382dc56242773704ef5f5cee7aa2db3ebc577/src/ksp/pc/impls/gamg/gamg.c">Actual source code: gamg.c</a></center><br>

<html>
<head>
<title></title>
<meta name="generator" content="c2html 0.9.6">
<meta name="date" content="2025-04-30T18:15:01+00:00">
</head>

<body bgcolor="#FFFFFF">
<pre width=80>
<a name="line1">  1: </a><font color="#B22222">/*</font>
<a name="line2">  2: </a><font color="#B22222"> GAMG geometric-algebric multigrid <a href="../../../../../manualpages/PC/PC.html">PC</a> - Mark Adams 2011</font>
<a name="line3">  3: </a><font color="#B22222"> */</font>
<a name="line4">  4: </a>#include <A href="../../../../src/ksp/pc/impls/gamg/gamg.h.html">&lt;../src/ksp/pc/impls/gamg/gamg.h&gt;</A>
<a name="line5">  5: </a>#include <A href="../../../../src/ksp/ksp/impls/cheby/chebyshevimpl.h.html">&lt;../src/ksp/ksp/impls/cheby/chebyshevimpl.h&gt;</A>

<a name="line7">  7: </a><font color="#A020F0">#if defined(PETSC_HAVE_CUDA)</font>
<a name="line8">  8: </a><font color="#A020F0">  #include &lt;cuda_runtime.h&gt;</font>
<a name="line9">  9: </a><font color="#A020F0">#endif</font>

<a name="line11"> 11: </a><font color="#A020F0">#if defined(PETSC_HAVE_HIP)</font>
<a name="line12"> 12: </a><font color="#A020F0">  #include &lt;hip/hip_runtime.h&gt;</font>
<a name="line13"> 13: </a><font color="#A020F0">#endif</font>

<a name="line15"> 15: </a><a href="../../../../../manualpages/Log/PetscLogEvent.html">PetscLogEvent</a> petsc_gamg_setup_events[GAMG_NUM_SET];
<a name="line16"> 16: </a><a href="../../../../../manualpages/Log/PetscLogEvent.html">PetscLogEvent</a> petsc_gamg_setup_matmat_events[PETSC_MG_MAXLEVELS][3];

<a name="line18"> 18: </a><font color="#B22222">// #define GAMG_STAGES</font>
<a name="line19"> 19: </a><font color="#A020F0">#if defined(GAMG_STAGES)</font>
<a name="line20"> 20: </a>static <a href="../../../../../manualpages/Log/PetscLogStage.html">PetscLogStage</a> gamg_stages[PETSC_MG_MAXLEVELS];
<a name="line21"> 21: </a><font color="#A020F0">#endif</font>

<a name="line23"> 23: </a>static <a href="../../../../../manualpages/Sys/PetscFunctionList.html">PetscFunctionList</a> GAMGList = NULL;
<a name="line24"> 24: </a>static <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a>         PCGAMGPackageInitialized;

<a name="line26"> 26: </a><strong><font color="#4169E1"><a name="PCReset_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCReset_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc)</font></strong>
<a name="line27"> 27: </a>{
<a name="line28"> 28: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line29"> 29: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line31"> 31: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line32"> 32: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(pc_gamg-&gt;data));
<a name="line33"> 33: </a>  pc_gamg-&gt;data_sz = 0;
<a name="line34"> 34: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(pc_gamg-&gt;orig_data));
<a name="line35"> 35: </a>  <font color="#4169E1">for</font> (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> level = 0; level &lt; PETSC_MG_MAXLEVELS; level++) {
<a name="line36"> 36: </a>    mg-&gt;min_eigen_DinvA[level] = 0;
<a name="line37"> 37: </a>    mg-&gt;max_eigen_DinvA[level] = 0;
<a name="line38"> 38: </a>  }
<a name="line39"> 39: </a>  pc_gamg-&gt;emin = 0;
<a name="line40"> 40: </a>  pc_gamg-&gt;emax = 0;
<a name="line41"> 41: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCReset_MG(pc));
<a name="line42"> 42: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatCoarsenDestroy.html">MatCoarsenDestroy</a>(&amp;pc_gamg-&gt;asm_crs));
<a name="line43"> 43: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line44"> 44: </a>}

<a name="line46"> 46: </a><font color="#B22222">/*</font>
<a name="line47"> 47: </a><font color="#B22222">   PCGAMGCreateLevel_GAMG: create coarse op with RAP.  repartition and/or reduce number</font>
<a name="line48"> 48: </a><font color="#B22222">     of active processors.</font>

<a name="line50"> 50: </a><font color="#B22222">   Input Parameter:</font>
<a name="line51"> 51: </a><font color="#B22222">   . pc - parameters + side effect: coarse data in 'pc_gamg-&gt;data' and</font>
<a name="line52"> 52: </a><font color="#B22222">          'pc_gamg-&gt;data_sz' are changed via repartitioning/reduction.</font>
<a name="line53"> 53: </a><font color="#B22222">   . Amat_fine - matrix on this fine (k) level</font>
<a name="line54"> 54: </a><font color="#B22222">   . cr_bs - coarse block size</font>
<a name="line55"> 55: </a><font color="#B22222">   In/Output Parameter:</font>
<a name="line56"> 56: </a><font color="#B22222">   . a_P_inout - prolongation operator to the next level (k--&gt;k-1)</font>
<a name="line57"> 57: </a><font color="#B22222">   . a_nactive_proc - number of active procs</font>
<a name="line58"> 58: </a><font color="#B22222">   Output Parameter:</font>
<a name="line59"> 59: </a><font color="#B22222">   . a_Amat_crs - coarse matrix that is created (k-1)</font>
<a name="line60"> 60: </a><font color="#B22222">*/</font>
<a name="line61"> 61: </a><strong><font color="#4169E1"><a name="PCGAMGCreateLevel_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGCreateLevel_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Mat/Mat.html">Mat</a> Amat_fine, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> cr_bs, <a href="../../../../../manualpages/Mat/Mat.html">Mat</a> *a_P_inout, <a href="../../../../../manualpages/Mat/Mat.html">Mat</a> *a_Amat_crs, <a href="../../../../../manualpages/Sys/PetscMPIInt.html">PetscMPIInt</a> *a_nactive_proc, <a href="../../../../../manualpages/IS/IS.html">IS</a> *Pcolumnperm, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> is_last)</font></strong>
<a name="line62"> 62: </a>{
<a name="line63"> 63: </a>  PC_MG      *mg      = (PC_MG *)pc-&gt;data;
<a name="line64"> 64: </a>  PC_GAMG    *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;
<a name="line65"> 65: </a>  <a href="../../../../../manualpages/Mat/Mat.html">Mat</a>         Cmat = NULL, Pold = *a_P_inout;
<a name="line66"> 66: </a>  <a href="../../../../../manualpages/Sys/MPI_Comm.html">MPI_Comm</a>    comm;
<a name="line67"> 67: </a>  <a href="../../../../../manualpages/Sys/PetscMPIInt.html">PetscMPIInt</a> rank, size, new_size, nactive = *a_nactive_proc;
<a name="line68"> 68: </a>  <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>    ncrs_eq, ncrs, f_bs;

<a name="line70"> 70: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line71"> 71: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectGetComm.html">PetscObjectGetComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)Amat_fine, &amp;comm));
<a name="line72"> 72: </a>  <a href="../../../../../manualpages/Sys/PetscCallMPI.html">PetscCallMPI</a>(<a href="http://www.mpich.org/static/docs/latest/www3/MPI_Comm_rank.html#MPI_Comm_rank">MPI_Comm_rank</a>(comm, &amp;rank));
<a name="line73"> 73: </a>  <a href="../../../../../manualpages/Sys/PetscCallMPI.html">PetscCallMPI</a>(<a href="http://www.mpich.org/static/docs/latest/www3/MPI_Comm_size.html#MPI_Comm_size">MPI_Comm_size</a>(comm, &amp;size));
<a name="line74"> 74: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetBlockSize.html">MatGetBlockSize</a>(Amat_fine, &amp;f_bs));

<a name="line76"> 76: </a>  <font color="#4169E1">if</font> (Pcolumnperm) *Pcolumnperm = NULL;

<a name="line78"> 78: </a>  <font color="#B22222">/* set 'ncrs' (nodes), 'ncrs_eq' (equations)*/</font>
<a name="line79"> 79: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetLocalSize.html">MatGetLocalSize</a>(Pold, NULL, &amp;ncrs_eq));
<a name="line80"> 80: </a>  <font color="#4169E1">if</font> (pc_gamg-&gt;data_cell_rows &gt; 0) {
<a name="line81"> 81: </a>    ncrs = pc_gamg-&gt;data_sz / pc_gamg-&gt;data_cell_cols / pc_gamg-&gt;data_cell_rows;
<a name="line82"> 82: </a>  } <font color="#4169E1">else</font> {
<a name="line83"> 83: </a>    <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> bs;
<a name="line84"> 84: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetBlockSizes.html">MatGetBlockSizes</a>(Pold, NULL, &amp;bs));
<a name="line85"> 85: </a>    ncrs = ncrs_eq / bs;
<a name="line86"> 86: </a>  }
<a name="line87"> 87: </a>  <font color="#B22222">/* get number of PEs to make active 'new_size', reduce, can be any integer 1-P */</font>
<a name="line88"> 88: </a>  <font color="#4169E1">if</font> (pc_gamg-&gt;level_reduction_factors[pc_gamg-&gt;current_level] == 0 &amp;&amp; <a href="../../../../../manualpages/Sys/PetscDefined.html">PetscDefined</a>(HAVE_CUDA) &amp;&amp; pc_gamg-&gt;current_level == 0) { <font color="#B22222">/* 0 turns reducing to 1 process/device on; do for HIP, etc. */</font>
<a name="line89"> 89: </a><font color="#A020F0">#if defined(PETSC_HAVE_CUDA)</font>
<a name="line90"> 90: </a>    PetscShmComm pshmcomm;
<a name="line91"> 91: </a>    <a href="../../../../../manualpages/Sys/PetscMPIInt.html">PetscMPIInt</a>  locrank;
<a name="line92"> 92: </a>    <a href="../../../../../manualpages/Sys/MPI_Comm.html">MPI_Comm</a>     loccomm;
<a name="line93"> 93: </a>    <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>     s_nnodes, r_nnodes, new_new_size;
<a name="line94"> 94: </a>    cudaError_t  cerr;
<a name="line95"> 95: </a>    int          devCount;
<a name="line96"> 96: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscShmCommGet.html">PetscShmCommGet</a>(comm, &amp;pshmcomm));
<a name="line97"> 97: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscShmCommGetMpiShmComm.html">PetscShmCommGetMpiShmComm</a>(pshmcomm, &amp;loccomm));
<a name="line98"> 98: </a>    <a href="../../../../../manualpages/Sys/PetscCallMPI.html">PetscCallMPI</a>(<a href="http://www.mpich.org/static/docs/latest/www3/MPI_Comm_rank.html#MPI_Comm_rank">MPI_Comm_rank</a>(loccomm, &amp;locrank));
<a name="line99"> 99: </a>    s_nnodes = !locrank;
<a name="line100">100: </a>    <a href="../../../../../manualpages/Sys/PetscCallMPI.html">PetscCallMPI</a>(<a href="../../../../../manualpages/Sys/MPIU_Allreduce.html">MPIU_Allreduce</a>(&amp;s_nnodes, &amp;r_nnodes, 1, <a href="../../../../../manualpages/Sys/MPIU_INT.html">MPIU_INT</a>, MPI_SUM, comm));
<a name="line101">101: </a>    <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>((size % r_nnodes) == 0, <a href="../../../../../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_PLIB</a>, <font color="#666666">"odd number of nodes np=%d nnodes%"</font> PetscInt_FMT, size, r_nnodes);
<a name="line102">102: </a>    devCount = 0;
<a name="line103">103: </a>    cerr     = cudaGetDeviceCount(&amp;devCount);
<a name="line104">104: </a>    cudaGetLastError();                         <font color="#B22222">/* Reset the last error */</font>
<a name="line105">105: </a>    <font color="#4169E1">if</font> (cerr == cudaSuccess &amp;&amp; devCount &gt;= 1) { <font color="#B22222">/* There are devices, else go to heuristic */</font>
<a name="line106">106: </a>      new_new_size = r_nnodes * devCount;
<a name="line107">107: </a>      new_size     = new_new_size;
<a name="line108">108: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: Fine grid with Cuda. %"</font> PetscInt_FMT <font color="#666666">" nodes. Change new active set size %d --&gt; %d (devCount=%d #nodes=%"</font> PetscInt_FMT <font color="#666666">")\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, r_nnodes, nactive, new_size, devCount, r_nnodes));
<a name="line109">109: </a>    } <font color="#4169E1">else</font> {
<a name="line110">110: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: With Cuda but no device. Use heuristics.\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix));
<a name="line111">111: </a>      <font color="#4169E1">goto</font> HEURISTIC;
<a name="line112">112: </a>    }
<a name="line113">113: </a><font color="#A020F0">#else</font>
<a name="line114">114: </a>    <a href="../../../../../manualpages/Sys/SETERRQ.html">SETERRQ</a>(<a href="../../../../../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_PLIB</a>, <font color="#666666">"should not be here"</font>);
<a name="line115">115: </a><font color="#A020F0">#endif</font>
<a name="line116">116: </a>  } <font color="#4169E1">else</font> <font color="#4169E1">if</font> (pc_gamg-&gt;level_reduction_factors[pc_gamg-&gt;current_level] &gt; 0) {
<a name="line117">117: </a>    <font color="#4169E1">if</font> (nactive &lt; pc_gamg-&gt;level_reduction_factors[pc_gamg-&gt;current_level]) {
<a name="line118">118: </a>      new_size = 1;
<a name="line119">119: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: reduction factor too small for %d active processes: reduce to one process\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, new_size));
<a name="line120">120: </a>    } <font color="#4169E1">else</font> {
<a name="line121">121: </a>      <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(nactive % pc_gamg-&gt;level_reduction_factors[pc_gamg-&gt;current_level] == 0, <a href="../../../../../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_PLIB</a>, <font color="#666666">"odd number of active process %d wrt reduction factor %"</font> PetscInt_FMT, nactive, pc_gamg-&gt;level_reduction_factors[pc_gamg-&gt;current_level]);
<a name="line122">122: </a>      new_size = nactive / pc_gamg-&gt;level_reduction_factors[pc_gamg-&gt;current_level];
<a name="line123">123: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: Manually setting reduction to %d active processes (%d/%"</font> PetscInt_FMT <font color="#666666">")\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, new_size, nactive, pc_gamg-&gt;level_reduction_factors[pc_gamg-&gt;current_level]));
<a name="line124">124: </a>    }
<a name="line125">125: </a>  } <font color="#4169E1">else</font> <font color="#4169E1">if</font> (is_last &amp;&amp; !pc_gamg-&gt;use_parallel_coarse_grid_solver) {
<a name="line126">126: </a>    new_size = 1;
<a name="line127">127: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: Force coarsest grid reduction to %d active processes\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, new_size));
<a name="line128">128: </a>  } <font color="#4169E1">else</font> {
<a name="line129">129: </a>    <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> ncrs_eq_glob;
<a name="line130">130: </a><font color="#A020F0">#if defined(PETSC_HAVE_CUDA)</font>
<a name="line131">131: </a>  HEURISTIC:
<a name="line132">132: </a><font color="#A020F0">#endif</font>
<a name="line133">133: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetSize.html">MatGetSize</a>(Pold, NULL, &amp;ncrs_eq_glob));
<a name="line134">134: </a>    new_size = (<a href="../../../../../manualpages/Sys/PetscMPIInt.html">PetscMPIInt</a>)((float)ncrs_eq_glob / (float)pc_gamg-&gt;min_eq_proc + 0.5); <font color="#B22222">/* hardwire min. number of eq/proc */</font>
<a name="line135">135: </a>    <font color="#4169E1">if</font> (!new_size) new_size = 1;                                                       <font color="#B22222">/* not likely, possible? */</font>
<a name="line136">136: </a>    <font color="#4169E1">else</font> <font color="#4169E1">if</font> (new_size &gt;= nactive) new_size = nactive;                                  <font color="#B22222">/* no change, rare */</font>
<a name="line137">137: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: Coarse grid reduction from %d to %d active processes\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, nactive, new_size));
<a name="line138">138: </a>  }
<a name="line139">139: </a>  <font color="#4169E1">if</font> (new_size == nactive) {
<a name="line140">140: </a>    <font color="#B22222">/* output - no repartitioning or reduction - could bail here</font>
<a name="line141">141: </a><font color="#B22222">       we know that the grid structure can be reused in <a href="../../../../../manualpages/Mat/MatPtAP.html">MatPtAP</a> */</font>
<a name="line142">142: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_events[GAMG_PTAP], 0, 0, 0, 0));
<a name="line143">143: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_matmat_events[pc_gamg-&gt;current_level][1], 0, 0, 0, 0));
<a name="line144">144: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatPtAP.html">MatPtAP</a>(Amat_fine, Pold, <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_INITIAL_MATRIX</a>, 2.0, a_Amat_crs));
<a name="line145">145: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_matmat_events[pc_gamg-&gt;current_level][1], 0, 0, 0, 0));
<a name="line146">146: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_events[GAMG_PTAP], 0, 0, 0, 0));
<a name="line147">147: </a>    <font color="#4169E1">if</font> (new_size &lt; size) {
<a name="line148">148: </a>      <font color="#B22222">/* odd case where multiple coarse grids are on one processor or no coarsening ... */</font>
<a name="line149">149: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: reduced grid using same number of processors (%d) as last grid (use larger coarse grid)\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, nactive));
<a name="line150">150: </a>      <font color="#4169E1">if</font> (pc_gamg-&gt;cpu_pin_coarse_grids) {
<a name="line151">151: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatBindToCPU.html">MatBindToCPU</a>(*a_Amat_crs, <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>));
<a name="line152">152: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatBindToCPU.html">MatBindToCPU</a>(*a_P_inout, <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>));
<a name="line153">153: </a>      }
<a name="line154">154: </a>    }
<a name="line155">155: </a>  } <font color="#4169E1">else</font> { <font color="#B22222">/* reduce active processors - we know that the grid structure can NOT be reused in <a href="../../../../../manualpages/Mat/MatPtAP.html">MatPtAP</a> */</font>
<a name="line156">156: </a>    <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> *counts, *newproc_idx, ii, jj, kk, strideNew, *tidx, ncrs_new, ncrs_eq_new, nloc_old, expand_factor = 1, rfactor = 1;
<a name="line157">157: </a>    <a href="../../../../../manualpages/IS/IS.html">IS</a>        is_eq_newproc, is_eq_num, new_eq_indices;
<a name="line158">158: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_events[GAMG_REDUCE], 0, 0, 0, 0));
<a name="line159">159: </a>    nloc_old = ncrs_eq / cr_bs;
<a name="line160">160: </a>    <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(ncrs_eq % cr_bs == 0, <a href="../../../../../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_PLIB</a>, <font color="#666666">"ncrs_eq %"</font> PetscInt_FMT <font color="#666666">" not divisible by cr_bs %"</font> PetscInt_FMT, ncrs_eq, cr_bs);
<a name="line161">161: </a>    <font color="#B22222">/* get new_size and rfactor */</font>
<a name="line162">162: </a>    <font color="#4169E1">if</font> (pc_gamg-&gt;layout_type == <a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMG_LAYOUT_SPREAD</a> || !pc_gamg-&gt;repart) {
<a name="line163">163: </a>      <font color="#B22222">/* find factor */</font>
<a name="line164">164: </a>      <font color="#4169E1">if</font> (new_size == 1) rfactor = size; <font color="#B22222">/* don't modify */</font>
<a name="line165">165: </a>      <font color="#4169E1">else</font> {
<a name="line166">166: </a>        <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> best_fact = 0.;
<a name="line167">167: </a>        jj                  = -1;
<a name="line168">168: </a>        <font color="#4169E1">for</font> (kk = 1; kk &lt;= size; kk++) {
<a name="line169">169: </a>          <font color="#4169E1">if</font> (!(size % kk)) { <font color="#B22222">/* a candidate */</font>
<a name="line170">170: </a>            <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> nactpe = (<a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a>)size / (<a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a>)kk, fact = nactpe / (<a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a>)new_size;
<a name="line171">171: </a>            <font color="#4169E1">if</font> (fact &gt; 1.0) fact = 1. / fact; <font color="#B22222">/* keep fact &lt; 1 */</font>
<a name="line172">172: </a>            <font color="#4169E1">if</font> (fact &gt; best_fact) {
<a name="line173">173: </a>              best_fact = fact;
<a name="line174">174: </a>              jj        = kk;
<a name="line175">175: </a>            }
<a name="line176">176: </a>          }
<a name="line177">177: </a>        }
<a name="line178">178: </a>        <font color="#4169E1">if</font> (jj != -1) rfactor = jj;
<a name="line179">179: </a>        <font color="#4169E1">else</font> rfactor = 1; <font color="#B22222">/* a prime */</font>
<a name="line180">180: </a>        <font color="#4169E1">if</font> (pc_gamg-&gt;layout_type == <a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMG_LAYOUT_COMPACT</a>) expand_factor = 1;
<a name="line181">181: </a>        <font color="#4169E1">else</font> expand_factor = rfactor;
<a name="line182">182: </a>      }
<a name="line183">183: </a>      new_size = size / rfactor; <font color="#B22222">/* make new size one that is factor */</font>
<a name="line184">184: </a>      <font color="#4169E1">if</font> (new_size == nactive) { <font color="#B22222">/* no repartitioning or reduction, bail out because nested here (rare) */</font>
<a name="line185">185: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: Finding factorable processor set stopped reduction: new_size=%d, neq(loc)=%"</font> PetscInt_FMT <font color="#666666">"\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, new_size, ncrs_eq));
<a name="line186">186: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_events[GAMG_REDUCE], 0, 0, 0, 0));
<a name="line187">187: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_events[GAMG_PTAP], 0, 0, 0, 0));
<a name="line188">188: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_matmat_events[pc_gamg-&gt;current_level][1], 0, 0, 0, 0));
<a name="line189">189: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatPtAP.html">MatPtAP</a>(Amat_fine, Pold, <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_INITIAL_MATRIX</a>, 2.0, a_Amat_crs));
<a name="line190">190: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_matmat_events[pc_gamg-&gt;current_level][1], 0, 0, 0, 0));
<a name="line191">191: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_events[GAMG_PTAP], 0, 0, 0, 0));
<a name="line192">192: </a>        <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line193">193: </a>      }
<a name="line194">194: </a>    }
<a name="line195">195: </a>    <font color="#B22222">/* make 'is_eq_newproc' */</font>
<a name="line196">196: </a>    <font color="#4169E1">if</font> (pc_gamg-&gt;repart) { <font color="#B22222">/* Repartition Cmat_{k} and move columns of P^{k}_{k-1} and coordinates of primal part accordingly */</font>
<a name="line197">197: </a>      <a href="../../../../../manualpages/Mat/Mat.html">Mat</a> adj;

<a name="line199">199: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_events[GAMG_PTAP], 0, 0, 0, 0));
<a name="line200">200: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_matmat_events[pc_gamg-&gt;current_level][1], 0, 0, 0, 0));
<a name="line201">201: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatPtAP.html">MatPtAP</a>(Amat_fine, Pold, <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_INITIAL_MATRIX</a>, 2.0, &amp;Cmat));
<a name="line202">202: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_matmat_events[pc_gamg-&gt;current_level][1], 0, 0, 0, 0));
<a name="line203">203: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_events[GAMG_PTAP], 0, 0, 0, 0));
<a name="line204">204: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_events[GAMG_REPART], 0, 0, 0, 0));
<a name="line205">205: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: Repartition: size (active): %d --&gt; %d, %"</font> PetscInt_FMT <font color="#666666">" local equations, using %s process layout\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, *a_nactive_proc, new_size, ncrs_eq, (pc_gamg-&gt;layout_type == <a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMG_LAYOUT_COMPACT</a>) ? <font color="#666666">"compact"</font> : <font color="#666666">"spread"</font>));
<a name="line206">206: </a>      <font color="#B22222">/* get 'adj' */</font>
<a name="line207">207: </a>      <font color="#4169E1">if</font> (cr_bs == 1) {
<a name="line208">208: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatConvert.html">MatConvert</a>(Cmat, <a href="../../../../../manualpages/Mat/MATMPIADJ.html">MATMPIADJ</a>, <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_INITIAL_MATRIX</a>, &amp;adj));
<a name="line209">209: </a>      } <font color="#4169E1">else</font> {
<a name="line210">210: </a>        <font color="#B22222">/* make a scalar matrix to partition (no Stokes here) */</font>
<a name="line211">211: </a>        <a href="../../../../../manualpages/Mat/Mat.html">Mat</a>                tMat;
<a name="line212">212: </a>        <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>           Istart_crs, Iend_crs, ncols, jj, Ii;
<a name="line213">213: </a>        const <a href="../../../../../manualpages/Sys/PetscScalar.html">PetscScalar</a> *vals;
<a name="line214">214: </a>        const <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>    *idx;
<a name="line215">215: </a>        <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>          *d_nnz, *o_nnz, M, N, maxnnz = 0, *j_buf = NULL;
<a name="line216">216: </a>        <a href="../../../../../manualpages/Sys/PetscScalar.html">PetscScalar</a>       *v_buff = NULL;
<a name="line217">217: </a>        static <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>    llev   = 0; <font color="#B22222">/* ugly but just used for debugging */</font>
<a name="line218">218: </a>        <a href="../../../../../manualpages/Mat/MatType.html">MatType</a>            mtype;

<a name="line220">220: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscMalloc2.html">PetscMalloc2</a>(ncrs, &amp;d_nnz, ncrs, &amp;o_nnz));
<a name="line221">221: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetOwnershipRange.html">MatGetOwnershipRange</a>(Cmat, &amp;Istart_crs, &amp;Iend_crs));
<a name="line222">222: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetSize.html">MatGetSize</a>(Cmat, &amp;M, &amp;N));
<a name="line223">223: </a>        <font color="#4169E1">for</font> (Ii = Istart_crs, jj = 0; Ii &lt; Iend_crs; Ii += cr_bs, jj++) {
<a name="line224">224: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetRow.html">MatGetRow</a>(Cmat, Ii, &amp;ncols, NULL, NULL));
<a name="line225">225: </a>          d_nnz[jj] = ncols / cr_bs;
<a name="line226">226: </a>          o_nnz[jj] = ncols / cr_bs;
<a name="line227">227: </a>          <font color="#4169E1">if</font> (ncols &gt; maxnnz) maxnnz = ncols;
<a name="line228">228: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatRestoreRow.html">MatRestoreRow</a>(Cmat, Ii, &amp;ncols, NULL, NULL));
<a name="line229">229: </a>          <font color="#4169E1">if</font> (d_nnz[jj] &gt; ncrs) d_nnz[jj] = ncrs;
<a name="line230">230: </a>          <font color="#4169E1">if</font> (o_nnz[jj] &gt; (M / cr_bs - ncrs)) o_nnz[jj] = M / cr_bs - ncrs;
<a name="line231">231: </a>        }

<a name="line233">233: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetType.html">MatGetType</a>(Amat_fine, &amp;mtype));
<a name="line234">234: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatCreate.html">MatCreate</a>(comm, &amp;tMat));
<a name="line235">235: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetSizes.html">MatSetSizes</a>(tMat, ncrs, ncrs, <a href="../../../../../manualpages/Sys/PETSC_DETERMINE.html">PETSC_DETERMINE</a>, <a href="../../../../../manualpages/Sys/PETSC_DETERMINE.html">PETSC_DETERMINE</a>));
<a name="line236">236: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetType.html">MatSetType</a>(tMat, mtype));
<a name="line237">237: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSeqAIJSetPreallocation.html">MatSeqAIJSetPreallocation</a>(tMat, 0, d_nnz));
<a name="line238">238: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatMPIAIJSetPreallocation.html">MatMPIAIJSetPreallocation</a>(tMat, 0, d_nnz, 0, o_nnz));
<a name="line239">239: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree2.html">PetscFree2</a>(d_nnz, o_nnz));
<a name="line240">240: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscMalloc2.html">PetscMalloc2</a>(maxnnz, &amp;j_buf, maxnnz, &amp;v_buff));
<a name="line241">241: </a>        <font color="#4169E1">for</font> (ii = 0; ii &lt; maxnnz; ii++) v_buff[ii] = 1.;

<a name="line243">243: </a>        <font color="#4169E1">for</font> (ii = Istart_crs; ii &lt; Iend_crs; ii++) {
<a name="line244">244: </a>          <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> dest_row = ii / cr_bs;
<a name="line245">245: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetRow.html">MatGetRow</a>(Cmat, ii, &amp;ncols, &amp;idx, &amp;vals));
<a name="line246">246: </a>          <font color="#4169E1">for</font> (jj = 0; jj &lt; ncols; jj++) j_buf[jj] = idx[jj] / cr_bs;
<a name="line247">247: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetValues.html">MatSetValues</a>(tMat, 1, &amp;dest_row, ncols, j_buf, v_buff, <a href="../../../../../manualpages/Sys/ADD_VALUES.html">ADD_VALUES</a>));
<a name="line248">248: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatRestoreRow.html">MatRestoreRow</a>(Cmat, ii, &amp;ncols, &amp;idx, &amp;vals));
<a name="line249">249: </a>        }
<a name="line250">250: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatAssemblyBegin.html">MatAssemblyBegin</a>(tMat, <a href="../../../../../manualpages/Mat/MatAssemblyType.html">MAT_FINAL_ASSEMBLY</a>));
<a name="line251">251: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatAssemblyEnd.html">MatAssemblyEnd</a>(tMat, <a href="../../../../../manualpages/Mat/MatAssemblyType.html">MAT_FINAL_ASSEMBLY</a>));
<a name="line252">252: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree2.html">PetscFree2</a>(j_buf, v_buff));

<a name="line254">254: </a>        <font color="#4169E1">if</font> (llev++ == -1) {
<a name="line255">255: </a>          <a href="../../../../../manualpages/Viewer/PetscViewer.html">PetscViewer</a> viewer;
<a name="line256">256: </a>          char        fname[32];
<a name="line257">257: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscSNPrintf.html">PetscSNPrintf</a>(fname, <font color="#4169E1">sizeof</font>(fname), <font color="#666666">"part_mat_%"</font> PetscInt_FMT <font color="#666666">".mat"</font>, llev));
<a name="line258">258: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerBinaryOpen.html">PetscViewerBinaryOpen</a>(comm, fname, <a href="../../../../../manualpages/Sys/PetscFileMode.html">FILE_MODE_WRITE</a>, &amp;viewer));
<a name="line259">259: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatView.html">MatView</a>(tMat, viewer));
<a name="line260">260: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerDestroy.html">PetscViewerDestroy</a>(&amp;viewer));
<a name="line261">261: </a>        }
<a name="line262">262: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatConvert.html">MatConvert</a>(tMat, <a href="../../../../../manualpages/Mat/MATMPIADJ.html">MATMPIADJ</a>, <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_INITIAL_MATRIX</a>, &amp;adj));
<a name="line263">263: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatDestroy.html">MatDestroy</a>(&amp;tMat));
<a name="line264">264: </a>      } <font color="#B22222">/* create 'adj' */</font>

<a name="line266">266: </a>      { <font color="#B22222">/* partition: get newproc_idx */</font>
<a name="line267">267: </a>        char            prefix[256];
<a name="line268">268: </a>        const char     *pcpre;
<a name="line269">269: </a>        const <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> *is_idx;
<a name="line270">270: </a>        <a href="../../../../../manualpages/Mat/MatPartitioning.html">MatPartitioning</a> mpart;
<a name="line271">271: </a>        <a href="../../../../../manualpages/IS/IS.html">IS</a>              proc_is;

<a name="line273">273: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatPartitioningCreate.html">MatPartitioningCreate</a>(comm, &amp;mpart));
<a name="line274">274: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatPartitioningSetAdjacency.html">MatPartitioningSetAdjacency</a>(mpart, adj));
<a name="line275">275: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCGetOptionsPrefix.html">PCGetOptionsPrefix</a>(pc, &amp;pcpre));
<a name="line276">276: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscSNPrintf.html">PetscSNPrintf</a>(prefix, <font color="#4169E1">sizeof</font>(prefix), <font color="#666666">"%spc_gamg_"</font>, pcpre ? pcpre : <font color="#666666">""</font>));
<a name="line277">277: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectSetOptionsPrefix.html">PetscObjectSetOptionsPrefix</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)mpart, prefix));
<a name="line278">278: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatPartitioningSetFromOptions.html">MatPartitioningSetFromOptions</a>(mpart));
<a name="line279">279: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatPartitioningSetNParts.html">MatPartitioningSetNParts</a>(mpart, new_size));
<a name="line280">280: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatPartitioningApply.html">MatPartitioningApply</a>(mpart, &amp;proc_is));
<a name="line281">281: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatPartitioningDestroy.html">MatPartitioningDestroy</a>(&amp;mpart));

<a name="line283">283: </a>        <font color="#B22222">/* collect <a href="../../../../../manualpages/IS/IS.html">IS</a> info */</font>
<a name="line284">284: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscMalloc1.html">PetscMalloc1</a>(ncrs_eq, &amp;newproc_idx));
<a name="line285">285: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISGetIndices.html">ISGetIndices</a>(proc_is, &amp;is_idx));
<a name="line286">286: </a>        <font color="#4169E1">for</font> (kk = jj = 0; kk &lt; nloc_old; kk++) {
<a name="line287">287: </a>          <font color="#4169E1">for</font> (ii = 0; ii &lt; cr_bs; ii++, jj++) { newproc_idx[jj] = is_idx[kk] * expand_factor; <font color="#B22222">/* distribution */</font> }
<a name="line288">288: </a>        }
<a name="line289">289: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISRestoreIndices.html">ISRestoreIndices</a>(proc_is, &amp;is_idx));
<a name="line290">290: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&amp;proc_is));
<a name="line291">291: </a>      }
<a name="line292">292: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatDestroy.html">MatDestroy</a>(&amp;adj));

<a name="line294">294: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISCreateGeneral.html">ISCreateGeneral</a>(comm, ncrs_eq, newproc_idx, <a href="../../../../../manualpages/Sys/PetscCopyMode.html">PETSC_OWN_POINTER</a>, &amp;is_eq_newproc));
<a name="line295">295: </a>      <font color="#B22222">/*</font>
<a name="line296">296: </a><font color="#B22222">        Create an index set from the is_eq_newproc index set to indicate the mapping TO</font>
<a name="line297">297: </a><font color="#B22222">      */</font>
<a name="line298">298: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISPartitioningToNumbering.html">ISPartitioningToNumbering</a>(is_eq_newproc, &amp;is_eq_num));
<a name="line299">299: </a>      <font color="#B22222">/*</font>
<a name="line300">300: </a><font color="#B22222">        Determine how many equations/vertices are assigned to each processor</font>
<a name="line301">301: </a><font color="#B22222">      */</font>
<a name="line302">302: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscMalloc1.html">PetscMalloc1</a>(size, &amp;counts));
<a name="line303">303: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISPartitioningCount.html">ISPartitioningCount</a>(is_eq_newproc, size, counts));
<a name="line304">304: </a>      ncrs_eq_new = counts[rank];
<a name="line305">305: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&amp;is_eq_newproc));
<a name="line306">306: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(counts));
<a name="line307">307: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_events[GAMG_REPART], 0, 0, 0, 0));
<a name="line308">308: </a>    } <font color="#4169E1">else</font> { <font color="#B22222">/* simple aggregation of parts -- 'is_eq_newproc' */</font>
<a name="line309">309: </a>      const <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> *ranges;
<a name="line310">310: </a>      <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>        newstart = 0;
<a name="line311">311: </a>      <a href="../../../../../manualpages/IS/PetscLayout.html">PetscLayout</a>     ilay;

<a name="line313">313: </a>      <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(new_size != nactive, <a href="../../../../../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_PLIB</a>, <font color="#666666">"new_size==nactive. Should not happen"</font>);
<a name="line314">314: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: Number of equations (loc) %"</font> PetscInt_FMT <font color="#666666">" with simple aggregation\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, ncrs_eq));
<a name="line315">315: </a>      <a href="../../../../../manualpages/Sys/PetscCallMPI.html">PetscCallMPI</a>(<a href="http://www.mpich.org/static/docs/latest/www3/MPI_Exscan.html#MPI_Exscan">MPI_Exscan</a>(&amp;ncrs_eq, &amp;newstart, 1, <a href="../../../../../manualpages/Sys/MPIU_INT.html">MPIU_INT</a>, MPI_SUM, comm));
<a name="line316">316: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISCreateStride.html">ISCreateStride</a>(comm, ncrs_eq, newstart, 1, &amp;is_eq_num));
<a name="line317">317: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISSetPermutation.html">ISSetPermutation</a>(is_eq_num));
<a name="line318">318: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISGetLayout.html">ISGetLayout</a>(is_eq_num, &amp;ilay));
<a name="line319">319: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/PetscLayoutGetRanges.html">PetscLayoutGetRanges</a>(ilay, &amp;ranges));
<a name="line320">320: </a>      ncrs_eq_new = 0;
<a name="line321">321: </a>      <font color="#4169E1">for</font> (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> r = 0; r &lt; size; r++)
<a name="line322">322: </a>        <font color="#4169E1">if</font> (rank == (r / rfactor) * expand_factor) ncrs_eq_new += ranges[r + 1] - ranges[r];
<a name="line323">323: </a>      <font color="#B22222">//targetPE = (rank / rfactor) * expand_factor;</font>
<a name="line324">324: </a>      <font color="#B22222">//<a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISCreateStride.html">ISCreateStride</a>(comm, ncrs_eq, targetPE, 0, &is_eq_newproc));</font>
<a name="line325">325: </a>      <font color="#B22222">//<a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISPartitioningToNumbering.html">ISPartitioningToNumbering</a>(is_eq_newproc, &is_eq_num));</font>
<a name="line326">326: </a>      <font color="#B22222">//<a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscMalloc1.html">PetscMalloc1</a>(size, &counts));</font>
<a name="line327">327: </a>      <font color="#B22222">//<a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISPartitioningCount.html">ISPartitioningCount</a>(is_eq_newproc, size, counts));</font>
<a name="line328">328: </a>      <font color="#B22222">//ncrs_eq_new = counts[rank];</font>
<a name="line329">329: </a>      <font color="#B22222">//<a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&is_eq_newproc));</font>
<a name="line330">330: </a>      <font color="#B22222">//<a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(counts));</font>
<a name="line331">331: </a>    } <font color="#B22222">/* end simple 'is_eq_newproc' */</font>

<a name="line333">333: </a>    ncrs_new = ncrs_eq_new / cr_bs;

<a name="line335">335: </a>    <font color="#B22222">/* data movement scope -- this could be moved to subclasses so that we don't try to cram all auxiliary data into some complex abstracted thing */</font>
<a name="line336">336: </a>    {
<a name="line337">337: </a>      <a href="../../../../../manualpages/Vec/Vec.html">Vec</a>             src_crd, dest_crd;
<a name="line338">338: </a>      const <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> *idx, ndata_rows = pc_gamg-&gt;data_cell_rows, ndata_cols = pc_gamg-&gt;data_cell_cols, node_data_sz = ndata_rows * ndata_cols;
<a name="line339">339: </a>      <a href="../../../../../manualpages/PetscSF/VecScatter.html">VecScatter</a>      vecscat;
<a name="line340">340: </a>      <a href="../../../../../manualpages/Sys/PetscScalar.html">PetscScalar</a>    *array;
<a name="line341">341: </a>      <a href="../../../../../manualpages/IS/IS.html">IS</a>              isscat;
<a name="line342">342: </a>      <font color="#B22222">/* move data (for primal equations only) */</font>
<a name="line343">343: </a>      <font color="#B22222">/* Create a vector to contain the newly ordered element information */</font>
<a name="line344">344: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecCreate.html">VecCreate</a>(comm, &amp;dest_crd));
<a name="line345">345: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecSetSizes.html">VecSetSizes</a>(dest_crd, node_data_sz * ncrs_new, <a href="../../../../../manualpages/Sys/PETSC_DECIDE.html">PETSC_DECIDE</a>));
<a name="line346">346: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecSetType.html">VecSetType</a>(dest_crd, <a href="../../../../../manualpages/Vec/VECSTANDARD.html">VECSTANDARD</a>)); <font color="#B22222">/* this is needed! */</font>
<a name="line347">347: </a>      <font color="#B22222">/*</font>
<a name="line348">348: </a><font color="#B22222">        There are 'ndata_rows*ndata_cols' data items per node, (one can think of the vectors of having</font>
<a name="line349">349: </a><font color="#B22222">        a block size of ...).  Note, ISs are expanded into equation space by 'cr_bs'.</font>
<a name="line350">350: </a><font color="#B22222">      */</font>
<a name="line351">351: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscMalloc1.html">PetscMalloc1</a>(ncrs * node_data_sz, &amp;tidx));
<a name="line352">352: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISGetIndices.html">ISGetIndices</a>(is_eq_num, &amp;idx));
<a name="line353">353: </a>      <font color="#4169E1">for</font> (ii = 0, jj = 0; ii &lt; ncrs; ii++) {
<a name="line354">354: </a>        <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> id = idx[ii * cr_bs] / cr_bs; <font color="#B22222">/* get node back */</font>
<a name="line355">355: </a>        <font color="#4169E1">for</font> (kk = 0; kk &lt; node_data_sz; kk++, jj++) tidx[jj] = id * node_data_sz + kk;
<a name="line356">356: </a>      }
<a name="line357">357: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISRestoreIndices.html">ISRestoreIndices</a>(is_eq_num, &amp;idx));
<a name="line358">358: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISCreateGeneral.html">ISCreateGeneral</a>(comm, node_data_sz * ncrs, tidx, <a href="../../../../../manualpages/Sys/PetscCopyMode.html">PETSC_COPY_VALUES</a>, &amp;isscat));
<a name="line359">359: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(tidx));
<a name="line360">360: </a>      <font color="#B22222">/*</font>
<a name="line361">361: </a><font color="#B22222">        Create a vector to contain the original vertex information for each element</font>
<a name="line362">362: </a><font color="#B22222">      */</font>
<a name="line363">363: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecCreateSeq.html">VecCreateSeq</a>(<a href="../../../../../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, node_data_sz * ncrs, &amp;src_crd));
<a name="line364">364: </a>      <font color="#4169E1">for</font> (jj = 0; jj &lt; ndata_cols; jj++) {
<a name="line365">365: </a>        const <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> stride0 = ncrs * pc_gamg-&gt;data_cell_rows;
<a name="line366">366: </a>        <font color="#4169E1">for</font> (ii = 0; ii &lt; ncrs; ii++) {
<a name="line367">367: </a>          <font color="#4169E1">for</font> (kk = 0; kk &lt; ndata_rows; kk++) {
<a name="line368">368: </a>            <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>    ix = ii * ndata_rows + kk + jj * stride0, jx = ii * node_data_sz + kk * ndata_cols + jj;
<a name="line369">369: </a>            <a href="../../../../../manualpages/Sys/PetscScalar.html">PetscScalar</a> tt = pc_gamg-&gt;data[ix];
<a name="line370">370: </a>            <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecSetValues.html">VecSetValues</a>(src_crd, 1, &amp;jx, &amp;tt, <a href="../../../../../manualpages/Sys/INSERT_VALUES.html">INSERT_VALUES</a>));
<a name="line371">371: </a>          }
<a name="line372">372: </a>        }
<a name="line373">373: </a>      }
<a name="line374">374: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecAssemblyBegin.html">VecAssemblyBegin</a>(src_crd));
<a name="line375">375: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecAssemblyEnd.html">VecAssemblyEnd</a>(src_crd));
<a name="line376">376: </a>      <font color="#B22222">/*</font>
<a name="line377">377: </a><font color="#B22222">        Scatter the element vertex information (still in the original vertex ordering)</font>
<a name="line378">378: </a><font color="#B22222">        to the correct processor</font>
<a name="line379">379: </a><font color="#B22222">      */</font>
<a name="line380">380: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecScatterCreate.html">VecScatterCreate</a>(src_crd, NULL, dest_crd, isscat, &amp;vecscat));
<a name="line381">381: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&amp;isscat));
<a name="line382">382: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecScatterBegin.html">VecScatterBegin</a>(vecscat, src_crd, dest_crd, <a href="../../../../../manualpages/Sys/INSERT_VALUES.html">INSERT_VALUES</a>, <a href="../../../../../manualpages/Vec/SCATTER_FORWARD.html">SCATTER_FORWARD</a>));
<a name="line383">383: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecScatterEnd.html">VecScatterEnd</a>(vecscat, src_crd, dest_crd, <a href="../../../../../manualpages/Sys/INSERT_VALUES.html">INSERT_VALUES</a>, <a href="../../../../../manualpages/Vec/SCATTER_FORWARD.html">SCATTER_FORWARD</a>));
<a name="line384">384: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecScatterDestroy.html">VecScatterDestroy</a>(&amp;vecscat));
<a name="line385">385: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecDestroy.html">VecDestroy</a>(&amp;src_crd));
<a name="line386">386: </a>      <font color="#B22222">/*</font>
<a name="line387">387: </a><font color="#B22222">        Put the element vertex data into a new allocation of the gdata-&gt;ele</font>
<a name="line388">388: </a><font color="#B22222">      */</font>
<a name="line389">389: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(pc_gamg-&gt;data));
<a name="line390">390: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscMalloc1.html">PetscMalloc1</a>(node_data_sz * ncrs_new, &amp;pc_gamg-&gt;data));

<a name="line392">392: </a>      pc_gamg-&gt;data_sz = node_data_sz * ncrs_new;
<a name="line393">393: </a>      strideNew        = ncrs_new * ndata_rows;

<a name="line395">395: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecGetArray.html">VecGetArray</a>(dest_crd, &amp;array));
<a name="line396">396: </a>      <font color="#4169E1">for</font> (jj = 0; jj &lt; ndata_cols; jj++) {
<a name="line397">397: </a>        <font color="#4169E1">for</font> (ii = 0; ii &lt; ncrs_new; ii++) {
<a name="line398">398: </a>          <font color="#4169E1">for</font> (kk = 0; kk &lt; ndata_rows; kk++) {
<a name="line399">399: </a>            <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> ix = ii * ndata_rows + kk + jj * strideNew, jx = ii * node_data_sz + kk * ndata_cols + jj;
<a name="line400">400: </a>            pc_gamg-&gt;data[ix] = <a href="../../../../../manualpages/Sys/PetscRealPart.html">PetscRealPart</a>(array[jx]);
<a name="line401">401: </a>          }
<a name="line402">402: </a>        }
<a name="line403">403: </a>      }
<a name="line404">404: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecRestoreArray.html">VecRestoreArray</a>(dest_crd, &amp;array));
<a name="line405">405: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecDestroy.html">VecDestroy</a>(&amp;dest_crd));
<a name="line406">406: </a>    }
<a name="line407">407: </a>    <font color="#B22222">/* move A and P (columns) with new layout */</font>
<a name="line408">408: </a>    <font color="#B22222">/*</font>
<a name="line409">409: </a><font color="#B22222">      Invert for <a href="../../../../../manualpages/Mat/MatCreateSubMatrix.html">MatCreateSubMatrix</a></font>
<a name="line410">410: </a><font color="#B22222">    */</font>
<a name="line411">411: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISInvertPermutation.html">ISInvertPermutation</a>(is_eq_num, ncrs_eq_new, &amp;new_eq_indices));
<a name="line412">412: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISSort.html">ISSort</a>(new_eq_indices));
<a name="line413">413: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISSetBlockSize.html">ISSetBlockSize</a>(new_eq_indices, cr_bs));
<a name="line414">414: </a>    <font color="#4169E1">if</font> (Pcolumnperm) {
<a name="line415">415: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectReference.html">PetscObjectReference</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)new_eq_indices));
<a name="line416">416: </a>      *Pcolumnperm = new_eq_indices;
<a name="line417">417: </a>    }
<a name="line418">418: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&amp;is_eq_num));

<a name="line420">420: </a>    <font color="#B22222">/* 'a_Amat_crs' output */</font>
<a name="line421">421: </a>    <font color="#4169E1">if</font> (Cmat) { <font color="#B22222">/* repartitioning from Cmat adjacency case */</font>
<a name="line422">422: </a>      <a href="../../../../../manualpages/Mat/Mat.html">Mat</a>       mat;
<a name="line423">423: </a>      <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> isset, isspd, isher;
<a name="line424">424: </a><font color="#A020F0">#if !defined(PETSC_USE_COMPLEX)</font>
<a name="line425">425: </a>      <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> issym;
<a name="line426">426: </a><font color="#A020F0">#endif</font>

<a name="line428">428: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatCreateSubMatrix.html">MatCreateSubMatrix</a>(Cmat, new_eq_indices, new_eq_indices, <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_INITIAL_MATRIX</a>, &amp;mat));
<a name="line429">429: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatIsSPDKnown.html">MatIsSPDKnown</a>(Cmat, &amp;isset, &amp;isspd)); <font color="#B22222">// like <a href="../../../../../manualpages/Mat/MatPropagateSymmetryOptions.html">MatPropagateSymmetryOptions</a>, but should set <a href="../../../../../manualpages/Mat/MatOption.html">MAT_STRUCTURALLY_SYMMETRIC</a> ?</font>
<a name="line430">430: </a>      <font color="#4169E1">if</font> (isset) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetOption.html">MatSetOption</a>(mat, <a href="../../../../../manualpages/Mat/MatOption.html">MAT_SPD</a>, isspd));
<a name="line431">431: </a>      <font color="#4169E1">else</font> {
<a name="line432">432: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatIsHermitianKnown.html">MatIsHermitianKnown</a>(Cmat, &amp;isset, &amp;isher));
<a name="line433">433: </a>        <font color="#4169E1">if</font> (isset) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetOption.html">MatSetOption</a>(mat, <a href="../../../../../manualpages/Mat/MatOption.html">MAT_HERMITIAN</a>, isher));
<a name="line434">434: </a>        <font color="#4169E1">else</font> {
<a name="line435">435: </a><font color="#A020F0">#if !defined(PETSC_USE_COMPLEX)</font>
<a name="line436">436: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatIsSymmetricKnown.html">MatIsSymmetricKnown</a>(Cmat, &amp;isset, &amp;issym));
<a name="line437">437: </a>          <font color="#4169E1">if</font> (isset) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetOption.html">MatSetOption</a>(mat, <a href="../../../../../manualpages/Mat/MatOption.html">MAT_SYMMETRIC</a>, issym));
<a name="line438">438: </a><font color="#A020F0">#endif</font>
<a name="line439">439: </a>        }
<a name="line440">440: </a>      }
<a name="line441">441: </a>      *a_Amat_crs = mat;
<a name="line442">442: </a>    }

<a name="line444">444: </a>    <font color="#B22222">/* prolongator */</font>
<a name="line445">445: </a>    {
<a name="line446">446: </a>      <a href="../../../../../manualpages/IS/IS.html">IS</a>       findices;
<a name="line447">447: </a>      <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> Istart, Iend;
<a name="line448">448: </a>      <a href="../../../../../manualpages/Mat/Mat.html">Mat</a>      Pnew;

<a name="line450">450: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetOwnershipRange.html">MatGetOwnershipRange</a>(Pold, &amp;Istart, &amp;Iend));
<a name="line451">451: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISCreateStride.html">ISCreateStride</a>(comm, Iend - Istart, Istart, 1, &amp;findices));
<a name="line452">452: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISSetBlockSize.html">ISSetBlockSize</a>(findices, f_bs));
<a name="line453">453: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatCreateSubMatrix.html">MatCreateSubMatrix</a>(Pold, findices, new_eq_indices, <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_INITIAL_MATRIX</a>, &amp;Pnew));
<a name="line454">454: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&amp;findices));
<a name="line455">455: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetOption.html">MatSetOption</a>(Pnew, <a href="../../../../../manualpages/Mat/MatOption.html">MAT_FORM_EXPLICIT_TRANSPOSE</a>, <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>));

<a name="line457">457: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatDestroy.html">MatDestroy</a>(a_P_inout));

<a name="line459">459: </a>      <font color="#B22222">/* output - repartitioned */</font>
<a name="line460">460: </a>      *a_P_inout = Pnew;
<a name="line461">461: </a>    }

<a name="line463">463: </a>    <font color="#4169E1">if</font> (!Cmat) { <font color="#B22222">/* simple repartitioning case */</font>
<a name="line464">464: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_events[GAMG_PTAP], 0, 0, 0, 0));
<a name="line465">465: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_matmat_events[pc_gamg-&gt;current_level][1], 0, 0, 0, 0));
<a name="line466">466: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatPtAP.html">MatPtAP</a>(Amat_fine, *a_P_inout, <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_INITIAL_MATRIX</a>, 2.0, a_Amat_crs));
<a name="line467">467: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_matmat_events[pc_gamg-&gt;current_level][1], 0, 0, 0, 0));
<a name="line468">468: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_events[GAMG_PTAP], 0, 0, 0, 0));
<a name="line469">469: </a>    }
<a name="line470">470: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatDestroy.html">MatDestroy</a>(&amp;Cmat));
<a name="line471">471: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&amp;new_eq_indices));

<a name="line473">473: </a>    *a_nactive_proc = new_size; <font color="#B22222">/* output */</font>

<a name="line475">475: </a>    <font color="#B22222">/* pinning on reduced grids, not a bad heuristic and optimization gets folded into process reduction optimization */</font>
<a name="line476">476: </a>    <font color="#4169E1">if</font> (pc_gamg-&gt;cpu_pin_coarse_grids) {
<a name="line477">477: </a><font color="#A020F0">#if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA)</font>
<a name="line478">478: </a>      static <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> llev = 2;
<a name="line479">479: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: Pinning level %"</font> PetscInt_FMT <font color="#666666">" to the CPU\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, llev++));
<a name="line480">480: </a><font color="#A020F0">#endif</font>
<a name="line481">481: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatBindToCPU.html">MatBindToCPU</a>(*a_Amat_crs, <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>));
<a name="line482">482: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatBindToCPU.html">MatBindToCPU</a>(*a_P_inout, <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>));
<a name="line483">483: </a>      <font color="#4169E1">if</font> (1) { <font color="#B22222">/* HACK: move this to MatBindCPU_MPIAIJXXX; lvec is created, need to pin it, this is done in MatSetUpMultiply_MPIAIJ. Hack */</font>
<a name="line484">484: </a>        <a href="../../../../../manualpages/Mat/Mat.html">Mat</a>         A = *a_Amat_crs, P = *a_P_inout;
<a name="line485">485: </a>        <a href="../../../../../manualpages/Sys/PetscMPIInt.html">PetscMPIInt</a> size;
<a name="line486">486: </a>        <a href="../../../../../manualpages/Sys/PetscCallMPI.html">PetscCallMPI</a>(<a href="http://www.mpich.org/static/docs/latest/www3/MPI_Comm_size.html#MPI_Comm_size">MPI_Comm_size</a>(<a href="../../../../../manualpages/Sys/PetscObjectComm.html">PetscObjectComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)A), &amp;size));
<a name="line487">487: </a>        <font color="#4169E1">if</font> (size &gt; 1) {
<a name="line488">488: </a>          Mat_MPIAIJ *a = (Mat_MPIAIJ *)A-&gt;data, *p = (Mat_MPIAIJ *)P-&gt;data;
<a name="line489">489: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecBindToCPU.html">VecBindToCPU</a>(a-&gt;lvec, <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>));
<a name="line490">490: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Vec/VecBindToCPU.html">VecBindToCPU</a>(p-&gt;lvec, <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>));
<a name="line491">491: </a>        }
<a name="line492">492: </a>      }
<a name="line493">493: </a>    }
<a name="line494">494: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_events[GAMG_REDUCE], 0, 0, 0, 0));
<a name="line495">495: </a>  } <font color="#B22222">// processor reduce</font>
<a name="line496">496: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line497">497: </a>}

<a name="line499">499: </a><font color="#B22222">// used in GEO</font>
<a name="line500">500: </a><strong><font color="#4169E1"><a name="PCGAMGSquareGraph_GAMG"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSquareGraph_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> a_pc, <a href="../../../../../manualpages/Mat/Mat.html">Mat</a> Gmat1, <a href="../../../../../manualpages/Mat/Mat.html">Mat</a> *Gmat2)</font></strong>
<a name="line501">501: </a>{
<a name="line502">502: </a>  const char *prefix;
<a name="line503">503: </a>  char        addp[32];
<a name="line504">504: </a>  PC_MG      *mg      = (PC_MG *)a_pc-&gt;data;
<a name="line505">505: </a>  PC_GAMG    *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line507">507: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line508">508: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCGetOptionsPrefix.html">PCGetOptionsPrefix</a>(a_pc, &amp;prefix));
<a name="line509">509: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(a_pc, <font color="#666666">"%s: Square Graph on level %"</font> PetscInt_FMT <font color="#666666">"\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)a_pc)-&gt;prefix, pc_gamg-&gt;current_level + 1));
<a name="line510">510: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatProductCreate.html">MatProductCreate</a>(Gmat1, Gmat1, NULL, Gmat2));
<a name="line511">511: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetOptionsPrefix.html">MatSetOptionsPrefix</a>(*Gmat2, prefix));
<a name="line512">512: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscSNPrintf.html">PetscSNPrintf</a>(addp, <font color="#4169E1">sizeof</font>(addp), <font color="#666666">"pc_gamg_square_%"</font> PetscInt_FMT <font color="#666666">"_"</font>, pc_gamg-&gt;current_level));
<a name="line513">513: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatAppendOptionsPrefix.html">MatAppendOptionsPrefix</a>(*Gmat2, addp));
<a name="line514">514: </a>  <font color="#4169E1">if</font> ((*Gmat2)-&gt;structurally_symmetric == <a href="../../../../../manualpages/Sys/PetscBool3.html">PETSC_BOOL3_TRUE</a>) {
<a name="line515">515: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatProductSetType.html">MatProductSetType</a>(*Gmat2, <a href="../../../../../manualpages/Mat/MatProductType.html">MATPRODUCT_AB</a>));
<a name="line516">516: </a>  } <font color="#4169E1">else</font> {
<a name="line517">517: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetOption.html">MatSetOption</a>(Gmat1, <a href="../../../../../manualpages/Mat/MatOption.html">MAT_FORM_EXPLICIT_TRANSPOSE</a>, <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>));
<a name="line518">518: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatProductSetType.html">MatProductSetType</a>(*Gmat2, <a href="../../../../../manualpages/Mat/MatProductType.html">MATPRODUCT_AtB</a>));
<a name="line519">519: </a>  }
<a name="line520">520: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatProductSetFromOptions.html">MatProductSetFromOptions</a>(*Gmat2));
<a name="line521">521: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_matmat_events[pc_gamg-&gt;current_level][0], 0, 0, 0, 0));
<a name="line522">522: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatProductSymbolic.html">MatProductSymbolic</a>(*Gmat2));
<a name="line523">523: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_matmat_events[pc_gamg-&gt;current_level][0], 0, 0, 0, 0));
<a name="line524">524: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatProductClear.html">MatProductClear</a>(*Gmat2));
<a name="line525">525: </a>  <font color="#B22222">/* we only need the sparsity, cheat and tell PETSc the matrix has been assembled */</font>
<a name="line526">526: </a>  (*Gmat2)-&gt;assembled = <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>;
<a name="line527">527: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line528">528: </a>}

<a name="line530">530: </a><font color="#B22222">/*</font>
<a name="line531">531: </a><font color="#B22222">   PCSetUp_GAMG - Prepares for the use of the GAMG preconditioner</font>
<a name="line532">532: </a><font color="#B22222">                    by setting data structures and options.</font>

<a name="line534">534: </a><font color="#B22222">   Input Parameter:</font>
<a name="line535">535: </a><font color="#B22222">.  pc - the preconditioner context</font>

<a name="line537">537: </a><font color="#B22222">*/</font>
<a name="line538">538: </a><strong><font color="#4169E1"><a name="PCSetUp_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCSetUp_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc)</font></strong>
<a name="line539">539: </a>{
<a name="line540">540: </a>  PC_MG      *mg      = (PC_MG *)pc-&gt;data;
<a name="line541">541: </a>  PC_GAMG    *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;
<a name="line542">542: </a>  <a href="../../../../../manualpages/Mat/Mat.html">Mat</a>         Pmat    = pc-&gt;pmat;
<a name="line543">543: </a>  <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>    fine_level, level, level1, bs, M, N, qq, lidx, nASMBlocksArr[PETSC_MG_MAXLEVELS], cr_bs;
<a name="line544">544: </a>  <a href="../../../../../manualpages/Sys/MPI_Comm.html">MPI_Comm</a>    comm;
<a name="line545">545: </a>  <a href="../../../../../manualpages/Sys/PetscMPIInt.html">PetscMPIInt</a> rank, size, nactivepe;
<a name="line546">546: </a>  <a href="../../../../../manualpages/Mat/Mat.html">Mat</a>         Aarr[PETSC_MG_MAXLEVELS], Parr[PETSC_MG_MAXLEVELS];
<a name="line547">547: </a>  <a href="../../../../../manualpages/IS/IS.html">IS</a>         *ASMLocalIDsArr[PETSC_MG_MAXLEVELS];
<a name="line548">548: </a>  <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a>   is_last = <a href="../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>;
<a name="line549">549: </a><font color="#A020F0">#if defined(PETSC_USE_INFO)</font>
<a name="line550">550: </a>  <a href="../../../../../manualpages/Sys/PetscLogDouble.html">PetscLogDouble</a> nnz0 = 0., nnztot = 0.;
<a name="line551">551: </a>  <a href="../../../../../manualpages/Mat/MatInfo.html">MatInfo</a>        info;
<a name="line552">552: </a><font color="#A020F0">#endif</font>

<a name="line554">554: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line555">555: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectGetComm.html">PetscObjectGetComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, &amp;comm));
<a name="line556">556: </a>  <a href="../../../../../manualpages/Sys/PetscCallMPI.html">PetscCallMPI</a>(<a href="http://www.mpich.org/static/docs/latest/www3/MPI_Comm_rank.html#MPI_Comm_rank">MPI_Comm_rank</a>(comm, &amp;rank));
<a name="line557">557: </a>  <a href="../../../../../manualpages/Sys/PetscCallMPI.html">PetscCallMPI</a>(<a href="http://www.mpich.org/static/docs/latest/www3/MPI_Comm_size.html#MPI_Comm_size">MPI_Comm_size</a>(comm, &amp;size));
<a name="line558">558: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_events[GAMG_SETUP], 0, 0, 0, 0));
<a name="line559">559: </a>  <font color="#4169E1">if</font> (pc-&gt;setupcalled) {
<a name="line560">560: </a>    <font color="#4169E1">if</font> (!pc_gamg-&gt;reuse_prol || pc-&gt;flag == <a href="../../../../../manualpages/Mat/MatStructure.html">DIFFERENT_NONZERO_PATTERN</a>) {
<a name="line561">561: </a>      <font color="#B22222">/* reset everything */</font>
<a name="line562">562: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCReset_MG(pc));
<a name="line563">563: </a>      pc-&gt;setupcalled = 0;
<a name="line564">564: </a>    } <font color="#4169E1">else</font> {
<a name="line565">565: </a>      PC_MG_Levels **mglevels = mg-&gt;levels;
<a name="line566">566: </a>      <font color="#B22222">/* just do Galerkin grids */</font>
<a name="line567">567: </a>      <a href="../../../../../manualpages/Mat/Mat.html">Mat</a> B, dA, dB;
<a name="line568">568: </a>      <font color="#4169E1">if</font> (pc_gamg-&gt;Nlevels &gt; 1) {
<a name="line569">569: </a>        <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> gl;
<a name="line570">570: </a>        <font color="#B22222">/* currently only handle case where mat and pmat are the same on coarser levels */</font>
<a name="line571">571: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPGetOperators.html">KSPGetOperators</a>(mglevels[pc_gamg-&gt;Nlevels - 1]-&gt;smoothd, &amp;dA, &amp;dB));
<a name="line572">572: </a>        <font color="#B22222">/* (re)set to get dirty flag */</font>
<a name="line573">573: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPSetOperators.html">KSPSetOperators</a>(mglevels[pc_gamg-&gt;Nlevels - 1]-&gt;smoothd, dA, dB));

<a name="line575">575: </a>        <font color="#4169E1">for</font> (level = pc_gamg-&gt;Nlevels - 2, gl = 0; level &gt;= 0; level--, gl++) {
<a name="line576">576: </a>          <a href="../../../../../manualpages/Mat/MatReuse.html">MatReuse</a> reuse = <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_INITIAL_MATRIX</a>;
<a name="line577">577: </a><font color="#A020F0">#if defined(GAMG_STAGES)</font>
<a name="line578">578: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogStagePush.html">PetscLogStagePush</a>(gamg_stages[gl]));
<a name="line579">579: </a><font color="#A020F0">#endif</font>
<a name="line580">580: </a>          <font color="#B22222">/* matrix nonzero structure can change from repartitioning or process reduction but don't know if we have process reduction here. Should fix */</font>
<a name="line581">581: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPGetOperators.html">KSPGetOperators</a>(mglevels[level]-&gt;smoothd, NULL, &amp;B));
<a name="line582">582: </a>          <font color="#4169E1">if</font> (B-&gt;product) {
<a name="line583">583: </a>            <font color="#4169E1">if</font> (B-&gt;product-&gt;A == dB &amp;&amp; B-&gt;product-&gt;B == mglevels[level + 1]-&gt;interpolate) reuse = <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_REUSE_MATRIX</a>;
<a name="line584">584: </a>          }
<a name="line585">585: </a>          <font color="#4169E1">if</font> (reuse == <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_INITIAL_MATRIX</a>) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatDestroy.html">MatDestroy</a>(&amp;mglevels[level]-&gt;A));
<a name="line586">586: </a>          <font color="#4169E1">if</font> (reuse == <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_REUSE_MATRIX</a>) {
<a name="line587">587: </a>            <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: RAP after initial setup, reuse matrix level %"</font> PetscInt_FMT <font color="#666666">"\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, level));
<a name="line588">588: </a>          } <font color="#4169E1">else</font> {
<a name="line589">589: </a>            <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: RAP after initial setup, with repartitioning (new matrix) level %"</font> PetscInt_FMT <font color="#666666">"\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, level));
<a name="line590">590: </a>          }
<a name="line591">591: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_matmat_events[gl][1], 0, 0, 0, 0));
<a name="line592">592: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatPtAP.html">MatPtAP</a>(dB, mglevels[level + 1]-&gt;interpolate, reuse, <a href="../../../../../manualpages/Sys/PETSC_DETERMINE.html">PETSC_DETERMINE</a>, &amp;B));
<a name="line593">593: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_matmat_events[gl][1], 0, 0, 0, 0));
<a name="line594">594: </a>          <font color="#4169E1">if</font> (reuse == <a href="../../../../../manualpages/Mat/MatReuse.html">MAT_INITIAL_MATRIX</a>) mglevels[level]-&gt;A = B;
<a name="line595">595: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPSetOperators.html">KSPSetOperators</a>(mglevels[level]-&gt;smoothd, B, B));
<a name="line596">596: </a>          <font color="#B22222">// check for redoing eigen estimates</font>
<a name="line597">597: </a>          <font color="#4169E1">if</font> (pc_gamg-&gt;recompute_esteig) {
<a name="line598">598: </a>            <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> ischeb;
<a name="line599">599: </a>            <a href="../../../../../manualpages/KSP/KSP.html">KSP</a>       smoother;
<a name="line600">600: </a>            <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCMGGetSmoother.html">PCMGGetSmoother</a>(pc, level + 1, &amp;smoother));
<a name="line601">601: </a>            <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectTypeCompare.html">PetscObjectTypeCompare</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)smoother, <a href="../../../../../manualpages/KSP/KSPCHEBYSHEV.html">KSPCHEBYSHEV</a>, &amp;ischeb));
<a name="line602">602: </a>            <font color="#4169E1">if</font> (ischeb) {
<a name="line603">603: </a>              KSP_Chebyshev *cheb = (KSP_Chebyshev *)smoother-&gt;data;
<a name="line604">604: </a>              cheb-&gt;emin_provided = 0;
<a name="line605">605: </a>              cheb-&gt;emax_provided = 0;
<a name="line606">606: </a>            }
<a name="line607">607: </a>            <font color="#B22222">/* we could call <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPChebyshevSetEigenvalues.html">KSPChebyshevSetEigenvalues</a>(smoother, 0, 0)); but the logic does not work properly */</font>
<a name="line608">608: </a>          }
<a name="line609">609: </a>          <font color="#B22222">// inc</font>
<a name="line610">610: </a>          dB = B;
<a name="line611">611: </a><font color="#A020F0">#if defined(GAMG_STAGES)</font>
<a name="line612">612: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogStagePop.html">PetscLogStagePop</a>());
<a name="line613">613: </a><font color="#A020F0">#endif</font>
<a name="line614">614: </a>        }
<a name="line615">615: </a>      }

<a name="line617">617: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCSetUp_MG(pc));
<a name="line618">618: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_events[GAMG_SETUP], 0, 0, 0, 0));
<a name="line619">619: </a>      <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line620">620: </a>    }
<a name="line621">621: </a>  }

<a name="line623">623: </a>  <font color="#4169E1">if</font> (!pc_gamg-&gt;data) {
<a name="line624">624: </a>    <font color="#4169E1">if</font> (pc_gamg-&gt;orig_data) {
<a name="line625">625: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetBlockSize.html">MatGetBlockSize</a>(Pmat, &amp;bs));
<a name="line626">626: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetLocalSize.html">MatGetLocalSize</a>(Pmat, &amp;qq, NULL));

<a name="line628">628: </a>      pc_gamg-&gt;data_sz        = (qq / bs) * pc_gamg-&gt;orig_data_cell_rows * pc_gamg-&gt;orig_data_cell_cols;
<a name="line629">629: </a>      pc_gamg-&gt;data_cell_rows = pc_gamg-&gt;orig_data_cell_rows;
<a name="line630">630: </a>      pc_gamg-&gt;data_cell_cols = pc_gamg-&gt;orig_data_cell_cols;

<a name="line632">632: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscMalloc1.html">PetscMalloc1</a>(pc_gamg-&gt;data_sz, &amp;pc_gamg-&gt;data));
<a name="line633">633: </a>      <font color="#4169E1">for</font> (qq = 0; qq &lt; pc_gamg-&gt;data_sz; qq++) pc_gamg-&gt;data[qq] = pc_gamg-&gt;orig_data[qq];
<a name="line634">634: </a>    } <font color="#4169E1">else</font> {
<a name="line635">635: </a>      <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(pc_gamg-&gt;ops-&gt;createdefaultdata, comm, <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_PLIB</a>, <font color="#666666">"'createdefaultdata' not set(?) need to support NULL data"</font>);
<a name="line636">636: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(pc_gamg-&gt;ops-&gt;createdefaultdata(pc, Pmat));
<a name="line637">637: </a>    }
<a name="line638">638: </a>  }

<a name="line640">640: </a>  <font color="#B22222">/* cache original data for reuse */</font>
<a name="line641">641: </a>  <font color="#4169E1">if</font> (!pc_gamg-&gt;orig_data &amp;&amp; (<a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a>)(!pc_gamg-&gt;reuse_prol)) {
<a name="line642">642: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscMalloc1.html">PetscMalloc1</a>(pc_gamg-&gt;data_sz, &amp;pc_gamg-&gt;orig_data));
<a name="line643">643: </a>    <font color="#4169E1">for</font> (qq = 0; qq &lt; pc_gamg-&gt;data_sz; qq++) pc_gamg-&gt;orig_data[qq] = pc_gamg-&gt;data[qq];
<a name="line644">644: </a>    pc_gamg-&gt;orig_data_cell_rows = pc_gamg-&gt;data_cell_rows;
<a name="line645">645: </a>    pc_gamg-&gt;orig_data_cell_cols = pc_gamg-&gt;data_cell_cols;
<a name="line646">646: </a>  }

<a name="line648">648: </a>  <font color="#B22222">/* get basic dims */</font>
<a name="line649">649: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetBlockSize.html">MatGetBlockSize</a>(Pmat, &amp;bs));
<a name="line650">650: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetSize.html">MatGetSize</a>(Pmat, &amp;M, NULL));

<a name="line652">652: </a><font color="#A020F0">#if defined(PETSC_USE_INFO)</font>
<a name="line653">653: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetInfo.html">MatGetInfo</a>(Pmat, <a href="../../../../../manualpages/Mat/MatInfoType.html">MAT_GLOBAL_SUM</a>, &amp;info)); <font color="#B22222">/* global reduction */</font>
<a name="line654">654: </a>  nnz0   = info.nz_used;
<a name="line655">655: </a>  nnztot = info.nz_used;
<a name="line656">656: </a><font color="#A020F0">#endif</font>
<a name="line657">657: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: level %d) N=%"</font> PetscInt_FMT <font color="#666666">", n data rows=%"</font> PetscInt_FMT <font color="#666666">", n data cols=%"</font> PetscInt_FMT <font color="#666666">", nnz/row (ave)=%"</font> PetscInt_FMT <font color="#666666">", block size %"</font> PetscInt_FMT <font color="#666666">", np=%d\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, 0, M, pc_gamg-&gt;data_cell_rows,
<a name="line658">658: </a>                      pc_gamg-&gt;data_cell_cols, (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>)(nnz0 / (<a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a>)M + 0.5), bs, size));

<a name="line660">660: </a>  <font color="#B22222">/* Get A_i and R_i */</font>
<a name="line661">661: </a>  <font color="#4169E1">for</font> (level = 0, Aarr[0] = Pmat, nactivepe = size; level &lt; (pc_gamg-&gt;Nlevels - 1) &amp;&amp; (level == 0 || M &gt; pc_gamg-&gt;coarse_eq_limit); level++) {
<a name="line662">662: </a>    pc_gamg-&gt;current_level = level;
<a name="line663">663: </a>    level1                 = level + 1;
<a name="line664">664: </a><font color="#A020F0">#if defined(GAMG_STAGES)</font>
<a name="line665">665: </a>    <font color="#4169E1">if</font> (!gamg_stages[level]) {
<a name="line666">666: </a>      char str[32];
<a name="line667">667: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscSNPrintf.html">PetscSNPrintf</a>(str, <a href="../../../../../manualpages/Sys/PETSC_STATIC_ARRAY_LENGTH.html">PETSC_STATIC_ARRAY_LENGTH</a>(str), <font color="#666666">"GAMG Level %"</font> PetscInt_FMT, level));
<a name="line668">668: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogStageRegister.html">PetscLogStageRegister</a>(str, &amp;gamg_stages[level]));
<a name="line669">669: </a>    }
<a name="line670">670: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogStagePush.html">PetscLogStagePush</a>(gamg_stages[level]));
<a name="line671">671: </a><font color="#A020F0">#endif</font>
<a name="line672">672: </a>    <font color="#B22222">/* construct prolongator - Parr[level1] */</font>
<a name="line673">673: </a>    <font color="#4169E1">if</font> (level == 0 &amp;&amp; pc_gamg-&gt;injection_index_size &gt; 0) {
<a name="line674">674: </a>      <a href="../../../../../manualpages/Mat/Mat.html">Mat</a>      Prol;
<a name="line675">675: </a>      <a href="../../../../../manualpages/Mat/MatType.html">MatType</a>  mtype;
<a name="line676">676: </a>      <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> prol_m, prol_n, Prol_N = (M / bs) * pc_gamg-&gt;injection_index_size, Istart, Iend, nn, row;
<a name="line677">677: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"Create fine grid injection space prolongation %"</font> PetscInt_FMT <font color="#666666">" x %"</font> PetscInt_FMT <font color="#666666">". %s\n"</font>, M, Prol_N, pc_gamg-&gt;data ? <font color="#666666">"delete null space data"</font> : <font color="#666666">""</font>));
<a name="line678">678: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetOwnershipRange.html">MatGetOwnershipRange</a>(Pmat, &amp;Istart, &amp;Iend));
<a name="line679">679: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetLocalSize.html">MatGetLocalSize</a>(Pmat, &amp;prol_m, NULL)); <font color="#B22222">// rows m x n</font>
<a name="line680">680: </a>      prol_n = (prol_m / bs) * pc_gamg-&gt;injection_index_size;
<a name="line681">681: </a>      <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(pc_gamg-&gt;injection_index_size &lt; bs, <a href="../../../../../manualpages/Sys/PetscObjectComm.html">PetscObjectComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc), <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_ARG_INCOMP</a>, <font color="#666666">"Injection size %"</font> PetscInt_FMT <font color="#666666">" must be less that block size %"</font> PetscInt_FMT, pc_gamg-&gt;injection_index_size, bs);
<a name="line682">682: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetType.html">MatGetType</a>(Pmat, &amp;mtype));
<a name="line683">683: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatCreate.html">MatCreate</a>(<a href="../../../../../manualpages/Sys/PetscObjectComm.html">PetscObjectComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc), &amp;Prol));
<a name="line684">684: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetBlockSizes.html">MatSetBlockSizes</a>(Prol, bs, pc_gamg-&gt;injection_index_size));
<a name="line685">685: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetSizes.html">MatSetSizes</a>(Prol, prol_m, prol_n, M, Prol_N));
<a name="line686">686: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetType.html">MatSetType</a>(Prol, mtype));
<a name="line687">687: </a><font color="#A020F0">#if <a href="../../../../../manualpages/Sys/PetscDefined.html">PetscDefined</a>(HAVE_DEVICE)</font>
<a name="line688">688: </a>      <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> flg;
<a name="line689">689: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatBoundToCPU.html">MatBoundToCPU</a>(Pmat, &amp;flg));
<a name="line690">690: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatBindToCPU.html">MatBindToCPU</a>(Prol, flg));
<a name="line691">691: </a>      <font color="#4169E1">if</font> (flg) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetBindingPropagates.html">MatSetBindingPropagates</a>(Prol, <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>));
<a name="line692">692: </a><font color="#A020F0">#endif</font>
<a name="line693">693: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSeqAIJSetPreallocation.html">MatSeqAIJSetPreallocation</a>(Prol, 1, NULL));
<a name="line694">694: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatMPIAIJSetPreallocation.html">MatMPIAIJSetPreallocation</a>(Prol, 1, NULL, 0, NULL));
<a name="line695">695: </a>      <font color="#B22222">// set I \kron [1, 1, ... ]^T</font>
<a name="line696">696: </a>      <font color="#4169E1">for</font> (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> ii = Istart, col = (Istart / bs) * pc_gamg-&gt;injection_index_size; ii &lt; Iend; ii += bs) {
<a name="line697">697: </a>        const <a href="../../../../../manualpages/Sys/PetscScalar.html">PetscScalar</a> one = 1;
<a name="line698">698: </a>        <font color="#4169E1">for</font> (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> jj = 0; jj &lt; pc_gamg-&gt;injection_index_size; jj++, col++) {
<a name="line699">699: </a>          <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> row = ii + pc_gamg-&gt;injection_index[jj];
<a name="line700">700: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetValues.html">MatSetValues</a>(Prol, 1, &amp;row, 1, &amp;col, &amp;one, <a href="../../../../../manualpages/Sys/INSERT_VALUES.html">INSERT_VALUES</a>));
<a name="line701">701: </a>        }
<a name="line702">702: </a>      }
<a name="line703">703: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatAssemblyBegin.html">MatAssemblyBegin</a>(Prol, <a href="../../../../../manualpages/Mat/MatAssemblyType.html">MAT_FINAL_ASSEMBLY</a>));
<a name="line704">704: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatAssemblyEnd.html">MatAssemblyEnd</a>(Prol, <a href="../../../../../manualpages/Mat/MatAssemblyType.html">MAT_FINAL_ASSEMBLY</a>));
<a name="line705">705: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatViewFromOptions.html">MatViewFromOptions</a>(Prol, NULL, <font color="#666666">"-mat_view_injection"</font>));
<a name="line706">706: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetBlockSizes.html">MatGetBlockSizes</a>(Prol, NULL, &amp;cr_bs)); <font color="#B22222">// column size</font>
<a name="line707">707: </a>      Parr[level1] = Prol;
<a name="line708">708: </a>      <font color="#B22222">// can not deal with null space -- with array of 'injection cols' we could take 'injection rows and 'injection cols' to 'data'</font>
<a name="line709">709: </a>      <font color="#4169E1">if</font> (pc_gamg-&gt;data) {
<a name="line710">710: </a>        pc_gamg-&gt;data_cell_cols      = pc_gamg-&gt;injection_index_size;
<a name="line711">711: </a>        pc_gamg-&gt;data_cell_rows      = pc_gamg-&gt;injection_index_size;
<a name="line712">712: </a>        pc_gamg-&gt;orig_data_cell_cols = 0;
<a name="line713">713: </a>        pc_gamg-&gt;orig_data_cell_rows = 0;
<a name="line714">714: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(pc_gamg-&gt;data));
<a name="line715">715: </a>        pc_gamg-&gt;data_sz = pc_gamg-&gt;injection_index_size * prol_n;
<a name="line716">716: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscMalloc1.html">PetscMalloc1</a>(pc_gamg-&gt;data_sz, &amp;pc_gamg-&gt;data));
<a name="line717">717: </a>        <font color="#4169E1">for</font> (row = nn = 0; row &lt; prol_n; row += pc_gamg-&gt;injection_index_size) {
<a name="line718">718: </a>          <font color="#4169E1">for</font> (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> jj = 0; jj &lt; pc_gamg-&gt;injection_index_size; jj++) {
<a name="line719">719: </a>            <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> idx = row * pc_gamg-&gt;injection_index_size + jj * pc_gamg-&gt;injection_index_size;
<a name="line720">720: </a>            <font color="#4169E1">for</font> (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> kk = 0; kk &lt; pc_gamg-&gt;injection_index_size; kk++, nn++) { pc_gamg-&gt;data[idx + kk] = (jj == kk) ? 1 : 0; }
<a name="line721">721: </a>          }
<a name="line722">722: </a>        }
<a name="line723">723: </a>        <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(nn == pc_gamg-&gt;data_sz, <a href="../../../../../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_PLIB</a>, <font color="#666666">"nn != pc_gamg-&gt;data_sz %"</font> PetscInt_FMT <font color="#666666">" %"</font> PetscInt_FMT, pc_gamg-&gt;data_sz, nn);
<a name="line724">724: </a>      }
<a name="line725">725: </a>    } <font color="#4169E1">else</font> {
<a name="line726">726: </a>      <a href="../../../../../manualpages/Mat/Mat.html">Mat</a>               Gmat, mat;
<a name="line727">727: </a>      PetscCoarsenData *agg_lists;
<a name="line728">728: </a>      <a href="../../../../../manualpages/Mat/Mat.html">Mat</a>               Prol11;

<a name="line730">730: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCGAMGCreateGraph.html">PCGAMGCreateGraph</a>(pc, Aarr[level], &amp;Gmat));
<a name="line731">731: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(pc_gamg-&gt;ops-&gt;coarsen(pc, &amp;Gmat, &amp;agg_lists)); <font color="#B22222">// Gmat may have ghosts for QR aggregates not in matrix</font>
<a name="line732">732: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PetscCDGetMat(agg_lists, &amp;mat));
<a name="line733">733: </a>      <font color="#4169E1">if</font> (!mat) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PetscCDSetMat(agg_lists, Gmat));
<a name="line734">734: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(pc_gamg-&gt;ops-&gt;prolongator(pc, Aarr[level], agg_lists, &amp;Prol11));
<a name="line735">735: </a>      <font color="#B22222">/* could have failed to create new level */</font>
<a name="line736">736: </a>      <font color="#4169E1">if</font> (Prol11) {
<a name="line737">737: </a>        const char *prefix;
<a name="line738">738: </a>        char        addp[32];

<a name="line740">740: </a>        <font color="#B22222">/* get new block size of coarse matrices */</font>
<a name="line741">741: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetBlockSizes.html">MatGetBlockSizes</a>(Prol11, NULL, &amp;cr_bs)); <font color="#B22222">// column size</font>

<a name="line743">743: </a>        <font color="#4169E1">if</font> (pc_gamg-&gt;ops-&gt;optprolongator) {
<a name="line744">744: </a>          <font color="#B22222">/* smooth */</font>
<a name="line745">745: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(pc_gamg-&gt;ops-&gt;optprolongator(pc, Aarr[level], &amp;Prol11));
<a name="line746">746: </a>        }

<a name="line748">748: </a>        <font color="#4169E1">if</font> (pc_gamg-&gt;use_aggs_in_asm) {
<a name="line749">749: </a>          <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> bs;
<a name="line750">750: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetBlockSizes.html">MatGetBlockSizes</a>(Prol11, &amp;bs, NULL)); <font color="#B22222">// row block size</font>
<a name="line751">751: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PetscCDGetASMBlocks(agg_lists, bs, &amp;nASMBlocksArr[level], &amp;ASMLocalIDsArr[level]));
<a name="line752">752: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%"</font> PetscInt_FMT <font color="#666666">": %"</font> PetscInt_FMT <font color="#666666">" ASM local domains,  bs = %"</font> PetscInt_FMT <font color="#666666">"\n"</font>, level, nASMBlocksArr[level], bs));
<a name="line753">753: </a>        } <font color="#4169E1">else</font> <font color="#4169E1">if</font> (pc_gamg-&gt;asm_hem_aggs) {
<a name="line754">754: </a>          const char *prefix;
<a name="line755">755: </a>          <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>    bs;

<a name="line757">757: </a>          <font color="#B22222">/*</font>
<a name="line758">758: </a><font color="#B22222">             Do not use aggs created for defining coarser problems, instead create aggs specifically to use</font>
<a name="line759">759: </a><font color="#B22222">             to define <a href="../../../../../manualpages/PC/PCASM.html">PCASM</a> blocks.</font>
<a name="line760">760: </a><font color="#B22222">          */</font>
<a name="line761">761: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PetscCDGetMat(agg_lists, &amp;mat));
<a name="line762">762: </a>          <font color="#4169E1">if</font> (mat == Gmat) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PetscCDClearMat(agg_lists)); <font color="#B22222">// take the <a href="../../../../../manualpages/Mat/Mat.html">Mat</a> away from the list (yuck)</font>
<a name="line763">763: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PetscCDDestroy(agg_lists));
<a name="line764">764: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"HEM ASM passes = %"</font> PetscInt_FMT <font color="#666666">"\n"</font>, pc_gamg-&gt;asm_hem_aggs));
<a name="line765">765: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatCoarsenDestroy.html">MatCoarsenDestroy</a>(&amp;pc_gamg-&gt;asm_crs));
<a name="line766">766: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatCoarsenCreate.html">MatCoarsenCreate</a>(<a href="../../../../../manualpages/Sys/PetscObjectComm.html">PetscObjectComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc), &amp;pc_gamg-&gt;asm_crs));
<a name="line767">767: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectGetOptionsPrefix.html">PetscObjectGetOptionsPrefix</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, &amp;prefix));
<a name="line768">768: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectSetOptionsPrefix.html">PetscObjectSetOptionsPrefix</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc_gamg-&gt;asm_crs, prefix));
<a name="line769">769: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatCoarsenSetFromOptions.html">MatCoarsenSetFromOptions</a>(pc_gamg-&gt;asm_crs)); <font color="#B22222">// get strength args</font>
<a name="line770">770: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatCoarsenSetType.html">MatCoarsenSetType</a>(pc_gamg-&gt;asm_crs, <a href="../../../../../manualpages/MatGraphOperations/MATCOARSENHEM.html">MATCOARSENHEM</a>));
<a name="line771">771: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatCoarsenSetMaximumIterations.html">MatCoarsenSetMaximumIterations</a>(pc_gamg-&gt;asm_crs, pc_gamg-&gt;asm_hem_aggs));
<a name="line772">772: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatCoarsenSetAdjacency.html">MatCoarsenSetAdjacency</a>(pc_gamg-&gt;asm_crs, Gmat));
<a name="line773">773: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatCoarsenSetStrictAggs.html">MatCoarsenSetStrictAggs</a>(pc_gamg-&gt;asm_crs, <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>));
<a name="line774">774: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatCoarsenApply.html">MatCoarsenApply</a>(pc_gamg-&gt;asm_crs));
<a name="line775">775: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatCoarsenGetData.html">MatCoarsenGetData</a>(pc_gamg-&gt;asm_crs, &amp;agg_lists)); <font color="#B22222">/* output */</font>
<a name="line776">776: </a>          <font color="#B22222">// create aggregates</font>
<a name="line777">777: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetBlockSizes.html">MatGetBlockSizes</a>(Aarr[level], &amp;bs, NULL)); <font color="#B22222">// row block size</font>
<a name="line778">778: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PetscCDGetASMBlocks(agg_lists, bs, &amp;nASMBlocksArr[level], &amp;ASMLocalIDsArr[level]));
<a name="line779">779: </a>        }
<a name="line780">780: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCGetOptionsPrefix.html">PCGetOptionsPrefix</a>(pc, &amp;prefix));
<a name="line781">781: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetOptionsPrefix.html">MatSetOptionsPrefix</a>(Prol11, prefix));
<a name="line782">782: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscSNPrintf.html">PetscSNPrintf</a>(addp, <font color="#4169E1">sizeof</font>(addp), <font color="#666666">"pc_gamg_prolongator_%"</font> PetscInt_FMT <font color="#666666">"_"</font>, level));
<a name="line783">783: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatAppendOptionsPrefix.html">MatAppendOptionsPrefix</a>(Prol11, addp));
<a name="line784">784: </a>        <font color="#B22222">/* Always generate the transpose with CUDA</font>
<a name="line785">785: </a><font color="#B22222">           Such behaviour can be adapted with -pc_gamg_prolongator_ prefixed options */</font>
<a name="line786">786: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetOption.html">MatSetOption</a>(Prol11, <a href="../../../../../manualpages/Mat/MatOption.html">MAT_FORM_EXPLICIT_TRANSPOSE</a>, <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>));
<a name="line787">787: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatSetFromOptions.html">MatSetFromOptions</a>(Prol11));
<a name="line788">788: </a>        Parr[level1] = Prol11;
<a name="line789">789: </a>      } <font color="#4169E1">else</font> Parr[level1] = NULL; <font color="#B22222">/* failed to coarsen */</font>
<a name="line790">790: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PetscCDGetMat(agg_lists, &amp;mat));
<a name="line791">791: </a>      <font color="#4169E1">if</font> (mat == Gmat) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PetscCDClearMat(agg_lists)); <font color="#B22222">// take the <a href="../../../../../manualpages/Mat/Mat.html">Mat</a> away from the list (yuck)</font>
<a name="line792">792: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatDestroy.html">MatDestroy</a>(&amp;Gmat));
<a name="line793">793: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PetscCDDestroy(agg_lists));
<a name="line794">794: </a>    } <font color="#B22222">/* construct prolongator scope */</font>
<a name="line795">795: </a>    <font color="#4169E1">if</font> (level == 0) Aarr[0] = Pmat; <font color="#B22222">/* use Pmat for finest level setup */</font>
<a name="line796">796: </a>    <font color="#4169E1">if</font> (!Parr[level1]) {            <font color="#B22222">/* failed to coarsen */</font>
<a name="line797">797: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: Stop gridding, level %"</font> PetscInt_FMT <font color="#666666">"\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, level));
<a name="line798">798: </a><font color="#A020F0">#if defined(GAMG_STAGES)</font>
<a name="line799">799: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogStagePop.html">PetscLogStagePop</a>());
<a name="line800">800: </a><font color="#A020F0">#endif</font>
<a name="line801">801: </a>      <font color="#4169E1">break</font>;
<a name="line802">802: </a>    }
<a name="line803">803: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetSize.html">MatGetSize</a>(Parr[level1], &amp;M, &amp;N)); <font color="#B22222">/* N is next M, a loop test variables */</font>
<a name="line804">804: </a>    <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(!is_last, <a href="../../../../../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_PLIB</a>, <font color="#666666">"Is last ?"</font>);
<a name="line805">805: </a>    <font color="#4169E1">if</font> (N &lt;= pc_gamg-&gt;coarse_eq_limit) is_last = <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>;
<a name="line806">806: </a>    <font color="#4169E1">if</font> (level1 == pc_gamg-&gt;Nlevels - 1) is_last = <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>;
<a name="line807">807: </a>    <font color="#4169E1">if</font> (level == PETSC_MG_MAXLEVELS - 2) is_last = <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>;
<a name="line808">808: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventBegin.html">PetscLogEventBegin</a>(petsc_gamg_setup_events[GAMG_LEVEL], 0, 0, 0, 0));
<a name="line809">809: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(pc_gamg-&gt;ops-&gt;createlevel(pc, Aarr[level], cr_bs, &amp;Parr[level1], &amp;Aarr[level1], &amp;nactivepe, NULL, is_last));
<a name="line810">810: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_events[GAMG_LEVEL], 0, 0, 0, 0));

<a name="line812">812: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetSize.html">MatGetSize</a>(Aarr[level1], &amp;M, &amp;N)); <font color="#B22222">/* M is loop test variables */</font>
<a name="line813">813: </a><font color="#A020F0">#if defined(PETSC_USE_INFO)</font>
<a name="line814">814: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetInfo.html">MatGetInfo</a>(Aarr[level1], <a href="../../../../../manualpages/Mat/MatInfoType.html">MAT_GLOBAL_SUM</a>, &amp;info));
<a name="line815">815: </a>    nnztot += info.nz_used;
<a name="line816">816: </a><font color="#A020F0">#endif</font>
<a name="line817">817: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: %"</font> PetscInt_FMT <font color="#666666">") N=%"</font> PetscInt_FMT <font color="#666666">", n data cols=%"</font> PetscInt_FMT <font color="#666666">", nnz/row (ave)=%"</font> PetscInt_FMT <font color="#666666">", %d active pes\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, level1, M, pc_gamg-&gt;data_cell_cols, (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>)(info.nz_used / (<a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a>)M), nactivepe));

<a name="line819">819: </a><font color="#A020F0">#if defined(GAMG_STAGES)</font>
<a name="line820">820: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogStagePop.html">PetscLogStagePop</a>());
<a name="line821">821: </a><font color="#A020F0">#endif</font>
<a name="line822">822: </a>    <font color="#B22222">/* stop if one node or one proc -- could pull back for singular problems */</font>
<a name="line823">823: </a>    <font color="#4169E1">if</font> ((pc_gamg-&gt;data_cell_cols &amp;&amp; M / pc_gamg-&gt;data_cell_cols &lt; 2) || (!pc_gamg-&gt;data_cell_cols &amp;&amp; M / bs &lt; 2)) {
<a name="line824">824: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: HARD stop of coarsening on level %"</font> PetscInt_FMT <font color="#666666">".  Grid too small: %"</font> PetscInt_FMT <font color="#666666">" block nodes\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, level, M / bs));
<a name="line825">825: </a>      level++;
<a name="line826">826: </a>      <font color="#4169E1">break</font>;
<a name="line827">827: </a>    } <font color="#4169E1">else</font> <font color="#4169E1">if</font> (level == PETSC_MG_MAXLEVELS - 2) { <font color="#B22222">/* stop if we are limited by PC_MG_MAXLEVELS */</font>
<a name="line828">828: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: HARD stop of coarsening on level %"</font> PetscInt_FMT <font color="#666666">".  PC_MG_MAXLEVELS reached\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, level));
<a name="line829">829: </a>      level++;
<a name="line830">830: </a>      <font color="#4169E1">break</font>;
<a name="line831">831: </a>    }
<a name="line832">832: </a>  } <font color="#B22222">/* levels */</font>
<a name="line833">833: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(pc_gamg-&gt;data));

<a name="line835">835: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: %"</font> PetscInt_FMT <font color="#666666">" levels, operator complexity = %g\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, level + 1, nnztot / nnz0));
<a name="line836">836: </a>  pc_gamg-&gt;Nlevels = level + 1;
<a name="line837">837: </a>  fine_level       = level;
<a name="line838">838: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCMGSetLevels.html">PCMGSetLevels</a>(pc, pc_gamg-&gt;Nlevels, NULL));

<a name="line840">840: </a>  <font color="#4169E1">if</font> (pc_gamg-&gt;Nlevels &gt; 1) { <font color="#B22222">/* don't setup MG if one level */</font>

<a name="line842">842: </a>    <font color="#B22222">/* set default smoothers &amp; set operators */</font>
<a name="line843">843: </a>    <font color="#4169E1">for</font> (lidx = 1, level = pc_gamg-&gt;Nlevels - 2; lidx &lt;= fine_level; lidx++, level--) {
<a name="line844">844: </a>      <a href="../../../../../manualpages/KSP/KSP.html">KSP</a> smoother;
<a name="line845">845: </a>      <a href="../../../../../manualpages/PC/PC.html">PC</a>  subpc;

<a name="line847">847: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCMGGetSmoother.html">PCMGGetSmoother</a>(pc, lidx, &amp;smoother));
<a name="line848">848: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPGetPC.html">KSPGetPC</a>(smoother, &amp;subpc));

<a name="line850">850: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPSetNormType.html">KSPSetNormType</a>(smoother, <a href="../../../../../manualpages/KSP/KSP_NORM_NONE.html">KSP_NORM_NONE</a>));
<a name="line851">851: </a>      <font color="#B22222">/* set ops */</font>
<a name="line852">852: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPSetOperators.html">KSPSetOperators</a>(smoother, Aarr[level], Aarr[level]));
<a name="line853">853: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCMGSetInterpolation.html">PCMGSetInterpolation</a>(pc, lidx, Parr[level + 1]));

<a name="line855">855: </a>      <font color="#B22222">/* set defaults */</font>
<a name="line856">856: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPSetType.html">KSPSetType</a>(smoother, <a href="../../../../../manualpages/KSP/KSPCHEBYSHEV.html">KSPCHEBYSHEV</a>));

<a name="line858">858: </a>      <font color="#B22222">/* set blocks for ASM smoother that uses the 'aggregates' */</font>
<a name="line859">859: </a>      <font color="#4169E1">if</font> (pc_gamg-&gt;use_aggs_in_asm || pc_gamg-&gt;asm_hem_aggs) {
<a name="line860">860: </a>        <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> sz;
<a name="line861">861: </a>        <a href="../../../../../manualpages/IS/IS.html">IS</a>      *iss;

<a name="line863">863: </a>        sz  = nASMBlocksArr[level];
<a name="line864">864: </a>        iss = ASMLocalIDsArr[level];
<a name="line865">865: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCSetType.html">PCSetType</a>(subpc, <a href="../../../../../manualpages/PC/PCASM.html">PCASM</a>));
<a name="line866">866: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCASMSetOverlap.html">PCASMSetOverlap</a>(subpc, 0));
<a name="line867">867: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCASMSetType.html">PCASMSetType</a>(subpc, <a href="../../../../../manualpages/PC/PCASMType.html">PC_ASM_BASIC</a>));
<a name="line868">868: </a>        <font color="#4169E1">if</font> (!sz) {
<a name="line869">869: </a>          <a href="../../../../../manualpages/IS/IS.html">IS</a> is;
<a name="line870">870: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISCreateGeneral.html">ISCreateGeneral</a>(<a href="../../../../../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, 0, NULL, <a href="../../../../../manualpages/Sys/PetscCopyMode.html">PETSC_COPY_VALUES</a>, &amp;is));
<a name="line871">871: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCASMSetLocalSubdomains.html">PCASMSetLocalSubdomains</a>(subpc, 1, NULL, &amp;is));
<a name="line872">872: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&amp;is));
<a name="line873">873: </a>        } <font color="#4169E1">else</font> {
<a name="line874">874: </a>          <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> kk;
<a name="line875">875: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCASMSetLocalSubdomains.html">PCASMSetLocalSubdomains</a>(subpc, sz, iss, NULL));
<a name="line876">876: </a>          <font color="#4169E1">for</font> (kk = 0; kk &lt; sz; kk++) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&amp;iss[kk]));
<a name="line877">877: </a>          <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(iss));
<a name="line878">878: </a>        }
<a name="line879">879: </a>        ASMLocalIDsArr[level] = NULL;
<a name="line880">880: </a>        nASMBlocksArr[level]  = 0;
<a name="line881">881: </a>      } <font color="#4169E1">else</font> {
<a name="line882">882: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCSetType.html">PCSetType</a>(subpc, <a href="../../../../../manualpages/PC/PCJACOBI.html">PCJACOBI</a>));
<a name="line883">883: </a>      }
<a name="line884">884: </a>    }
<a name="line885">885: </a>    {
<a name="line886">886: </a>      <font color="#B22222">/* coarse grid */</font>
<a name="line887">887: </a>      <a href="../../../../../manualpages/KSP/KSP.html">KSP</a>      smoother, *k2;
<a name="line888">888: </a>      <a href="../../../../../manualpages/PC/PC.html">PC</a>       subpc, pc2;
<a name="line889">889: </a>      <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> ii, first;
<a name="line890">890: </a>      <a href="../../../../../manualpages/Mat/Mat.html">Mat</a>      Lmat = Aarr[pc_gamg-&gt;Nlevels - 1];
<a name="line891">891: </a>      lidx          = 0;

<a name="line893">893: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCMGGetSmoother.html">PCMGGetSmoother</a>(pc, lidx, &amp;smoother));
<a name="line894">894: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPSetOperators.html">KSPSetOperators</a>(smoother, Lmat, Lmat));
<a name="line895">895: </a>      <font color="#4169E1">if</font> (!pc_gamg-&gt;use_parallel_coarse_grid_solver) {
<a name="line896">896: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPSetNormType.html">KSPSetNormType</a>(smoother, <a href="../../../../../manualpages/KSP/KSP_NORM_NONE.html">KSP_NORM_NONE</a>));
<a name="line897">897: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPGetPC.html">KSPGetPC</a>(smoother, &amp;subpc));
<a name="line898">898: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCSetType.html">PCSetType</a>(subpc, <a href="../../../../../manualpages/PC/PCBJACOBI.html">PCBJACOBI</a>));
<a name="line899">899: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCSetUp.html">PCSetUp</a>(subpc));
<a name="line900">900: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCBJacobiGetSubKSP.html">PCBJacobiGetSubKSP</a>(subpc, &amp;ii, &amp;first, &amp;k2));
<a name="line901">901: </a>        <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(ii == 1, <a href="../../../../../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_PLIB</a>, <font color="#666666">"ii %"</font> PetscInt_FMT <font color="#666666">" is not one"</font>, ii);
<a name="line902">902: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPGetPC.html">KSPGetPC</a>(k2[0], &amp;pc2));
<a name="line903">903: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCSetType.html">PCSetType</a>(pc2, <a href="../../../../../manualpages/PC/PCLU.html">PCLU</a>));
<a name="line904">904: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCFactorSetShiftType.html">PCFactorSetShiftType</a>(pc2, MAT_SHIFT_INBLOCKS));
<a name="line905">905: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPSetTolerances.html">KSPSetTolerances</a>(k2[0], <a href="../../../../../manualpages/Sys/PETSC_CURRENT.html">PETSC_CURRENT</a>, <a href="../../../../../manualpages/Sys/PETSC_CURRENT.html">PETSC_CURRENT</a>, <a href="../../../../../manualpages/Sys/PETSC_CURRENT.html">PETSC_CURRENT</a>, 1));
<a name="line906">906: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPSetType.html">KSPSetType</a>(k2[0], <a href="../../../../../manualpages/KSP/KSPPREONLY.html">KSPPREONLY</a>));
<a name="line907">907: </a>      }
<a name="line908">908: </a>    }

<a name="line910">910: </a>    <font color="#B22222">/* should be called in PCSetFromOptions_GAMG(), but cannot be called prior to <a href="../../../../../manualpages/PC/PCMGSetLevels.html">PCMGSetLevels</a>() */</font>
<a name="line911">911: </a>    <a href="../../../../../manualpages/Sys/PetscObjectOptionsBegin.html">PetscObjectOptionsBegin</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc);
<a name="line912">912: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCSetFromOptions_MG(pc, PetscOptionsObject));
<a name="line913">913: </a>    <a href="../../../../../manualpages/Sys/PetscOptionsEnd.html">PetscOptionsEnd</a>();
<a name="line914">914: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCMGSetGalerkin.html">PCMGSetGalerkin</a>(pc, <a href="../../../../../manualpages/PC/PCMGalerkinType.html">PC_MG_GALERKIN_EXTERNAL</a>));

<a name="line916">916: </a>    <font color="#B22222">/* set cheby eigen estimates from SA to use in the solver */</font>
<a name="line917">917: </a>    <font color="#4169E1">if</font> (pc_gamg-&gt;use_sa_esteig) {
<a name="line918">918: </a>      <font color="#4169E1">for</font> (lidx = 1, level = pc_gamg-&gt;Nlevels - 2; level &gt;= 0; lidx++, level--) {
<a name="line919">919: </a>        <a href="../../../../../manualpages/KSP/KSP.html">KSP</a>       smoother;
<a name="line920">920: </a>        <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> ischeb;

<a name="line922">922: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCMGGetSmoother.html">PCMGGetSmoother</a>(pc, lidx, &amp;smoother));
<a name="line923">923: </a>        <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectTypeCompare.html">PetscObjectTypeCompare</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)smoother, <a href="../../../../../manualpages/KSP/KSPCHEBYSHEV.html">KSPCHEBYSHEV</a>, &amp;ischeb));
<a name="line924">924: </a>        <font color="#4169E1">if</font> (ischeb) {
<a name="line925">925: </a>          KSP_Chebyshev *cheb = (KSP_Chebyshev *)smoother-&gt;data;

<a name="line927">927: </a>          <font color="#B22222">// The command line will override these settings because <a href="../../../../../manualpages/KSP/KSPSetFromOptions.html">KSPSetFromOptions</a> is called in PCSetUp_MG</font>
<a name="line928">928: </a>          <font color="#4169E1">if</font> (mg-&gt;max_eigen_DinvA[level] &gt; 0) {
<a name="line929">929: </a>            <font color="#B22222">// SA uses Jacobi for P; we use SA estimates if the smoother is also Jacobi or if the user explicitly requested it.</font>
<a name="line930">930: </a>            <font color="#B22222">// TODO: This should test whether it's the same Jacobi variant (DIAG, ROWSUM, etc.)</font>
<a name="line931">931: </a>            <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> emax, emin;

<a name="line933">933: </a>            emin = mg-&gt;min_eigen_DinvA[level];
<a name="line934">934: </a>            emax = mg-&gt;max_eigen_DinvA[level];
<a name="line935">935: </a>            <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: PCSetUp_GAMG: call <a href="../../../../../manualpages/KSP/KSPChebyshevSetEigenvalues.html">KSPChebyshevSetEigenvalues</a> on level %"</font> PetscInt_FMT <font color="#666666">" (N=%"</font> PetscInt_FMT <font color="#666666">") with emax = %g emin = %g\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix, level, Aarr[level]-&gt;rmap-&gt;N, (double)emax, (double)emin));
<a name="line936">936: </a>            cheb-&gt;emin_provided = emin;
<a name="line937">937: </a>            cheb-&gt;emax_provided = emax;
<a name="line938">938: </a>          }
<a name="line939">939: </a>        }
<a name="line940">940: </a>      }
<a name="line941">941: </a>    }

<a name="line943">943: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCSetUp_MG(pc));

<a name="line945">945: </a>    <font color="#B22222">/* clean up */</font>
<a name="line946">946: </a>    <font color="#4169E1">for</font> (level = 1; level &lt; pc_gamg-&gt;Nlevels; level++) {
<a name="line947">947: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatDestroy.html">MatDestroy</a>(&amp;Parr[level]));
<a name="line948">948: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatDestroy.html">MatDestroy</a>(&amp;Aarr[level]));
<a name="line949">949: </a>    }
<a name="line950">950: </a>  } <font color="#4169E1">else</font> {
<a name="line951">951: </a>    <a href="../../../../../manualpages/KSP/KSP.html">KSP</a> smoother;

<a name="line953">953: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscInfo.html">PetscInfo</a>(pc, <font color="#666666">"%s: One level solver used (system is seen as DD). Using default solver.\n"</font>, ((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)-&gt;prefix));
<a name="line954">954: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCMGGetSmoother.html">PCMGGetSmoother</a>(pc, 0, &amp;smoother));
<a name="line955">955: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPSetOperators.html">KSPSetOperators</a>(smoother, Aarr[0], Aarr[0]));
<a name="line956">956: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPSetType.html">KSPSetType</a>(smoother, <a href="../../../../../manualpages/KSP/KSPPREONLY.html">KSPPREONLY</a>));
<a name="line957">957: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCSetUp_MG(pc));
<a name="line958">958: </a>  }
<a name="line959">959: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventEnd.html">PetscLogEventEnd</a>(petsc_gamg_setup_events[GAMG_SETUP], 0, 0, 0, 0));
<a name="line960">960: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line961">961: </a>}

<a name="line963">963: </a><font color="#B22222">/*</font>
<a name="line964">964: </a><font color="#B22222"> PCDestroy_GAMG - Destroys the private context for the GAMG preconditioner</font>
<a name="line965">965: </a><font color="#B22222">   that was created with PCCreate_GAMG().</font>

<a name="line967">967: </a><font color="#B22222">   Input Parameter:</font>
<a name="line968">968: </a><font color="#B22222">.  pc - the preconditioner context</font>

<a name="line970">970: </a><font color="#B22222">   Application Interface Routine: <a href="../../../../../manualpages/PC/PCDestroy.html">PCDestroy</a>()</font>
<a name="line971">971: </a><font color="#B22222">*/</font>
<a name="line972">972: </a><strong><font color="#4169E1"><a name="PCDestroy_GAMG"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCDestroy_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc)</font></strong>
<a name="line973">973: </a>{
<a name="line974">974: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line975">975: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line977">977: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line978">978: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCReset_GAMG(pc));
<a name="line979">979: </a>  <font color="#4169E1">if</font> (pc_gamg-&gt;ops-&gt;destroy) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>((*pc_gamg-&gt;ops-&gt;destroy)(pc));
<a name="line980">980: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(pc_gamg-&gt;ops));
<a name="line981">981: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(pc_gamg-&gt;gamg_type_name));
<a name="line982">982: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(pc_gamg));
<a name="line983">983: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetProcEqLim_C"</font>, NULL));
<a name="line984">984: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetCoarseEqLim_C"</font>, NULL));
<a name="line985">985: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetRepartition_C"</font>, NULL));
<a name="line986">986: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetEigenvalues_C"</font>, NULL));
<a name="line987">987: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetUseSAEstEig_C"</font>, NULL));
<a name="line988">988: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetRecomputeEstEig_C"</font>, NULL));
<a name="line989">989: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetReuseInterpolation_C"</font>, NULL));
<a name="line990">990: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGASMSetUseAggs_C"</font>, NULL));
<a name="line991">991: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetParallelCoarseGridSolve_C"</font>, NULL));
<a name="line992">992: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetCpuPinCoarseGrids_C"</font>, NULL));
<a name="line993">993: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetCoarseGridLayoutType_C"</font>, NULL));
<a name="line994">994: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetThreshold_C"</font>, NULL));
<a name="line995">995: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetRankReductionFactors_C"</font>, NULL));
<a name="line996">996: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetThresholdScale_C"</font>, NULL));
<a name="line997">997: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetType_C"</font>, NULL));
<a name="line998">998: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGGetType_C"</font>, NULL));
<a name="line999">999: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetNlevels_C"</font>, NULL));
<a name="line1000">1000: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGASMSetHEM_C"</font>, NULL));
<a name="line1001">1001: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetInjectionIndices_C"</font>, NULL));
<a name="line1002">1002: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetInjectionIndex_C"</font>, NULL));
<a name="line1003">1003: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCDestroy_MG(pc));
<a name="line1004">1004: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1005">1005: </a>}

<a name="line1007">1007: </a><font color="#B22222">/*@</font>
<a name="line1008">1008: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetProcEqLim.html">PCGAMGSetProcEqLim</a> - Set number of equations to aim for per process on the coarse grids via processor reduction in `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`</font>

<a name="line1010">1010: </a><font color="#B22222">  Logically Collective</font>

<a name="line1012">1012: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1013">1013: </a><font color="#B22222">+ pc - the preconditioner context</font>
<a name="line1014">1014: </a><font color="#B22222">- n  - the number of equations</font>

<a name="line1016">1016: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1017">1017: </a><font color="#B22222">. -pc_gamg_process_eq_limit &lt;limit&gt; - set the limit</font>

<a name="line1019">1019: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1021">1021: </a><font color="#B22222">  Note:</font>
<a name="line1022">1022: </a><font color="#B22222">  `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` will reduce the number of MPI processes used directly on the coarse grids so that there are around &lt;limit&gt; equations on each process</font>
<a name="line1023">1023: </a><font color="#B22222">  that has degrees of freedom</font>

<a name="line1025">1025: </a><font color="#B22222">  Developer Note:</font>
<a name="line1026">1026: </a><font color="#B22222">  Should be named `PCGAMGSetProcessEquationLimit()`.</font>

<a name="line1028">1028: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetCoarseEqLim.html">PCGAMGSetCoarseEqLim</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetRankReductionFactors.html">PCGAMGSetRankReductionFactors</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetRepartition.html">PCGAMGSetRepartition</a>()`</font>
<a name="line1029">1029: </a><font color="#B22222">@*/</font>
<a name="line1030">1030: </a><strong><font color="#4169E1"><a name="PCGAMGSetProcEqLim"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetProcEqLim.html">PCGAMGSetProcEqLim</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n)</font></strong>
<a name="line1031">1031: </a>{
<a name="line1032">1032: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1034">1034: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetProcEqLim_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>), (pc, n));
<a name="line1035">1035: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1036">1036: </a>}

<a name="line1038">1038: </a><strong><font color="#4169E1"><a name="PCGAMGSetProcEqLim_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetProcEqLim_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n)</font></strong>
<a name="line1039">1039: </a>{
<a name="line1040">1040: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1041">1041: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1043">1043: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1044">1044: </a>  <font color="#4169E1">if</font> (n &gt; 0) pc_gamg-&gt;min_eq_proc = n;
<a name="line1045">1045: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1046">1046: </a>}

<a name="line1048">1048: </a><font color="#B22222">/*@</font>
<a name="line1049">1049: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetCoarseEqLim.html">PCGAMGSetCoarseEqLim</a> - Set maximum number of equations on the coarsest grid of `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`</font>

<a name="line1051">1051: </a><font color="#B22222">  Collective</font>

<a name="line1053">1053: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1054">1054: </a><font color="#B22222">+ pc - the preconditioner context</font>
<a name="line1055">1055: </a><font color="#B22222">- n  - maximum number of equations to aim for</font>

<a name="line1057">1057: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1058">1058: </a><font color="#B22222">. -pc_gamg_coarse_eq_limit &lt;limit&gt; - set the limit</font>

<a name="line1060">1060: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1062">1062: </a><font color="#B22222">  Note:</font>
<a name="line1063">1063: </a><font color="#B22222">  For example -pc_gamg_coarse_eq_limit 1000 will stop coarsening once the coarse grid</font>
<a name="line1064">1064: </a><font color="#B22222">  has less than 1000 unknowns.</font>

<a name="line1066">1066: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetProcEqLim.html">PCGAMGSetProcEqLim</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetRankReductionFactors.html">PCGAMGSetRankReductionFactors</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetRepartition.html">PCGAMGSetRepartition</a>()`,</font>
<a name="line1067">1067: </a><font color="#B22222">          `<a href="../../../../../manualpages/PC/PCGAMGSetParallelCoarseGridSolve.html">PCGAMGSetParallelCoarseGridSolve</a>()`</font>
<a name="line1068">1068: </a><font color="#B22222">@*/</font>
<a name="line1069">1069: </a><strong><font color="#4169E1"><a name="PCGAMGSetCoarseEqLim"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetCoarseEqLim.html">PCGAMGSetCoarseEqLim</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n)</font></strong>
<a name="line1070">1070: </a>{
<a name="line1071">1071: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1073">1073: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetCoarseEqLim_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>), (pc, n));
<a name="line1074">1074: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1075">1075: </a>}

<a name="line1077">1077: </a><strong><font color="#4169E1"><a name="PCGAMGSetCoarseEqLim_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetCoarseEqLim_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n)</font></strong>
<a name="line1078">1078: </a>{
<a name="line1079">1079: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1080">1080: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1082">1082: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1083">1083: </a>  <font color="#4169E1">if</font> (n &gt; 0) pc_gamg-&gt;coarse_eq_limit = n;
<a name="line1084">1084: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1085">1085: </a>}

<a name="line1087">1087: </a><font color="#B22222">/*@</font>
<a name="line1088">1088: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetRepartition.html">PCGAMGSetRepartition</a> - Repartition the degrees of freedom across the processors on the coarser grids when reducing the number of MPI ranks to use</font>

<a name="line1090">1090: </a><font color="#B22222">  Collective</font>

<a name="line1092">1092: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1093">1093: </a><font color="#B22222">+ pc - the preconditioner context</font>
<a name="line1094">1094: </a><font color="#B22222">- n  - `<a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>` or `<a href="../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>`</font>

<a name="line1096">1096: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1097">1097: </a><font color="#B22222">. -pc_gamg_repartition &lt;true,false&gt; - turn on the repartitioning</font>

<a name="line1099">1099: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1101">1101: </a><font color="#B22222">  Note:</font>
<a name="line1102">1102: </a><font color="#B22222">  This will generally improve the loading balancing of the work on each level so the solves will be faster but it adds to the</font>
<a name="line1103">1103: </a><font color="#B22222">  preconditioner setup time.</font>

<a name="line1105">1105: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetProcEqLim.html">PCGAMGSetProcEqLim</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetRankReductionFactors.html">PCGAMGSetRankReductionFactors</a>()`</font>
<a name="line1106">1106: </a><font color="#B22222">@*/</font>
<a name="line1107">1107: </a><strong><font color="#4169E1"><a name="PCGAMGSetRepartition"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetRepartition.html">PCGAMGSetRepartition</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> n)</font></strong>
<a name="line1108">1108: </a>{
<a name="line1109">1109: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1111">1111: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetRepartition_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a>), (pc, n));
<a name="line1112">1112: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1113">1113: </a>}

<a name="line1115">1115: </a><strong><font color="#4169E1"><a name="PCGAMGSetRepartition_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetRepartition_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> n)</font></strong>
<a name="line1116">1116: </a>{
<a name="line1117">1117: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1118">1118: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1120">1120: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1121">1121: </a>  pc_gamg-&gt;repart = n;
<a name="line1122">1122: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1123">1123: </a>}

<a name="line1125">1125: </a><font color="#B22222">/*@</font>
<a name="line1126">1126: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetUseSAEstEig.html">PCGAMGSetUseSAEstEig</a> - Use the eigen estimate from smoothed aggregation for the Chebyshev smoother during the solution process</font>

<a name="line1128">1128: </a><font color="#B22222">  Collective</font>

<a name="line1130">1130: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1131">1131: </a><font color="#B22222">+ pc - the preconditioner context</font>
<a name="line1132">1132: </a><font color="#B22222">- b  - flag</font>

<a name="line1134">1134: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1135">1135: </a><font color="#B22222">. -pc_gamg_use_sa_esteig &lt;true,false&gt; - use the eigen estimate</font>

<a name="line1137">1137: </a><font color="#B22222">  Level: advanced</font>

<a name="line1139">1139: </a><font color="#B22222">  Notes:</font>
<a name="line1140">1140: </a><font color="#B22222">  Smoothed aggregation constructs the smoothed prolongator $P = (I - \omega D^{-1} A) T$ where $T$ is the tentative prolongator and $D$ is the diagonal of $A$.</font>
<a name="line1141">1141: </a><font color="#B22222">  Eigenvalue estimates (based on a few `PCCG` or `PCGMRES` iterations) are computed to choose $\omega$ so that this is a stable smoothing operation.</font>
<a name="line1142">1142: </a><font color="#B22222">  If `<a href="../../../../../manualpages/KSP/KSPCHEBYSHEV.html">KSPCHEBYSHEV</a>` with `<a href="../../../../../manualpages/PC/PCJACOBI.html">PCJACOBI</a>` (diagonal) preconditioning is used for smoothing on the finest level, then the eigenvalue estimates</font>
<a name="line1143">1143: </a><font color="#B22222">  can be reused during the solution process.</font>
<a name="line1144">1144: </a><font color="#B22222">  This option is only used when the smoother uses `<a href="../../../../../manualpages/PC/PCJACOBI.html">PCJACOBI</a>`, and should be turned off when a different `<a href="../../../../../manualpages/PC/PCJacobiType.html">PCJacobiType</a>` is used.</font>
<a name="line1145">1145: </a><font color="#B22222">  It became default in PETSc 3.17.</font>

<a name="line1147">1147: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/KSP/KSPChebyshevSetEigenvalues.html">KSPChebyshevSetEigenvalues</a>()`, `<a href="../../../../../manualpages/KSP/KSPChebyshevEstEigSet.html">KSPChebyshevEstEigSet</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetRecomputeEstEig.html">PCGAMGSetRecomputeEstEig</a>()`</font>
<a name="line1148">1148: </a><font color="#B22222">@*/</font>
<a name="line1149">1149: </a><strong><font color="#4169E1"><a name="PCGAMGSetUseSAEstEig"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetUseSAEstEig.html">PCGAMGSetUseSAEstEig</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> b)</font></strong>
<a name="line1150">1150: </a>{
<a name="line1151">1151: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1153">1153: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetUseSAEstEig_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a>), (pc, b));
<a name="line1154">1154: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1155">1155: </a>}

<a name="line1157">1157: </a><strong><font color="#4169E1"><a name="PCGAMGSetUseSAEstEig_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetUseSAEstEig_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> b)</font></strong>
<a name="line1158">1158: </a>{
<a name="line1159">1159: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1160">1160: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1162">1162: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1163">1163: </a>  pc_gamg-&gt;use_sa_esteig = b;
<a name="line1164">1164: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1165">1165: </a>}

<a name="line1167">1167: </a><font color="#B22222">/*@</font>
<a name="line1168">1168: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetRecomputeEstEig.html">PCGAMGSetRecomputeEstEig</a> - Set flag for Chebyshev smoothers to recompute the eigen estimates when a new matrix is used</font>

<a name="line1170">1170: </a><font color="#B22222">  Collective</font>

<a name="line1172">1172: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1173">1173: </a><font color="#B22222">+ pc - the preconditioner context</font>
<a name="line1174">1174: </a><font color="#B22222">- b  - flag, default is `<a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>`</font>

<a name="line1176">1176: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1177">1177: </a><font color="#B22222">. -pc_gamg_recompute_esteig &lt;true&gt; - use the eigen estimate</font>

<a name="line1179">1179: </a><font color="#B22222">  Level: advanced</font>

<a name="line1181">1181: </a><font color="#B22222">  Note:</font>
<a name="line1182">1182: </a><font color="#B22222">  If the matrix changes only slightly in a new solve using ``<a href="../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>`` will save time in the setting up of the preconditioner</font>
<a name="line1183">1183: </a><font color="#B22222">  and may not affect the solution time much.</font>

<a name="line1185">1185: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/KSP/KSPChebyshevSetEigenvalues.html">KSPChebyshevSetEigenvalues</a>()`, `<a href="../../../../../manualpages/KSP/KSPChebyshevEstEigSet.html">KSPChebyshevEstEigSet</a>()`</font>
<a name="line1186">1186: </a><font color="#B22222">@*/</font>
<a name="line1187">1187: </a><strong><font color="#4169E1"><a name="PCGAMGSetRecomputeEstEig"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetRecomputeEstEig.html">PCGAMGSetRecomputeEstEig</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> b)</font></strong>
<a name="line1188">1188: </a>{
<a name="line1189">1189: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1191">1191: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetRecomputeEstEig_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a>), (pc, b));
<a name="line1192">1192: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1193">1193: </a>}

<a name="line1195">1195: </a><strong><font color="#4169E1"><a name="PCGAMGSetRecomputeEstEig_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetRecomputeEstEig_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> b)</font></strong>
<a name="line1196">1196: </a>{
<a name="line1197">1197: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1198">1198: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1200">1200: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1201">1201: </a>  pc_gamg-&gt;recompute_esteig = b;
<a name="line1202">1202: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1203">1203: </a>}

<a name="line1205">1205: </a><font color="#B22222">/*@</font>
<a name="line1206">1206: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetEigenvalues.html">PCGAMGSetEigenvalues</a> - Set WHAT eigenvalues WHY?</font>

<a name="line1208">1208: </a><font color="#B22222">  Collective</font>

<a name="line1210">1210: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1211">1211: </a><font color="#B22222">+ pc   - the preconditioner context</font>
<a name="line1212">1212: </a><font color="#B22222">. emax - max eigenvalue</font>
<a name="line1213">1213: </a><font color="#B22222">- emin - min eigenvalue</font>

<a name="line1215">1215: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1216">1216: </a><font color="#B22222">. -pc_gamg_eigenvalues &lt;emin,emax&gt; - estimates of the eigenvalues</font>

<a name="line1218">1218: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1220">1220: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetUseSAEstEig.html">PCGAMGSetUseSAEstEig</a>()`</font>
<a name="line1221">1221: </a><font color="#B22222">@*/</font>
<a name="line1222">1222: </a><strong><font color="#4169E1"><a name="PCGAMGSetEigenvalues"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetEigenvalues.html">PCGAMGSetEigenvalues</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> emax, <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> emin)</font></strong>
<a name="line1223">1223: </a>{
<a name="line1224">1224: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1226">1226: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetEigenvalues_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a>, <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a>), (pc, emax, emin));
<a name="line1227">1227: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1228">1228: </a>}

<a name="line1230">1230: </a><strong><font color="#4169E1"><a name="PCGAMGSetEigenvalues_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetEigenvalues_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> emax, <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> emin)</font></strong>
<a name="line1231">1231: </a>{
<a name="line1232">1232: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1233">1233: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1235">1235: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1236">1236: </a>  <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(emax &gt; emin, <a href="../../../../../manualpages/Sys/PetscObjectComm.html">PetscObjectComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc), <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_ARG_INCOMP</a>, <font color="#666666">"Maximum eigenvalue must be larger than minimum: max %g min %g"</font>, (double)emax, (double)emin);
<a name="line1237">1237: </a>  <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(emax * emin &gt; 0.0, <a href="../../../../../manualpages/Sys/PetscObjectComm.html">PetscObjectComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc), <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_ARG_INCOMP</a>, <font color="#666666">"Both eigenvalues must be of the same sign: max %g min %g"</font>, (double)emax, (double)emin);
<a name="line1238">1238: </a>  pc_gamg-&gt;emax = emax;
<a name="line1239">1239: </a>  pc_gamg-&gt;emin = emin;
<a name="line1240">1240: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1241">1241: </a>}

<a name="line1243">1243: </a><font color="#B22222">/*@</font>
<a name="line1244">1244: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetReuseInterpolation.html">PCGAMGSetReuseInterpolation</a> - Reuse prolongation when rebuilding a `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` algebraic multigrid preconditioner</font>

<a name="line1246">1246: </a><font color="#B22222">  Collective</font>

<a name="line1248">1248: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1249">1249: </a><font color="#B22222">+ pc - the preconditioner context</font>
<a name="line1250">1250: </a><font color="#B22222">- n  - `<a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>` or `<a href="../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>`</font>

<a name="line1252">1252: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1253">1253: </a><font color="#B22222">. -pc_gamg_reuse_interpolation &lt;true,false&gt; - reuse the previous interpolation</font>

<a name="line1255">1255: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1257">1257: </a><font color="#B22222">  Note:</font>
<a name="line1258">1258: </a><font color="#B22222">  May negatively affect the convergence rate of the method on new matrices if the matrix entries change a great deal, but allows</font>
<a name="line1259">1259: </a><font color="#B22222">  rebuilding the preconditioner quicker.</font>

<a name="line1261">1261: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`</font>
<a name="line1262">1262: </a><font color="#B22222">@*/</font>
<a name="line1263">1263: </a><strong><font color="#4169E1"><a name="PCGAMGSetReuseInterpolation"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetReuseInterpolation.html">PCGAMGSetReuseInterpolation</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> n)</font></strong>
<a name="line1264">1264: </a>{
<a name="line1265">1265: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1267">1267: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetReuseInterpolation_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a>), (pc, n));
<a name="line1268">1268: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1269">1269: </a>}

<a name="line1271">1271: </a><strong><font color="#4169E1"><a name="PCGAMGSetReuseInterpolation_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetReuseInterpolation_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> n)</font></strong>
<a name="line1272">1272: </a>{
<a name="line1273">1273: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1274">1274: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1276">1276: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1277">1277: </a>  pc_gamg-&gt;reuse_prol = n;
<a name="line1278">1278: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1279">1279: </a>}

<a name="line1281">1281: </a><font color="#B22222">/*@</font>
<a name="line1282">1282: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGASMSetUseAggs.html">PCGAMGASMSetUseAggs</a> - Have the `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` smoother on each level use `<a href="../../../../../manualpages/PC/PCASM.html">PCASM</a>` where the aggregates defined by the coarsening process are</font>
<a name="line1283">1283: </a><font color="#B22222">  the subdomains for the additive Schwarz preconditioner used as the smoother</font>

<a name="line1285">1285: </a><font color="#B22222">  Collective</font>

<a name="line1287">1287: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1288">1288: </a><font color="#B22222">+ pc  - the preconditioner context</font>
<a name="line1289">1289: </a><font color="#B22222">- flg - `<a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>` to use aggregates, `<a href="../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>` to not</font>

<a name="line1291">1291: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1292">1292: </a><font color="#B22222">. -pc_gamg_asm_use_agg &lt;true,false&gt; - use aggregates to define the additive Schwarz subdomains</font>

<a name="line1294">1294: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1296">1296: </a><font color="#B22222">  Note:</font>
<a name="line1297">1297: </a><font color="#B22222">  This option automatically sets the preconditioner on the levels to be `<a href="../../../../../manualpages/PC/PCASM.html">PCASM</a>`.</font>

<a name="line1299">1299: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCASM.html">PCASM</a>`, `<a href="../../../../../manualpages/PC/PCSetType.html">PCSetType</a>`</font>
<a name="line1300">1300: </a><font color="#B22222">@*/</font>
<a name="line1301">1301: </a><strong><font color="#4169E1"><a name="PCGAMGASMSetUseAggs"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGASMSetUseAggs.html">PCGAMGASMSetUseAggs</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> flg)</font></strong>
<a name="line1302">1302: </a>{
<a name="line1303">1303: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1305">1305: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGASMSetUseAggs_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a>), (pc, flg));
<a name="line1306">1306: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1307">1307: </a>}

<a name="line1309">1309: </a><strong><font color="#4169E1"><a name="PCGAMGASMSetUseAggs_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGASMSetUseAggs_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> flg)</font></strong>
<a name="line1310">1310: </a>{
<a name="line1311">1311: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1312">1312: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1314">1314: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1315">1315: </a>  pc_gamg-&gt;use_aggs_in_asm = flg;
<a name="line1316">1316: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1317">1317: </a>}

<a name="line1319">1319: </a><font color="#B22222">/*@</font>
<a name="line1320">1320: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetParallelCoarseGridSolve.html">PCGAMGSetParallelCoarseGridSolve</a> - allow a parallel coarse grid solver</font>

<a name="line1322">1322: </a><font color="#B22222">  Collective</font>

<a name="line1324">1324: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1325">1325: </a><font color="#B22222">+ pc  - the preconditioner context</font>
<a name="line1326">1326: </a><font color="#B22222">- flg - `<a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>` to not force coarse grid onto one processor</font>

<a name="line1328">1328: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1329">1329: </a><font color="#B22222">. -pc_gamg_parallel_coarse_grid_solver - use a parallel coarse grid solver</font>

<a name="line1331">1331: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1333">1333: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetCoarseGridLayoutType.html">PCGAMGSetCoarseGridLayoutType</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetCpuPinCoarseGrids.html">PCGAMGSetCpuPinCoarseGrids</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetRankReductionFactors.html">PCGAMGSetRankReductionFactors</a>()`</font>
<a name="line1334">1334: </a><font color="#B22222">@*/</font>
<a name="line1335">1335: </a><strong><font color="#4169E1"><a name="PCGAMGSetParallelCoarseGridSolve"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetParallelCoarseGridSolve.html">PCGAMGSetParallelCoarseGridSolve</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> flg)</font></strong>
<a name="line1336">1336: </a>{
<a name="line1337">1337: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1339">1339: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetParallelCoarseGridSolve_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a>), (pc, flg));
<a name="line1340">1340: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1341">1341: </a>}

<a name="line1343">1343: </a><strong><font color="#4169E1"><a name="PCGAMGSetParallelCoarseGridSolve_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetParallelCoarseGridSolve_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> flg)</font></strong>
<a name="line1344">1344: </a>{
<a name="line1345">1345: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1346">1346: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1348">1348: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1349">1349: </a>  pc_gamg-&gt;use_parallel_coarse_grid_solver = flg;
<a name="line1350">1350: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1351">1351: </a>}

<a name="line1353">1353: </a><font color="#B22222">/*@</font>
<a name="line1354">1354: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetCpuPinCoarseGrids.html">PCGAMGSetCpuPinCoarseGrids</a> - pin the coarse grids created in `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` to run only on the CPU since the problems may be too small to run efficiently on the GPUs</font>

<a name="line1356">1356: </a><font color="#B22222">  Collective</font>

<a name="line1358">1358: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1359">1359: </a><font color="#B22222">+ pc  - the preconditioner context</font>
<a name="line1360">1360: </a><font color="#B22222">- flg - `<a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>` to pin coarse grids to the CPU</font>

<a name="line1362">1362: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1363">1363: </a><font color="#B22222">. -pc_gamg_cpu_pin_coarse_grids - pin the coarse grids to the CPU</font>

<a name="line1365">1365: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1367">1367: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetCoarseGridLayoutType.html">PCGAMGSetCoarseGridLayoutType</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetParallelCoarseGridSolve.html">PCGAMGSetParallelCoarseGridSolve</a>()`</font>
<a name="line1368">1368: </a><font color="#B22222">@*/</font>
<a name="line1369">1369: </a><strong><font color="#4169E1"><a name="PCGAMGSetCpuPinCoarseGrids"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetCpuPinCoarseGrids.html">PCGAMGSetCpuPinCoarseGrids</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> flg)</font></strong>
<a name="line1370">1370: </a>{
<a name="line1371">1371: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1373">1373: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetCpuPinCoarseGrids_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a>), (pc, flg));
<a name="line1374">1374: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1375">1375: </a>}

<a name="line1377">1377: </a><strong><font color="#4169E1"><a name="PCGAMGSetCpuPinCoarseGrids_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetCpuPinCoarseGrids_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> flg)</font></strong>
<a name="line1378">1378: </a>{
<a name="line1379">1379: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1380">1380: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1382">1382: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1383">1383: </a>  pc_gamg-&gt;cpu_pin_coarse_grids = flg;
<a name="line1384">1384: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1385">1385: </a>}

<a name="line1387">1387: </a><font color="#B22222">/*@</font>
<a name="line1388">1388: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetCoarseGridLayoutType.html">PCGAMGSetCoarseGridLayoutType</a> - place coarse grids on processors with natural order (compact type)</font>

<a name="line1390">1390: </a><font color="#B22222">  Collective</font>

<a name="line1392">1392: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1393">1393: </a><font color="#B22222">+ pc  - the preconditioner context</font>
<a name="line1394">1394: </a><font color="#B22222">- flg - `<a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMGLayoutType</a>` type, either `<a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMG_LAYOUT_COMPACT</a>` or `<a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMG_LAYOUT_SPREAD</a>`</font>

<a name="line1396">1396: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1397">1397: </a><font color="#B22222">. -pc_gamg_coarse_grid_layout_type - place the coarse grids with natural ordering</font>

<a name="line1399">1399: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1401">1401: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetParallelCoarseGridSolve.html">PCGAMGSetParallelCoarseGridSolve</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetCpuPinCoarseGrids.html">PCGAMGSetCpuPinCoarseGrids</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMGLayoutType</a>`, `<a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMG_LAYOUT_COMPACT</a>`, `<a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMG_LAYOUT_SPREAD</a>`</font>
<a name="line1402">1402: </a><font color="#B22222">@*/</font>
<a name="line1403">1403: </a><strong><font color="#4169E1"><a name="PCGAMGSetCoarseGridLayoutType"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetCoarseGridLayoutType.html">PCGAMGSetCoarseGridLayoutType</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMGLayoutType</a> flg)</font></strong>
<a name="line1404">1404: </a>{
<a name="line1405">1405: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1407">1407: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetCoarseGridLayoutType_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMGLayoutType</a>), (pc, flg));
<a name="line1408">1408: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1409">1409: </a>}

<a name="line1411">1411: </a><strong><font color="#4169E1"><a name="PCGAMGSetCoarseGridLayoutType_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetCoarseGridLayoutType_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMGLayoutType</a> flg)</font></strong>
<a name="line1412">1412: </a>{
<a name="line1413">1413: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1414">1414: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1416">1416: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1417">1417: </a>  pc_gamg-&gt;layout_type = flg;
<a name="line1418">1418: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1419">1419: </a>}

<a name="line1421">1421: </a><font color="#B22222">/*@</font>
<a name="line1422">1422: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetNlevels.html">PCGAMGSetNlevels</a> -  Sets the maximum number of levels `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` will use</font>

<a name="line1424">1424: </a><font color="#B22222">  Collective</font>

<a name="line1426">1426: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1427">1427: </a><font color="#B22222">+ pc - the preconditioner</font>
<a name="line1428">1428: </a><font color="#B22222">- n  - the maximum number of levels to use</font>

<a name="line1430">1430: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1431">1431: </a><font color="#B22222">. -pc_mg_levels &lt;n&gt; - set the maximum number of levels to allow</font>

<a name="line1433">1433: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1435">1435: </a><font color="#B22222">  Developer Notes:</font>
<a name="line1436">1436: </a><font color="#B22222">  Should be called `PCGAMGSetMaximumNumberlevels()` and possible be shared with `<a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>`</font>

<a name="line1438">1438: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`</font>
<a name="line1439">1439: </a><font color="#B22222">@*/</font>
<a name="line1440">1440: </a><strong><font color="#4169E1"><a name="PCGAMGSetNlevels"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetNlevels.html">PCGAMGSetNlevels</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n)</font></strong>
<a name="line1441">1441: </a>{
<a name="line1442">1442: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1444">1444: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetNlevels_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>), (pc, n));
<a name="line1445">1445: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1446">1446: </a>}

<a name="line1448">1448: </a><strong><font color="#4169E1"><a name="PCGAMGSetNlevels_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetNlevels_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n)</font></strong>
<a name="line1449">1449: </a>{
<a name="line1450">1450: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1451">1451: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1453">1453: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1454">1454: </a>  pc_gamg-&gt;Nlevels = n;
<a name="line1455">1455: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1456">1456: </a>}

<a name="line1458">1458: </a><font color="#B22222">/*@</font>
<a name="line1459">1459: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGASMSetHEM.html">PCGAMGASMSetHEM</a> -  Sets the number of HEM matching passed</font>

<a name="line1461">1461: </a><font color="#B22222">  Collective</font>

<a name="line1463">1463: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1464">1464: </a><font color="#B22222">+ pc - the preconditioner</font>
<a name="line1465">1465: </a><font color="#B22222">- n  - number of HEM matching passed to construct ASM subdomains</font>

<a name="line1467">1467: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1468">1468: </a><font color="#B22222">. -pc_gamg_asm_hem &lt;n&gt; - set the number of HEM matching passed</font>

<a name="line1470">1470: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1472">1472: </a><font color="#B22222">  Developer Notes:</font>
<a name="line1473">1473: </a><font color="#B22222">  Should be called `PCGAMGSetMaximumNumberlevels()` and possible be shared with `<a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>`</font>

<a name="line1475">1475: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`</font>
<a name="line1476">1476: </a><font color="#B22222">@*/</font>
<a name="line1477">1477: </a><strong><font color="#4169E1"><a name="PCGAMGASMSetHEM"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGASMSetHEM.html">PCGAMGASMSetHEM</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n)</font></strong>
<a name="line1478">1478: </a>{
<a name="line1479">1479: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1481">1481: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGASMSetHEM_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>), (pc, n));
<a name="line1482">1482: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1483">1483: </a>}

<a name="line1485">1485: </a><strong><font color="#4169E1"><a name="PCGAMGASMSetHEM_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGASMSetHEM_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n)</font></strong>
<a name="line1486">1486: </a>{
<a name="line1487">1487: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1488">1488: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1490">1490: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1491">1491: </a>  pc_gamg-&gt;asm_hem_aggs = n;
<a name="line1492">1492: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1493">1493: </a>}

<a name="line1495">1495: </a><font color="#B22222">/*@</font>
<a name="line1496">1496: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetThreshold.html">PCGAMGSetThreshold</a> - Relative threshold to use for dropping edges in aggregation graph</font>

<a name="line1498">1498: </a><font color="#B22222">  Not Collective</font>

<a name="line1500">1500: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1501">1501: </a><font color="#B22222">+ pc - the preconditioner context</font>
<a name="line1502">1502: </a><font color="#B22222">. v  - array of threshold values for finest n levels; 0.0 means keep all nonzero entries in the graph; negative means keep even zero entries in the graph</font>
<a name="line1503">1503: </a><font color="#B22222">- n  - number of threshold values provided in array</font>

<a name="line1505">1505: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1506">1506: </a><font color="#B22222">. -pc_gamg_threshold &lt;threshold&gt; - the threshold to drop edges</font>

<a name="line1508">1508: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1510">1510: </a><font color="#B22222">  Notes:</font>
<a name="line1511">1511: </a><font color="#B22222">  Increasing the threshold decreases the rate of coarsening. Conversely reducing the threshold increases the rate of coarsening (aggressive coarsening) and thereby reduces the complexity of the coarse grids, and generally results in slower solver converge rates. Reducing coarse grid complexity reduced the complexity of Galerkin coarse grid construction considerably.</font>
<a name="line1512">1512: </a><font color="#B22222">  Before coarsening or aggregating the graph, `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` removes small values from the graph with this threshold, and thus reducing the coupling in the graph and a different (perhaps better) coarser set of points.</font>

<a name="line1514">1514: </a><font color="#B22222">  If `n` is less than the total number of coarsenings (see `<a href="../../../../../manualpages/PC/PCGAMGSetNlevels.html">PCGAMGSetNlevels</a>()`), then threshold scaling (see `<a href="../../../../../manualpages/PC/PCGAMGSetThresholdScale.html">PCGAMGSetThresholdScale</a>()`) is used for each successive coarsening.</font>
<a name="line1515">1515: </a><font color="#B22222">  In this case, `<a href="../../../../../manualpages/PC/PCGAMGSetThresholdScale.html">PCGAMGSetThresholdScale</a>()` must be called before `<a href="../../../../../manualpages/PC/PCGAMGSetThreshold.html">PCGAMGSetThreshold</a>()`.</font>
<a name="line1516">1516: </a><font color="#B22222">  If `n` is greater than the total number of levels, the excess entries in threshold will not be used.</font>

<a name="line1518">1518: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetAggressiveLevels.html">PCGAMGSetAggressiveLevels</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGMISkSetAggressive.html">PCGAMGMISkSetAggressive</a>()`, `PCGAMGSetMinDegreeOrderingMISk()`, `<a href="../../../../../manualpages/PC/PCGAMGSetThresholdScale.html">PCGAMGSetThresholdScale</a>()`</font>
<a name="line1519">1519: </a><font color="#B22222">@*/</font>
<a name="line1520">1520: </a><strong><font color="#4169E1"><a name="PCGAMGSetThreshold"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetThreshold.html">PCGAMGSetThreshold</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> v[], <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n)</font></strong>
<a name="line1521">1521: </a>{
<a name="line1522">1522: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1524">1524: </a>  <font color="#4169E1">if</font> (n) PetscAssertPointer(v, 2);
<a name="line1525">1525: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetThreshold_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a>[], <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>), (pc, v, n));
<a name="line1526">1526: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1527">1527: </a>}

<a name="line1529">1529: </a><strong><font color="#4169E1"><a name="PCGAMGSetThreshold_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetThreshold_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> v[], <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n)</font></strong>
<a name="line1530">1530: </a>{
<a name="line1531">1531: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1532">1532: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;
<a name="line1533">1533: </a>  <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> i;

<a name="line1535">1535: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1536">1536: </a>  <font color="#4169E1">for</font> (i = 0; i &lt; <a href="../../../../../manualpages/Sys/PetscMin.html">PetscMin</a>(n, PETSC_MG_MAXLEVELS); i++) pc_gamg-&gt;threshold[i] = v[i];
<a name="line1537">1537: </a>  <font color="#4169E1">for</font> (; i &lt; PETSC_MG_MAXLEVELS; i++) pc_gamg-&gt;threshold[i] = pc_gamg-&gt;threshold[i - 1] * pc_gamg-&gt;threshold_scale;
<a name="line1538">1538: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1539">1539: </a>}

<a name="line1541">1541: </a><font color="#B22222">/*@</font>
<a name="line1542">1542: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetRankReductionFactors.html">PCGAMGSetRankReductionFactors</a> - Set a manual schedule for MPI rank reduction on coarse grids</font>

<a name="line1544">1544: </a><font color="#B22222">  Collective</font>

<a name="line1546">1546: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1547">1547: </a><font color="#B22222">+ pc - the preconditioner context</font>
<a name="line1548">1548: </a><font color="#B22222">. v  - array of reduction factors. 0 for first value forces a reduction to one process/device on first level in CUDA</font>
<a name="line1549">1549: </a><font color="#B22222">- n  - number of values provided in array</font>

<a name="line1551">1551: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1552">1552: </a><font color="#B22222">. -pc_gamg_rank_reduction_factors &lt;factors&gt; - provide the schedule</font>

<a name="line1554">1554: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1556">1556: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetProcEqLim.html">PCGAMGSetProcEqLim</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetCoarseEqLim.html">PCGAMGSetCoarseEqLim</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetParallelCoarseGridSolve.html">PCGAMGSetParallelCoarseGridSolve</a>()`</font>
<a name="line1557">1557: </a><font color="#B22222">@*/</font>
<a name="line1558">1558: </a><strong><font color="#4169E1"><a name="PCGAMGSetRankReductionFactors"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetRankReductionFactors.html">PCGAMGSetRankReductionFactors</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> v[], <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n)</font></strong>
<a name="line1559">1559: </a>{
<a name="line1560">1560: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1562">1562: </a>  <font color="#4169E1">if</font> (n) PetscAssertPointer(v, 2);
<a name="line1563">1563: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetRankReductionFactors_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>[], <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>), (pc, v, n));
<a name="line1564">1564: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1565">1565: </a>}

<a name="line1567">1567: </a><strong><font color="#4169E1"><a name="PCGAMGSetRankReductionFactors_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetRankReductionFactors_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> v[], <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n)</font></strong>
<a name="line1568">1568: </a>{
<a name="line1569">1569: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1570">1570: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;
<a name="line1571">1571: </a>  <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> i;

<a name="line1573">1573: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1574">1574: </a>  <font color="#4169E1">for</font> (i = 0; i &lt; <a href="../../../../../manualpages/Sys/PetscMin.html">PetscMin</a>(n, PETSC_MG_MAXLEVELS); i++) pc_gamg-&gt;level_reduction_factors[i] = v[i];
<a name="line1575">1575: </a>  <font color="#4169E1">for</font> (; i &lt; PETSC_MG_MAXLEVELS; i++) pc_gamg-&gt;level_reduction_factors[i] = -1; <font color="#B22222">/* 0 stop putting one process/device on first level */</font>
<a name="line1576">1576: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1577">1577: </a>}

<a name="line1579">1579: </a><font color="#B22222">/*@</font>
<a name="line1580">1580: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetThresholdScale.html">PCGAMGSetThresholdScale</a> - Relative threshold reduction at each level</font>

<a name="line1582">1582: </a><font color="#B22222">  Not Collective</font>

<a name="line1584">1584: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1585">1585: </a><font color="#B22222">+ pc - the preconditioner context</font>
<a name="line1586">1586: </a><font color="#B22222">- v  - the threshold value reduction, usually &lt; 1.0</font>

<a name="line1588">1588: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1589">1589: </a><font color="#B22222">. -pc_gamg_threshold_scale &lt;v&gt; - set the relative threshold reduction on each level</font>

<a name="line1591">1591: </a><font color="#B22222">  Level: advanced</font>

<a name="line1593">1593: </a><font color="#B22222">  Note:</font>
<a name="line1594">1594: </a><font color="#B22222">  The initial threshold (for an arbitrary number of levels starting from the finest) can be set with `<a href="../../../../../manualpages/PC/PCGAMGSetThreshold.html">PCGAMGSetThreshold</a>()`.</font>
<a name="line1595">1595: </a><font color="#B22222">  This scaling is used for each subsequent coarsening, but must be called before `<a href="../../../../../manualpages/PC/PCGAMGSetThreshold.html">PCGAMGSetThreshold</a>()`.</font>

<a name="line1597">1597: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetThreshold.html">PCGAMGSetThreshold</a>()`</font>
<a name="line1598">1598: </a><font color="#B22222">@*/</font>
<a name="line1599">1599: </a><strong><font color="#4169E1"><a name="PCGAMGSetThresholdScale"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetThresholdScale.html">PCGAMGSetThresholdScale</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> v)</font></strong>
<a name="line1600">1600: </a>{
<a name="line1601">1601: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1603">1603: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetThresholdScale_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a>), (pc, v));
<a name="line1604">1604: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1605">1605: </a>}

<a name="line1607">1607: </a><strong><font color="#4169E1"><a name="PCGAMGSetThresholdScale_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetThresholdScale_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> v)</font></strong>
<a name="line1608">1608: </a>{
<a name="line1609">1609: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1610">1610: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1612">1612: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1613">1613: </a>  pc_gamg-&gt;threshold_scale = v;
<a name="line1614">1614: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1615">1615: </a>}

<a name="line1617">1617: </a><font color="#B22222">/*@</font>
<a name="line1618">1618: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetType.html">PCGAMGSetType</a> - Set the type of algorithm `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` should use</font>

<a name="line1620">1620: </a><font color="#B22222">  Collective</font>

<a name="line1622">1622: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1623">1623: </a><font color="#B22222">+ pc   - the preconditioner context</font>
<a name="line1624">1624: </a><font color="#B22222">- type - `<a href="../../../../../manualpages/PC/PCGAMGAGG.html">PCGAMGAGG</a>`, `PCGAMGGEO`, or `PCGAMGCLASSICAL`</font>

<a name="line1626">1626: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1627">1627: </a><font color="#B22222">. -pc_gamg_type &lt;agg,geo,classical&gt; - type of algebraic multigrid to apply - only agg is supported</font>

<a name="line1629">1629: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1631">1631: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMGGetType.html">PCGAMGGetType</a>()`, `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGType.html">PCGAMGType</a>`</font>
<a name="line1632">1632: </a><font color="#B22222">@*/</font>
<a name="line1633">1633: </a><strong><font color="#4169E1"><a name="PCGAMGSetType"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetType.html">PCGAMGSetType</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/PC/PCGAMGType.html">PCGAMGType</a> type)</font></strong>
<a name="line1634">1634: </a>{
<a name="line1635">1635: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1637">1637: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetType_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/PC/PCGAMGType.html">PCGAMGType</a>), (pc, type));
<a name="line1638">1638: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1639">1639: </a>}

<a name="line1641">1641: </a><font color="#B22222">/*@</font>
<a name="line1642">1642: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGGetType.html">PCGAMGGetType</a> - Get the type of algorithm `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` will use</font>

<a name="line1644">1644: </a><font color="#B22222">  Collective</font>

<a name="line1646">1646: </a><font color="#B22222">  Input Parameter:</font>
<a name="line1647">1647: </a><font color="#B22222">. pc - the preconditioner context</font>

<a name="line1649">1649: </a><font color="#B22222">  Output Parameter:</font>
<a name="line1650">1650: </a><font color="#B22222">. type - the type of algorithm used</font>

<a name="line1652">1652: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1654">1654: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetType.html">PCGAMGSetType</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGType.html">PCGAMGType</a>`</font>
<a name="line1655">1655: </a><font color="#B22222">@*/</font>
<a name="line1656">1656: </a><strong><font color="#4169E1"><a name="PCGAMGGetType"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGGetType.html">PCGAMGGetType</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/PC/PCGAMGType.html">PCGAMGType</a> *type)</font></strong>
<a name="line1657">1657: </a>{
<a name="line1658">1658: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1660">1660: </a>  <a href="../../../../../manualpages/Sys/PetscUseMethod.html">PetscUseMethod</a>(pc, <font color="#666666">"PCGAMGGetType_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/PC/PCGAMGType.html">PCGAMGType</a> *), (pc, type));
<a name="line1661">1661: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1662">1662: </a>}

<a name="line1664">1664: </a><strong><font color="#4169E1"><a name="PCGAMGGetType_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGGetType_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/PC/PCGAMGType.html">PCGAMGType</a> *type)</font></strong>
<a name="line1665">1665: </a>{
<a name="line1666">1666: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1667">1667: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1669">1669: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1670">1670: </a>  *type = pc_gamg-&gt;type;
<a name="line1671">1671: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1672">1672: </a>}

<a name="line1674">1674: </a><strong><font color="#4169E1"><a name="PCGAMGSetType_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetType_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/PC/PCGAMGType.html">PCGAMGType</a> type)</font></strong>
<a name="line1675">1675: </a>{
<a name="line1676">1676: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1677">1677: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;
<a name="line1678">1678: </a>  <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> (*r)(<a href="../../../../../manualpages/PC/PC.html">PC</a>);

<a name="line1680">1680: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1681">1681: </a>  pc_gamg-&gt;type = type;
<a name="line1682">1682: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFunctionListFind.html">PetscFunctionListFind</a>(GAMGList, type, &amp;r));
<a name="line1683">1683: </a>  <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(r, <a href="../../../../../manualpages/Sys/PetscObjectComm.html">PetscObjectComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc), <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_ARG_UNKNOWN_TYPE</a>, <font color="#666666">"Unknown GAMG type %s given"</font>, type);
<a name="line1684">1684: </a>  <font color="#4169E1">if</font> (pc_gamg-&gt;ops-&gt;destroy) {
<a name="line1685">1685: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>((*pc_gamg-&gt;ops-&gt;destroy)(pc));
<a name="line1686">1686: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscMemzero.html">PetscMemzero</a>(pc_gamg-&gt;ops, <font color="#4169E1">sizeof</font>(<font color="#4169E1">struct _PCGAMGOps</font>)));
<a name="line1687">1687: </a>    pc_gamg-&gt;ops-&gt;createlevel = PCGAMGCreateLevel_GAMG;
<a name="line1688">1688: </a>    <font color="#B22222">/* cleaning up common data in pc_gamg - this should disappear someday */</font>
<a name="line1689">1689: </a>    pc_gamg-&gt;data_cell_cols      = 0;
<a name="line1690">1690: </a>    pc_gamg-&gt;data_cell_rows      = 0;
<a name="line1691">1691: </a>    pc_gamg-&gt;orig_data_cell_cols = 0;
<a name="line1692">1692: </a>    pc_gamg-&gt;orig_data_cell_rows = 0;
<a name="line1693">1693: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(pc_gamg-&gt;data));
<a name="line1694">1694: </a>    pc_gamg-&gt;data_sz = 0;
<a name="line1695">1695: </a>  }
<a name="line1696">1696: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(pc_gamg-&gt;gamg_type_name));
<a name="line1697">1697: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscStrallocpy.html">PetscStrallocpy</a>(type, &amp;pc_gamg-&gt;gamg_type_name));
<a name="line1698">1698: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>((*r)(pc));
<a name="line1699">1699: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1700">1700: </a>}

<a name="line1702">1702: </a><strong><font color="#4169E1"><a name="PCView_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCView_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Viewer/PetscViewer.html">PetscViewer</a> viewer)</font></strong>
<a name="line1703">1703: </a>{
<a name="line1704">1704: </a>  PC_MG         *mg       = (PC_MG *)pc-&gt;data;
<a name="line1705">1705: </a>  PC_MG_Levels **mglevels = mg-&gt;levels;
<a name="line1706">1706: </a>  PC_GAMG       *pc_gamg  = (PC_GAMG *)mg-&gt;innerctx;
<a name="line1707">1707: </a>  <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a>      gc, oc;

<a name="line1709">1709: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1710">1710: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"    GAMG specific options\n"</font>));
<a name="line1711">1711: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"      Threshold for dropping small values in graph on each level ="</font>));
<a name="line1712">1712: </a>  <font color="#4169E1">for</font> (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> i = 0; i &lt; mg-&gt;nlevels; i++) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">" %g"</font>, (double)pc_gamg-&gt;threshold[i]));
<a name="line1713">1713: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"\n"</font>));
<a name="line1714">1714: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"      Threshold scaling factor for each level not specified = %g\n"</font>, (double)pc_gamg-&gt;threshold_scale));
<a name="line1715">1715: </a>  <font color="#4169E1">if</font> (pc_gamg-&gt;use_aggs_in_asm) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"      Using aggregates from GAMG coarsening process to define subdomains for <a href="../../../../../manualpages/PC/PCASM.html">PCASM</a>\n"</font>)); <font color="#B22222">// this take presedence</font>
<a name="line1716">1716: </a>  <font color="#4169E1">else</font> <font color="#4169E1">if</font> (pc_gamg-&gt;asm_hem_aggs) {
<a name="line1717">1717: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"      Using aggregates made with %"</font> PetscInt_FMT <font color="#666666">" applications of heavy edge matching (HEM) to define subdomains for <a href="../../../../../manualpages/PC/PCASM.html">PCASM</a>\n"</font>, pc_gamg-&gt;asm_hem_aggs));
<a name="line1718">1718: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPushTab.html">PetscViewerASCIIPushTab</a>(viewer));
<a name="line1719">1719: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPushTab.html">PetscViewerASCIIPushTab</a>(viewer));
<a name="line1720">1720: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPushTab.html">PetscViewerASCIIPushTab</a>(viewer));
<a name="line1721">1721: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPushTab.html">PetscViewerASCIIPushTab</a>(viewer));
<a name="line1722">1722: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/MatGraphOperations/MatCoarsenView.html">MatCoarsenView</a>(pc_gamg-&gt;asm_crs, viewer));
<a name="line1723">1723: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPopTab.html">PetscViewerASCIIPopTab</a>(viewer));
<a name="line1724">1724: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPopTab.html">PetscViewerASCIIPopTab</a>(viewer));
<a name="line1725">1725: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPopTab.html">PetscViewerASCIIPopTab</a>(viewer));
<a name="line1726">1726: </a>  }
<a name="line1727">1727: </a>  <font color="#4169E1">if</font> (pc_gamg-&gt;use_parallel_coarse_grid_solver) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"      Using parallel coarse grid solver (all coarse grid equations not put on one process)\n"</font>));
<a name="line1728">1728: </a>  <font color="#4169E1">if</font> (pc_gamg-&gt;injection_index_size) {
<a name="line1729">1729: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"      Using injection restriction/prolongation on first level, dofs:"</font>));
<a name="line1730">1730: </a>    <font color="#4169E1">for</font> (int i = 0; i &lt; pc_gamg-&gt;injection_index_size; i++) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">" %"</font> PetscInt_FMT, pc_gamg-&gt;injection_index[i]));
<a name="line1731">1731: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"\n"</font>));
<a name="line1732">1732: </a>  }
<a name="line1733">1733: </a>  <font color="#4169E1">if</font> (pc_gamg-&gt;ops-&gt;view) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>((*pc_gamg-&gt;ops-&gt;view)(pc, viewer));
<a name="line1734">1734: </a>  gc = oc = 0;
<a name="line1735">1735: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCMGGetGridComplexity.html">PCMGGetGridComplexity</a>(pc, &amp;gc, &amp;oc));
<a name="line1736">1736: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"      Complexity:    grid = %g    operator = %g\n"</font>, (double)gc, (double)oc));
<a name="line1737">1737: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"      Per-level complexity: op = operator, int = interpolation\n"</font>));
<a name="line1738">1738: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"          #equations  | #active PEs | avg nnz/row op | avg nnz/row int\n"</font>));
<a name="line1739">1739: </a>  <font color="#4169E1">for</font> (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> i = 0; i &lt; mg-&gt;nlevels; i++) {
<a name="line1740">1740: </a>    <a href="../../../../../manualpages/Mat/MatInfo.html">MatInfo</a>   info;
<a name="line1741">1741: </a>    <a href="../../../../../manualpages/Mat/Mat.html">Mat</a>       A;
<a name="line1742">1742: </a>    <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> rd[3];
<a name="line1743">1743: </a>    <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>  rst, ren, N;

<a name="line1745">1745: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/KSP/KSPGetOperators.html">KSPGetOperators</a>(mglevels[i]-&gt;smoothd, NULL, &amp;A));
<a name="line1746">1746: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetOwnershipRange.html">MatGetOwnershipRange</a>(A, &amp;rst, &amp;ren));
<a name="line1747">1747: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetSize.html">MatGetSize</a>(A, &amp;N, NULL));
<a name="line1748">1748: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetInfo.html">MatGetInfo</a>(A, <a href="../../../../../manualpages/Mat/MatInfoType.html">MAT_LOCAL</a>, &amp;info));
<a name="line1749">1749: </a>    rd[0] = (ren - rst &gt; 0) ? 1 : 0;
<a name="line1750">1750: </a>    rd[1] = info.nz_used;
<a name="line1751">1751: </a>    rd[2] = 0;
<a name="line1752">1752: </a>    <font color="#4169E1">if</font> (i) {
<a name="line1753">1753: </a>      <a href="../../../../../manualpages/Mat/Mat.html">Mat</a> P;
<a name="line1754">1754: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCMGGetInterpolation.html">PCMGGetInterpolation</a>(pc, i, &amp;P));
<a name="line1755">1755: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Mat/MatGetInfo.html">MatGetInfo</a>(P, <a href="../../../../../manualpages/Mat/MatInfoType.html">MAT_LOCAL</a>, &amp;info));
<a name="line1756">1756: </a>      rd[2] = info.nz_used;
<a name="line1757">1757: </a>    }
<a name="line1758">1758: </a>    <a href="../../../../../manualpages/Sys/PetscCallMPI.html">PetscCallMPI</a>(<a href="../../../../../manualpages/Sys/MPIU_Allreduce.html">MPIU_Allreduce</a>(MPI_IN_PLACE, rd, 3, <a href="../../../../../manualpages/Sys/MPIU_REAL.html">MPIU_REAL</a>, MPIU_SUM, <a href="../../../../../manualpages/Sys/PetscObjectComm.html">PetscObjectComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)));
<a name="line1759">1759: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Viewer/PetscViewerASCIIPrintf.html">PetscViewerASCIIPrintf</a>(viewer, <font color="#666666">"     %12"</font> PetscInt_FMT <font color="#666666">" %12"</font> PetscInt_FMT <font color="#666666">"   %12"</font> PetscInt_FMT <font color="#666666">"     %12"</font> PetscInt_FMT <font color="#666666">"\n"</font>, N, (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>)rd[0], (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>)PetscCeilReal(rd[1] / N), (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>)PetscCeilReal(rd[2] / N)));
<a name="line1760">1760: </a>  }
<a name="line1761">1761: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1762">1762: </a>}

<a name="line1764">1764: </a><font color="#B22222">/*@</font>
<a name="line1765">1765: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGSetInjectionIndex.html">PCGAMGSetInjectionIndex</a> - Array of subset of variables per vertex to inject into coarse grid space</font>

<a name="line1767">1767: </a><font color="#B22222">  Logically Collective</font>

<a name="line1769">1769: </a><font color="#B22222">  Input Parameters:</font>
<a name="line1770">1770: </a><font color="#B22222">+ pc  - the coarsen context</font>
<a name="line1771">1771: </a><font color="#B22222">. n   - number of indices</font>
<a name="line1772">1772: </a><font color="#B22222">- idx - array of indices</font>

<a name="line1774">1774: </a><font color="#B22222">  Options Database Key:</font>
<a name="line1775">1775: </a><font color="#B22222">. -pc_gamg_injection_index - array of subset of variables per vertex to use for injection coarse grid space</font>

<a name="line1777">1777: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1779">1779: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`</font>
<a name="line1780">1780: </a><font color="#B22222">@*/</font>
<a name="line1781">1781: </a><strong><font color="#4169E1"><a name="PCGAMGSetInjectionIndex"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGSetInjectionIndex.html">PCGAMGSetInjectionIndex</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> idx[])</font></strong>
<a name="line1782">1782: </a>{
<a name="line1783">1783: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1786">1786: </a>  <a href="../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCGAMGSetInjectionIndex_C"</font>, (<a href="../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>[]), (pc, n, idx));
<a name="line1787">1787: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1788">1788: </a>}

<a name="line1790">1790: </a><strong><font color="#4169E1"><a name="PCGAMGSetInjectionIndex_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCGAMGSetInjectionIndex_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> n, <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> idx[])</font></strong>
<a name="line1791">1791: </a>{
<a name="line1792">1792: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line1793">1793: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line1795">1795: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1796">1796: </a>  pc_gamg-&gt;injection_index_size = n;
<a name="line1797">1797: </a>  <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(n &lt; MAT_COARSEN_STRENGTH_INDEX_SIZE, <a href="../../../../../manualpages/Sys/PetscObjectComm.html">PetscObjectComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc), <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_ARG_INCOMP</a>, <font color="#666666">"array size %"</font> PetscInt_FMT <font color="#666666">" larger than max %d"</font>, n, MAT_COARSEN_STRENGTH_INDEX_SIZE);
<a name="line1798">1798: </a>  <font color="#4169E1">for</font> (<a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> i = 0; i &lt; n; i++) pc_gamg-&gt;injection_index[i] = idx[i];
<a name="line1799">1799: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1800">1800: </a>}

<a name="line1802">1802: </a><strong><font color="#4169E1"><a name="PCSetFromOptions_GAMG"></a>static <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCSetFromOptions_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, PetscOptionItems PetscOptionsObject)</font></strong>
<a name="line1803">1803: </a>{
<a name="line1804">1804: </a>  PC_MG             *mg      = (PC_MG *)pc-&gt;data;
<a name="line1805">1805: </a>  PC_GAMG           *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;
<a name="line1806">1806: </a>  <a href="../../../../../manualpages/Sys/PetscBool.html">PetscBool</a>          flag;
<a name="line1807">1807: </a>  <a href="../../../../../manualpages/Sys/MPI_Comm.html">MPI_Comm</a>           comm;
<a name="line1808">1808: </a>  char               prefix[256], tname[32];
<a name="line1809">1809: </a>  <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a>           i, n;
<a name="line1810">1810: </a>  const char        *pcpre;
<a name="line1811">1811: </a>  static const char *LayoutTypes[] = {<font color="#666666">"compact"</font>, <font color="#666666">"spread"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMGLayoutType</a>"</font>, <font color="#666666">"PC_GAMG_LAYOUT"</font>, NULL};

<a name="line1813">1813: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1814">1814: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectGetComm.html">PetscObjectGetComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, &amp;comm));
<a name="line1815">1815: </a>  <a href="../../../../../manualpages/Sys/PetscOptionsHeadBegin.html">PetscOptionsHeadBegin</a>(PetscOptionsObject, <font color="#666666">"GAMG options"</font>);
<a name="line1816">1816: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsInt.html">PetscOptionsInt</a>(<font color="#666666">"-pc_mg_levels"</font>, <font color="#666666">"Number of Levels"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCMGSetLevels.html">PCMGSetLevels</a>"</font>, -1, &amp;n, &amp;flag));
<a name="line1817">1817: </a>  <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(!flag, comm, <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_ARG_WRONG</a>, <font color="#666666">"Invalid flag -pc_mg_levels. GAMG does not allow the number of levels to be set."</font>);
<a name="line1818">1818: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsFList.html">PetscOptionsFList</a>(<font color="#666666">"-pc_gamg_type"</font>, <font color="#666666">"Type of AMG method (only 'agg' supported and useful)"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetType.html">PCGAMGSetType</a>"</font>, GAMGList, pc_gamg-&gt;gamg_type_name, tname, <font color="#4169E1">sizeof</font>(tname), &amp;flag));
<a name="line1819">1819: </a>  <font color="#4169E1">if</font> (flag) <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCGAMGSetType.html">PCGAMGSetType</a>(pc, tname));
<a name="line1820">1820: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsBool.html">PetscOptionsBool</a>(<font color="#666666">"-pc_gamg_repartition"</font>, <font color="#666666">"Repartion coarse grids"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetRepartition.html">PCGAMGSetRepartition</a>"</font>, pc_gamg-&gt;repart, &amp;pc_gamg-&gt;repart, NULL));
<a name="line1821">1821: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsBool.html">PetscOptionsBool</a>(<font color="#666666">"-pc_gamg_use_sa_esteig"</font>, <font color="#666666">"Use eigen estimate from smoothed aggregation for smoother"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetUseSAEstEig.html">PCGAMGSetUseSAEstEig</a>"</font>, pc_gamg-&gt;use_sa_esteig, &amp;pc_gamg-&gt;use_sa_esteig, NULL));
<a name="line1822">1822: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsBool.html">PetscOptionsBool</a>(<font color="#666666">"-pc_gamg_recompute_esteig"</font>, <font color="#666666">"Set flag to recompute eigen estimates for Chebyshev when matrix changes"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetRecomputeEstEig.html">PCGAMGSetRecomputeEstEig</a>"</font>, pc_gamg-&gt;recompute_esteig, &amp;pc_gamg-&gt;recompute_esteig, NULL));
<a name="line1823">1823: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsBool.html">PetscOptionsBool</a>(<font color="#666666">"-pc_gamg_reuse_interpolation"</font>, <font color="#666666">"Reuse prolongation operator"</font>, <font color="#666666">"PCGAMGReuseInterpolation"</font>, pc_gamg-&gt;reuse_prol, &amp;pc_gamg-&gt;reuse_prol, NULL));
<a name="line1824">1824: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsBool.html">PetscOptionsBool</a>(<font color="#666666">"-pc_gamg_asm_use_agg"</font>, <font color="#666666">"Use aggregation aggregates for ASM smoother"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGASMSetUseAggs.html">PCGAMGASMSetUseAggs</a>"</font>, pc_gamg-&gt;use_aggs_in_asm, &amp;pc_gamg-&gt;use_aggs_in_asm, NULL));
<a name="line1825">1825: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsBool.html">PetscOptionsBool</a>(<font color="#666666">"-pc_gamg_parallel_coarse_grid_solver"</font>, <font color="#666666">"Use parallel coarse grid solver (otherwise put last grid on one process)"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetParallelCoarseGridSolve.html">PCGAMGSetParallelCoarseGridSolve</a>"</font>, pc_gamg-&gt;use_parallel_coarse_grid_solver, &amp;pc_gamg-&gt;use_parallel_coarse_grid_solver, NULL));
<a name="line1826">1826: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsBool.html">PetscOptionsBool</a>(<font color="#666666">"-pc_gamg_cpu_pin_coarse_grids"</font>, <font color="#666666">"Pin coarse grids to the CPU"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetCpuPinCoarseGrids.html">PCGAMGSetCpuPinCoarseGrids</a>"</font>, pc_gamg-&gt;cpu_pin_coarse_grids, &amp;pc_gamg-&gt;cpu_pin_coarse_grids, NULL));
<a name="line1827">1827: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsEnum.html">PetscOptionsEnum</a>(<font color="#666666">"-pc_gamg_coarse_grid_layout_type"</font>, <font color="#666666">"compact: place reduced grids on processes in natural order; spread: distribute to whole machine for more memory bandwidth"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetCoarseGridLayoutType.html">PCGAMGSetCoarseGridLayoutType</a>"</font>, LayoutTypes,
<a name="line1828">1828: </a>                             (<a href="../../../../../manualpages/Sys/PetscEnum.html">PetscEnum</a>)pc_gamg-&gt;layout_type, (<a href="../../../../../manualpages/Sys/PetscEnum.html">PetscEnum</a> *)&amp;pc_gamg-&gt;layout_type, NULL));
<a name="line1829">1829: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsInt.html">PetscOptionsInt</a>(<font color="#666666">"-pc_gamg_process_eq_limit"</font>, <font color="#666666">"Limit (goal) on number of equations per process on coarse grids"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetProcEqLim.html">PCGAMGSetProcEqLim</a>"</font>, pc_gamg-&gt;min_eq_proc, &amp;pc_gamg-&gt;min_eq_proc, NULL));
<a name="line1830">1830: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsInt.html">PetscOptionsInt</a>(<font color="#666666">"-pc_gamg_coarse_eq_limit"</font>, <font color="#666666">"Limit on number of equations for the coarse grid"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetCoarseEqLim.html">PCGAMGSetCoarseEqLim</a>"</font>, pc_gamg-&gt;coarse_eq_limit, &amp;pc_gamg-&gt;coarse_eq_limit, NULL));
<a name="line1831">1831: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsInt.html">PetscOptionsInt</a>(<font color="#666666">"-pc_gamg_asm_hem_aggs"</font>, <font color="#666666">"Number of HEM matching passed in aggregates for ASM smoother"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGASMSetHEM.html">PCGAMGASMSetHEM</a>"</font>, pc_gamg-&gt;asm_hem_aggs, &amp;pc_gamg-&gt;asm_hem_aggs, NULL));
<a name="line1832">1832: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsReal.html">PetscOptionsReal</a>(<font color="#666666">"-pc_gamg_threshold_scale"</font>, <font color="#666666">"Scaling of threshold for each level not specified"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetThresholdScale.html">PCGAMGSetThresholdScale</a>"</font>, pc_gamg-&gt;threshold_scale, &amp;pc_gamg-&gt;threshold_scale, NULL));
<a name="line1833">1833: </a>  n = PETSC_MG_MAXLEVELS;
<a name="line1834">1834: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsRealArray.html">PetscOptionsRealArray</a>(<font color="#666666">"-pc_gamg_threshold"</font>, <font color="#666666">"Relative threshold to use for dropping edges in aggregation graph"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetThreshold.html">PCGAMGSetThreshold</a>"</font>, pc_gamg-&gt;threshold, &amp;n, &amp;flag));
<a name="line1835">1835: </a>  <font color="#4169E1">if</font> (!flag || n &lt; PETSC_MG_MAXLEVELS) {
<a name="line1836">1836: </a>    <font color="#4169E1">if</font> (!flag) n = 1;
<a name="line1837">1837: </a>    i = n;
<a name="line1838">1838: </a>    <font color="#4169E1">do</font> {
<a name="line1839">1839: </a>      pc_gamg-&gt;threshold[i] = pc_gamg-&gt;threshold[i - 1] * pc_gamg-&gt;threshold_scale;
<a name="line1840">1840: </a>    } <font color="#4169E1">while</font> (++i &lt; PETSC_MG_MAXLEVELS);
<a name="line1841">1841: </a>  }
<a name="line1842">1842: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsInt.html">PetscOptionsInt</a>(<font color="#666666">"-pc_mg_levels"</font>, <font color="#666666">"Set number of MG levels (should get from base class)"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetNlevels.html">PCGAMGSetNlevels</a>"</font>, pc_gamg-&gt;Nlevels, &amp;pc_gamg-&gt;Nlevels, NULL));
<a name="line1843">1843: </a>  <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(pc_gamg-&gt;Nlevels &lt;= PETSC_MG_MAXLEVELS, <a href="../../../../../manualpages/Sys/PetscObjectComm.html">PetscObjectComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc), <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_ARG_INCOMP</a>, <font color="#666666">"-pc_mg_levels (%"</font> PetscInt_FMT <font color="#666666">") &gt;= PETSC_MG_MAXLEVELS (%d)"</font>, pc_gamg-&gt;Nlevels, PETSC_MG_MAXLEVELS);
<a name="line1844">1844: </a>  n = PETSC_MG_MAXLEVELS;
<a name="line1845">1845: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsIntArray.html">PetscOptionsIntArray</a>(<font color="#666666">"-pc_gamg_rank_reduction_factors"</font>, <font color="#666666">"Manual schedule of coarse grid reduction factors that overrides internal heuristics (0 for first reduction puts one process/device)"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetRankReductionFactors.html">PCGAMGSetRankReductionFactors</a>"</font>, pc_gamg-&gt;level_reduction_factors, &amp;n, &amp;flag));
<a name="line1846">1846: </a>  <font color="#4169E1">if</font> (!flag) i = 0;
<a name="line1847">1847: </a>  <font color="#4169E1">else</font> i = n;
<a name="line1848">1848: </a>  <font color="#4169E1">do</font> {
<a name="line1849">1849: </a>    pc_gamg-&gt;level_reduction_factors[i] = -1;
<a name="line1850">1850: </a>  } <font color="#4169E1">while</font> (++i &lt; PETSC_MG_MAXLEVELS);
<a name="line1851">1851: </a>  {
<a name="line1852">1852: </a>    <a href="../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> eminmax[2] = {0., 0.};
<a name="line1853">1853: </a>    n                    = 2;
<a name="line1854">1854: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsRealArray.html">PetscOptionsRealArray</a>(<font color="#666666">"-pc_gamg_eigenvalues"</font>, <font color="#666666">"extreme eigenvalues for smoothed aggregation"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetEigenvalues.html">PCGAMGSetEigenvalues</a>"</font>, eminmax, &amp;n, &amp;flag));
<a name="line1855">1855: </a>    <font color="#4169E1">if</font> (flag) {
<a name="line1856">1856: </a>      <a href="../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(n == 2, <a href="../../../../../manualpages/Sys/PetscObjectComm.html">PetscObjectComm</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc), <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_ARG_INCOMP</a>, <font color="#666666">"-pc_gamg_eigenvalues: must specify 2 parameters, min and max eigenvalues"</font>);
<a name="line1857">1857: </a>      <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCGAMGSetEigenvalues.html">PCGAMGSetEigenvalues</a>(pc, eminmax[1], eminmax[0]));
<a name="line1858">1858: </a>    }
<a name="line1859">1859: </a>  }
<a name="line1860">1860: </a>  pc_gamg-&gt;injection_index_size = MAT_COARSEN_STRENGTH_INDEX_SIZE;
<a name="line1861">1861: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscOptionsIntArray.html">PetscOptionsIntArray</a>(<font color="#666666">"-pc_gamg_injection_index"</font>, <font color="#666666">"Array of indices to use to use injection coarse grid space"</font>, <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMGSetInjectionIndex.html">PCGAMGSetInjectionIndex</a>"</font>, pc_gamg-&gt;injection_index, &amp;pc_gamg-&gt;injection_index_size, NULL));
<a name="line1862">1862: </a>  <font color="#B22222">/* set options for subtype */</font>
<a name="line1863">1863: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>((*pc_gamg-&gt;ops-&gt;setfromoptions)(pc, PetscOptionsObject));

<a name="line1865">1865: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCGetOptionsPrefix.html">PCGetOptionsPrefix</a>(pc, &amp;pcpre));
<a name="line1866">1866: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscSNPrintf.html">PetscSNPrintf</a>(prefix, <font color="#4169E1">sizeof</font>(prefix), <font color="#666666">"%spc_gamg_"</font>, pcpre ? pcpre : <font color="#666666">""</font>));
<a name="line1867">1867: </a>  <a href="../../../../../manualpages/Sys/PetscOptionsHeadEnd.html">PetscOptionsHeadEnd</a>();
<a name="line1868">1868: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1869">1869: </a>}

<a name="line1871">1871: </a><font color="#B22222">/*MC</font>
<a name="line1872">1872: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a> - Geometric algebraic multigrid (AMG) preconditioner</font>

<a name="line1874">1874: </a><font color="#B22222">  Options Database Keys:</font>
<a name="line1875">1875: </a><font color="#B22222">+ -pc_gamg_type &lt;type,default=agg&gt;                 - one of agg, geo, or classical (only smoothed aggregation, agg, supported)</font>
<a name="line1876">1876: </a><font color="#B22222">. -pc_gamg_repartition  &lt;bool,default=false&gt;       - repartition the degrees of freedom across the coarse grids as they are determined</font>
<a name="line1877">1877: </a><font color="#B22222">. -pc_gamg_asm_use_agg &lt;bool,default=false&gt;        - use the aggregates from the coasening process to defined the subdomains on each level for the `<a href="../../../../../manualpages/PC/PCASM.html">PCASM</a>` smoother.</font>
<a name="line1878">1878: </a><font color="#B22222">                                                     That is using `-mg_levels_pc_type asm`</font>
<a name="line1879">1879: </a><font color="#B22222">. -pc_gamg_process_eq_limit &lt;limit, default=50&gt;    - `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` will reduce the number of MPI ranks used directly on the coarse grids so that there are around &lt;limit&gt;</font>
<a name="line1880">1880: </a><font color="#B22222">                                                     equations on each process that has degrees of freedom</font>
<a name="line1881">1881: </a><font color="#B22222">. -pc_gamg_coarse_eq_limit &lt;limit, default=50&gt;     - Set maximum number of equations on coarsest grid to aim for.</font>
<a name="line1882">1882: </a><font color="#B22222">. -pc_gamg_reuse_interpolation &lt;bool,default=true&gt; - when rebuilding the algebraic multigrid preconditioner reuse the previously computed interpolations (should always be true)</font>
<a name="line1883">1883: </a><font color="#B22222">. -pc_gamg_threshold[] &lt;thresh,default=[-1,...]&gt;   - Before aggregating the graph `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` will remove small values from the graph on each level (&lt; 0 does no filtering)</font>
<a name="line1884">1884: </a><font color="#B22222">- -pc_gamg_threshold_scale &lt;scale,default=1&gt;       - Scaling of threshold on each coarser grid if not specified</font>

<a name="line1886">1886: </a><font color="#B22222">  Options Database Keys for Aggregation:</font>
<a name="line1887">1887: </a><font color="#B22222">+ -pc_gamg_agg_nsmooths &lt;nsmooth, default=1&gt;                 - number of smoothing steps to use with smooth aggregation to construct prolongation</font>
<a name="line1888">1888: </a><font color="#B22222">. -pc_gamg_aggressive_coarsening &lt;n,default=1&gt;               - number of aggressive coarsening (MIS-2) levels from finest.</font>
<a name="line1889">1889: </a><font color="#B22222">. -pc_gamg_aggressive_square_graph &lt;bool,default=false&gt;      - Use square graph (A'A) or MIS-k (k=2) for aggressive coarsening</font>
<a name="line1890">1890: </a><font color="#B22222">. -pc_gamg_mis_k_minimum_degree_ordering &lt;bool,default=true&gt; - Use minimum degree ordering in greedy MIS algorithm</font>
<a name="line1891">1891: </a><font color="#B22222">. -pc_gamg_pc_gamg_asm_hem_aggs &lt;n,default=0&gt;                - Number of HEM aggregation steps for `<a href="../../../../../manualpages/PC/PCASM.html">PCASM</a>` smoother</font>
<a name="line1892">1892: </a><font color="#B22222">- -pc_gamg_aggressive_mis_k &lt;n,default=2&gt;                    - Number (k) distance in MIS coarsening (&gt;2 is 'aggressive')</font>

<a name="line1894">1894: </a><font color="#B22222">  Options Database Keys for Multigrid:</font>
<a name="line1895">1895: </a><font color="#B22222">+ -pc_mg_cycle_type &lt;v&gt;        - v or w, see `<a href="../../../../../manualpages/PC/PCMGSetCycleType.html">PCMGSetCycleType</a>()`</font>
<a name="line1896">1896: </a><font color="#B22222">. -pc_mg_distinct_smoothup     - configure the up and down (pre and post) smoothers separately, see <a href="../../../../../manualpages/PC/PCMGSetDistinctSmoothUp.html">PCMGSetDistinctSmoothUp</a>()</font>
<a name="line1897">1897: </a><font color="#B22222">. -pc_mg_type &lt;multiplicative&gt; - (one of) additive multiplicative full kascade</font>
<a name="line1898">1898: </a><font color="#B22222">- -pc_mg_levels &lt;levels&gt;       - Number of levels of multigrid to use. GAMG has a heuristic so pc_mg_levels is not usually used with GAMG</font>

<a name="line1900">1900: </a><font color="#B22222">  Level: intermediate</font>

<a name="line1902">1902: </a><font color="#B22222">  Notes:</font>
<a name="line1903">1903: </a><font color="#B22222">  To obtain good performance for `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` for vector valued problems you must</font>
<a name="line1904">1904: </a><font color="#B22222">  call `<a href="../../../../../manualpages/Mat/MatSetBlockSize.html">MatSetBlockSize</a>()` to indicate the number of degrees of freedom per grid point</font>
<a name="line1905">1905: </a><font color="#B22222">  call `<a href="../../../../../manualpages/Mat/MatSetNearNullSpace.html">MatSetNearNullSpace</a>()` (or `<a href="../../../../../manualpages/PC/PCSetCoordinates.html">PCSetCoordinates</a>()` if solving the equations of elasticity) to indicate the near null space of the operator</font>

<a name="line1907">1907: </a><font color="#B22222">  The many options for `<a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>` also work directly for `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` such as controlling the smoothers on each level etc.</font>

<a name="line1909">1909: </a><font color="#B22222">.seealso: [the Users Manual section on <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>](sec_amg), [the Users Manual section on <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>](sec_mg), [](ch_ksp), `<a href="../../../../../manualpages/PC/PCCreate.html">PCCreate</a>()`, `<a href="../../../../../manualpages/PC/PCSetType.html">PCSetType</a>()`,</font>
<a name="line1910">1910: </a><font color="#B22222">          `<a href="../../../../../manualpages/Mat/MatSetBlockSize.html">MatSetBlockSize</a>()`,</font>
<a name="line1911">1911: </a><font color="#B22222">          `<a href="../../../../../manualpages/PC/PCMGType.html">PCMGType</a>`, `<a href="../../../../../manualpages/PC/PCSetCoordinates.html">PCSetCoordinates</a>()`, `<a href="../../../../../manualpages/Mat/MatSetNearNullSpace.html">MatSetNearNullSpace</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetType.html">PCGAMGSetType</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGAGG.html">PCGAMGAGG</a>`, `PCGAMGGEO`, `PCGAMGCLASSICAL`, `<a href="../../../../../manualpages/PC/PCGAMGSetProcEqLim.html">PCGAMGSetProcEqLim</a>()`,</font>
<a name="line1912">1912: </a><font color="#B22222">          `<a href="../../../../../manualpages/PC/PCGAMGSetCoarseEqLim.html">PCGAMGSetCoarseEqLim</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetRepartition.html">PCGAMGSetRepartition</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGRegister.html">PCGAMGRegister</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetReuseInterpolation.html">PCGAMGSetReuseInterpolation</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGASMSetUseAggs.html">PCGAMGASMSetUseAggs</a>()`,</font>
<a name="line1913">1913: </a><font color="#B22222">          `<a href="../../../../../manualpages/PC/PCGAMGSetParallelCoarseGridSolve.html">PCGAMGSetParallelCoarseGridSolve</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetNlevels.html">PCGAMGSetNlevels</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetThreshold.html">PCGAMGSetThreshold</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGGetType.html">PCGAMGGetType</a>()`, `<a href="../../../../../manualpages/PC/PCGAMGSetUseSAEstEig.html">PCGAMGSetUseSAEstEig</a>()`</font>
<a name="line1914">1914: </a><font color="#B22222">M*/</font>
<a name="line1915">1915: </a><strong><font color="#4169E1"><a name="PCCreate_GAMG"></a>PETSC_EXTERN <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCCreate_GAMG(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc)</font></strong>
<a name="line1916">1916: </a>{
<a name="line1917">1917: </a>  PC_GAMG *pc_gamg;
<a name="line1918">1918: </a>  PC_MG   *mg;

<a name="line1920">1920: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line1921">1921: </a>  <font color="#B22222">/* register AMG type */</font>
<a name="line1922">1922: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCGAMGInitializePackage.html">PCGAMGInitializePackage</a>());

<a name="line1924">1924: </a>  <font color="#B22222">/* <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a> is an inherited class of <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>. Initialize pc as <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a> */</font>
<a name="line1925">1925: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCSetType.html">PCSetType</a>(pc, <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a>));
<a name="line1926">1926: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PetscObjectChangeTypeName((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>));

<a name="line1928">1928: </a>  <font color="#B22222">/* create a supporting struct and attach it to pc */</font>
<a name="line1929">1929: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscNew.html">PetscNew</a>(&amp;pc_gamg));
<a name="line1930">1930: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCMGSetGalerkin.html">PCMGSetGalerkin</a>(pc, <a href="../../../../../manualpages/PC/PCMGalerkinType.html">PC_MG_GALERKIN_EXTERNAL</a>));
<a name="line1931">1931: </a>  mg           = (PC_MG *)pc-&gt;data;
<a name="line1932">1932: </a>  mg-&gt;innerctx = pc_gamg;

<a name="line1934">1934: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscNew.html">PetscNew</a>(&amp;pc_gamg-&gt;ops));

<a name="line1936">1936: </a>  <font color="#B22222">/* these should be in subctx but repartitioning needs simple arrays */</font>
<a name="line1937">1937: </a>  pc_gamg-&gt;data_sz = 0;
<a name="line1938">1938: </a>  pc_gamg-&gt;data    = NULL;

<a name="line1940">1940: </a>  <font color="#B22222">/* overwrite the pointers of <a href="../../../../../manualpages/PC/PCMG.html">PCMG</a> by the functions of base class <a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a> */</font>
<a name="line1941">1941: </a>  pc-&gt;ops-&gt;setfromoptions = PCSetFromOptions_GAMG;
<a name="line1942">1942: </a>  pc-&gt;ops-&gt;setup          = PCSetUp_GAMG;
<a name="line1943">1943: </a>  pc-&gt;ops-&gt;reset          = PCReset_GAMG;
<a name="line1944">1944: </a>  pc-&gt;ops-&gt;destroy        = PCDestroy_GAMG;
<a name="line1945">1945: </a>  mg-&gt;view                = PCView_GAMG;

<a name="line1947">1947: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetProcEqLim_C"</font>, PCGAMGSetProcEqLim_GAMG));
<a name="line1948">1948: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetCoarseEqLim_C"</font>, PCGAMGSetCoarseEqLim_GAMG));
<a name="line1949">1949: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetRepartition_C"</font>, PCGAMGSetRepartition_GAMG));
<a name="line1950">1950: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetEigenvalues_C"</font>, PCGAMGSetEigenvalues_GAMG));
<a name="line1951">1951: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetUseSAEstEig_C"</font>, PCGAMGSetUseSAEstEig_GAMG));
<a name="line1952">1952: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetRecomputeEstEig_C"</font>, PCGAMGSetRecomputeEstEig_GAMG));
<a name="line1953">1953: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetReuseInterpolation_C"</font>, PCGAMGSetReuseInterpolation_GAMG));
<a name="line1954">1954: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGASMSetUseAggs_C"</font>, PCGAMGASMSetUseAggs_GAMG));
<a name="line1955">1955: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetParallelCoarseGridSolve_C"</font>, PCGAMGSetParallelCoarseGridSolve_GAMG));
<a name="line1956">1956: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetCpuPinCoarseGrids_C"</font>, PCGAMGSetCpuPinCoarseGrids_GAMG));
<a name="line1957">1957: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetCoarseGridLayoutType_C"</font>, PCGAMGSetCoarseGridLayoutType_GAMG));
<a name="line1958">1958: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetThreshold_C"</font>, PCGAMGSetThreshold_GAMG));
<a name="line1959">1959: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetRankReductionFactors_C"</font>, PCGAMGSetRankReductionFactors_GAMG));
<a name="line1960">1960: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetThresholdScale_C"</font>, PCGAMGSetThresholdScale_GAMG));
<a name="line1961">1961: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetType_C"</font>, PCGAMGSetType_GAMG));
<a name="line1962">1962: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGGetType_C"</font>, PCGAMGGetType_GAMG));
<a name="line1963">1963: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetNlevels_C"</font>, PCGAMGSetNlevels_GAMG));
<a name="line1964">1964: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGASMSetHEM_C"</font>, PCGAMGASMSetHEM_GAMG));
<a name="line1965">1965: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscObjectComposeFunction.html">PetscObjectComposeFunction</a>((<a href="../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc, <font color="#666666">"PCGAMGSetInjectionIndex_C"</font>, PCGAMGSetInjectionIndex_GAMG));
<a name="line1966">1966: </a>  pc_gamg-&gt;repart                          = <a href="../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>;
<a name="line1967">1967: </a>  pc_gamg-&gt;reuse_prol                      = <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>;
<a name="line1968">1968: </a>  pc_gamg-&gt;use_aggs_in_asm                 = <a href="../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>;
<a name="line1969">1969: </a>  pc_gamg-&gt;use_parallel_coarse_grid_solver = <a href="../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>;
<a name="line1970">1970: </a>  pc_gamg-&gt;cpu_pin_coarse_grids            = <a href="../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>;
<a name="line1971">1971: </a>  pc_gamg-&gt;layout_type                     = <a href="../../../../../manualpages/PC/PCGAMGLayoutType.html">PCGAMG_LAYOUT_SPREAD</a>;
<a name="line1972">1972: </a>  pc_gamg-&gt;min_eq_proc                     = 50;
<a name="line1973">1973: </a>  pc_gamg-&gt;asm_hem_aggs                    = 0;
<a name="line1974">1974: </a>  pc_gamg-&gt;coarse_eq_limit                 = 50;
<a name="line1975">1975: </a>  <font color="#4169E1">for</font> (int i = 0; i &lt; PETSC_MG_MAXLEVELS; i++) pc_gamg-&gt;threshold[i] = -1;
<a name="line1976">1976: </a>  pc_gamg-&gt;threshold_scale  = 1.;
<a name="line1977">1977: </a>  pc_gamg-&gt;Nlevels          = PETSC_MG_MAXLEVELS;
<a name="line1978">1978: </a>  pc_gamg-&gt;current_level    = 0; <font color="#B22222">/* don't need to init really */</font>
<a name="line1979">1979: </a>  pc_gamg-&gt;use_sa_esteig    = <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>;
<a name="line1980">1980: </a>  pc_gamg-&gt;recompute_esteig = <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>;
<a name="line1981">1981: </a>  pc_gamg-&gt;emin             = 0;
<a name="line1982">1982: </a>  pc_gamg-&gt;emax             = 0;

<a name="line1984">1984: </a>  pc_gamg-&gt;ops-&gt;createlevel = PCGAMGCreateLevel_GAMG;

<a name="line1986">1986: </a>  <font color="#B22222">/* PCSetUp_GAMG assumes that the type has been set, so set it to the default now */</font>
<a name="line1987">1987: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCGAMGSetType.html">PCGAMGSetType</a>(pc, <a href="../../../../../manualpages/PC/PCGAMGAGG.html">PCGAMGAGG</a>));
<a name="line1988">1988: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line1989">1989: </a>}

<a name="line1991">1991: </a><font color="#B22222">/*@C</font>
<a name="line1992">1992: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGInitializePackage.html">PCGAMGInitializePackage</a> - This function initializes everything in the `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` package. It is called</font>
<a name="line1993">1993: </a><font color="#B22222">  from `<a href="../../../../../manualpages/KSP/PCInitializePackage.html">PCInitializePackage</a>()`.</font>

<a name="line1995">1995: </a><font color="#B22222">  Level: developer</font>

<a name="line1997">1997: </a><font color="#B22222">.seealso: [](ch_ksp), `<a href="../../../../../manualpages/Sys/PetscInitialize.html">PetscInitialize</a>()`</font>
<a name="line1998">1998: </a><font color="#B22222">@*/</font>
<a name="line1999">1999: </a><strong><font color="#4169E1"><a name="PCGAMGInitializePackage"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGInitializePackage.html">PCGAMGInitializePackage</a>(void)</font></strong>
<a name="line2000">2000: </a>{
<a name="line2001">2001: </a>  <a href="../../../../../manualpages/Sys/PetscInt.html">PetscInt</a> l;

<a name="line2003">2003: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line2004">2004: </a>  <font color="#4169E1">if</font> (PCGAMGPackageInitialized) <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line2005">2005: </a>  PCGAMGPackageInitialized = <a href="../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>;
<a name="line2006">2006: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFunctionListAdd.html">PetscFunctionListAdd</a>(&amp;GAMGList, PCGAMGGEO, PCCreateGAMG_GEO));
<a name="line2007">2007: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFunctionListAdd.html">PetscFunctionListAdd</a>(&amp;GAMGList, <a href="../../../../../manualpages/PC/PCGAMGAGG.html">PCGAMGAGG</a>, PCCreateGAMG_AGG));
<a name="line2008">2008: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFunctionListAdd.html">PetscFunctionListAdd</a>(&amp;GAMGList, PCGAMGCLASSICAL, PCCreateGAMG_Classical));
<a name="line2009">2009: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscRegisterFinalize.html">PetscRegisterFinalize</a>(<a href="../../../../../manualpages/PC/PCGAMGFinalizePackage.html">PCGAMGFinalizePackage</a>));

<a name="line2011">2011: </a>  <font color="#B22222">/* general events */</font>
<a name="line2012">2012: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">"PCSetUp_GAMG+"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_SETUP]));
<a name="line2013">2013: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">" PCGAMGCreateG"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_GRAPH]));
<a name="line2014">2014: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">" GAMG Coarsen"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_COARSEN]));
<a name="line2015">2015: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">"  GAMG MIS/Agg"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_MIS]));
<a name="line2016">2016: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">" PCGAMGProl"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_PROL]));
<a name="line2017">2017: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">"  GAMG Prol-col"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_PROLA]));
<a name="line2018">2018: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">"  GAMG Prol-lift"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_PROLB]));
<a name="line2019">2019: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">" PCGAMGOptProl"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_OPT]));
<a name="line2020">2020: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">"  GAMG smooth"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_OPTSM]));
<a name="line2021">2021: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">" PCGAMGCreateL"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_LEVEL]));
<a name="line2022">2022: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">"  GAMG PtAP"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_PTAP]));
<a name="line2023">2023: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">"  GAMG Reduce"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_REDUCE]));
<a name="line2024">2024: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(<font color="#666666">"   GAMG Repart"</font>, PC_CLASSID, &amp;petsc_gamg_setup_events[GAMG_REPART]));
<a name="line2025">2025: </a>  <font color="#B22222">/* <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>("   GAMG Inv-Srt", PC_CLASSID, &amp;petsc_gamg_setup_events[SET13])); */</font>
<a name="line2026">2026: </a>  <font color="#B22222">/* <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>("   GAMG Move A", PC_CLASSID, &amp;petsc_gamg_setup_events[SET14])); */</font>
<a name="line2027">2027: </a>  <font color="#B22222">/* <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>("   GAMG Move P", PC_CLASSID, &amp;petsc_gamg_setup_events[SET15])); */</font>
<a name="line2028">2028: </a>  <font color="#4169E1">for</font> (l = 0; l &lt; PETSC_MG_MAXLEVELS; l++) {
<a name="line2029">2029: </a>    char ename[32];

<a name="line2031">2031: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscSNPrintf.html">PetscSNPrintf</a>(ename, <font color="#4169E1">sizeof</font>(ename), <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a> Squ l%02"</font> PetscInt_FMT, l));
<a name="line2032">2032: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(ename, PC_CLASSID, &amp;petsc_gamg_setup_matmat_events[l][0]));
<a name="line2033">2033: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscSNPrintf.html">PetscSNPrintf</a>(ename, <font color="#4169E1">sizeof</font>(ename), <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a> Gal l%02"</font> PetscInt_FMT, l));
<a name="line2034">2034: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(ename, PC_CLASSID, &amp;petsc_gamg_setup_matmat_events[l][1]));
<a name="line2035">2035: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscSNPrintf.html">PetscSNPrintf</a>(ename, <font color="#4169E1">sizeof</font>(ename), <font color="#666666">"<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a> Opt l%02"</font> PetscInt_FMT, l));
<a name="line2036">2036: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogEventRegister.html">PetscLogEventRegister</a>(ename, PC_CLASSID, &amp;petsc_gamg_setup_matmat_events[l][2]));
<a name="line2037">2037: </a>  }
<a name="line2038">2038: </a><font color="#A020F0">#if defined(GAMG_STAGES)</font>
<a name="line2039">2039: </a>  { <font color="#B22222">/* create timer stages */</font>
<a name="line2040">2040: </a>    char str[32];
<a name="line2041">2041: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscSNPrintf.html">PetscSNPrintf</a>(str, <a href="../../../../../manualpages/Sys/PETSC_STATIC_ARRAY_LENGTH.html">PETSC_STATIC_ARRAY_LENGTH</a>(str), <font color="#666666">"GAMG Level %d"</font>, 0));
<a name="line2042">2042: </a>    <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Log/PetscLogStageRegister.html">PetscLogStageRegister</a>(str, &amp;gamg_stages[0]));
<a name="line2043">2043: </a>  }
<a name="line2044">2044: </a><font color="#A020F0">#endif</font>
<a name="line2045">2045: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line2046">2046: </a>}

<a name="line2048">2048: </a><font color="#B22222">/*@C</font>
<a name="line2049">2049: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGFinalizePackage.html">PCGAMGFinalizePackage</a> - This function frees everything from the `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` package. It is</font>
<a name="line2050">2050: </a><font color="#B22222">  called from `<a href="../../../../../manualpages/Sys/PetscFinalize.html">PetscFinalize</a>()` automatically.</font>

<a name="line2052">2052: </a><font color="#B22222">  Level: developer</font>

<a name="line2054">2054: </a><font color="#B22222">.seealso: [](ch_ksp), `<a href="../../../../../manualpages/Sys/PetscFinalize.html">PetscFinalize</a>()`</font>
<a name="line2055">2055: </a><font color="#B22222">@*/</font>
<a name="line2056">2056: </a><strong><font color="#4169E1"><a name="PCGAMGFinalizePackage"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGFinalizePackage.html">PCGAMGFinalizePackage</a>(void)</font></strong>
<a name="line2057">2057: </a>{
<a name="line2058">2058: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line2059">2059: </a>  PCGAMGPackageInitialized = <a href="../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>;
<a name="line2060">2060: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFunctionListDestroy.html">PetscFunctionListDestroy</a>(&amp;GAMGList));
<a name="line2061">2061: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line2062">2062: </a>}

<a name="line2064">2064: </a><font color="#B22222">/*@C</font>
<a name="line2065">2065: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGRegister.html">PCGAMGRegister</a> - Register a `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` implementation.</font>

<a name="line2067">2067: </a><font color="#B22222">  Input Parameters:</font>
<a name="line2068">2068: </a><font color="#B22222">+ type   - string that will be used as the name of the `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>` type.</font>
<a name="line2069">2069: </a><font color="#B22222">- create - function for creating the gamg context.</font>

<a name="line2071">2071: </a><font color="#B22222">  Level: developer</font>

<a name="line2073">2073: </a><font color="#B22222">.seealso: [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMGType.html">PCGAMGType</a>`, `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetType.html">PCGAMGSetType</a>()`</font>
<a name="line2074">2074: </a><font color="#B22222">@*/</font>
<a name="line2075">2075: </a><strong><font color="#4169E1"><a name="PCGAMGRegister"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGRegister.html">PCGAMGRegister</a>(<a href="../../../../../manualpages/PC/PCGAMGType.html">PCGAMGType</a> type, <a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> (*create)(<a href="../../../../../manualpages/PC/PC.html">PC</a>))</font></strong>
<a name="line2076">2076: </a>{
<a name="line2077">2077: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line2078">2078: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/PC/PCGAMGInitializePackage.html">PCGAMGInitializePackage</a>());
<a name="line2079">2079: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../manualpages/Sys/PetscFunctionListAdd.html">PetscFunctionListAdd</a>(&amp;GAMGList, type, create));
<a name="line2080">2080: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line2081">2081: </a>}

<a name="line2083">2083: </a><font color="#B22222">/*@</font>
<a name="line2084">2084: </a><font color="#B22222">  <a href="../../../../../manualpages/PC/PCGAMGCreateGraph.html">PCGAMGCreateGraph</a> - Creates a graph that is used by the ``<a href="../../../../../manualpages/PC/PCGAMGType.html">PCGAMGType</a>`` in the coarsening process</font>

<a name="line2086">2086: </a><font color="#B22222">  Input Parameters:</font>
<a name="line2087">2087: </a><font color="#B22222">+ pc - the `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`</font>
<a name="line2088">2088: </a><font color="#B22222">- A  - the matrix, for any level</font>

<a name="line2090">2090: </a><font color="#B22222">  Output Parameter:</font>
<a name="line2091">2091: </a><font color="#B22222">. G - the graph</font>

<a name="line2093">2093: </a><font color="#B22222">  Level: advanced</font>

<a name="line2095">2095: </a><font color="#B22222">.seealso: [](ch_ksp), `<a href="../../../../../manualpages/PC/PCGAMGType.html">PCGAMGType</a>`, `<a href="../../../../../manualpages/PC/PCGAMG.html">PCGAMG</a>`, `<a href="../../../../../manualpages/PC/PCGAMGSetType.html">PCGAMGSetType</a>()`</font>
<a name="line2096">2096: </a><font color="#B22222">@*/</font>
<a name="line2097">2097: </a><strong><font color="#4169E1"><a name="PCGAMGCreateGraph"></a><a href="../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../manualpages/PC/PCGAMGCreateGraph.html">PCGAMGCreateGraph</a>(<a href="../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../manualpages/Mat/Mat.html">Mat</a> A, <a href="../../../../../manualpages/Mat/Mat.html">Mat</a> *G)</font></strong>
<a name="line2098">2098: </a>{
<a name="line2099">2099: </a>  PC_MG   *mg      = (PC_MG *)pc-&gt;data;
<a name="line2100">2100: </a>  PC_GAMG *pc_gamg = (PC_GAMG *)mg-&gt;innerctx;

<a name="line2102">2102: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line2103">2103: </a>  <a href="../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(pc_gamg-&gt;ops-&gt;creategraph(pc, A, G));
<a name="line2104">2104: </a>  <a href="../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line2105">2105: </a>}
</pre>
</body>

</html>