1 #include "BSprivate.h"
2 
3 /*@ BSmain_reperm - Permute the sparse matrix using data structures
4                     generated by BSmain_perm on the same matrix structure
5 
6     Input Parameters:
7 .   procinfo - the usual processor information
8 .   A - the original sparse matrix
9 .   pA - the matrix generated by an execution of BSmain_perm
10 
11     Output Parameters:
12 .   pA - same as pA except that the nonzero values in pA are the same
13          as those in A
14 
15     Returns:
16     void
17 
18     Notes:
19     The matrix pA must have been generated by BSmain_perm with
20     retain set to TRUE.
21 
22  @*/
BSmain_reperm(BSprocinfo * procinfo,BSspmat * A,BSpar_mat * pA)23 void BSmain_reperm(BSprocinfo *procinfo, BSspmat *A, BSpar_mat *pA)
24 {
25     BSreperm *reperm;
26 	BSsprow **perm_rows;
27 	int	max_row_len;
28 
29 	reperm = pA->reperm;
30 
31 	/* check to make sure that reperm isn't NULL */
32 	if (reperm == NULL) {
33 		MY_SETERRC(REPERM_ERROR,
34 			"Permutation information not saved: cannot repermute matrix\n");
35 	}
36 
37 	/* check rows for consistency */
38 	if (procinfo->error_check) {
39 		BSrow_err_check(A,procinfo); CHKERR(0);
40 	}
41 
42 	/* *************************************************************** */
43 	/* BEGIN SECTION:                                                  */
44 	/* Permute the nonzeros at the row level and sort them             */
45 	/* Remember to unsort them                                         */
46 	/* *************************************************************** */
47 
48 	BSperm_rows(A,pA->global_row_num,reperm->inode_perm,
49 		reperm->inode_distr,procinfo,FALSE,&max_row_len); CHKERR(0);
50 	perm_rows = BSrow_perm(A,pA->inv_perm); CHKERR(0);
51 
52 	/* *************************************************************** */
53 	/* END SECTION:                                                    */
54 	/* *************************************************************** */
55 
56 	/* *************************************************************** */
57 	/* BEGIN SECTION:                                                  */
58 	/* Put the numeric values into the transposed inode structure      */
59 	/* *************************************************************** */
60 	BSnz_2_inode(A,perm_rows,pA->inodes,pA->clique2inode,procinfo); CHKERR(0);
61 	MY_FREE(perm_rows);
62 
63 	/* *************************************************************** */
64 	/* END SECTION:                                                    */
65 	/* *************************************************************** */
66 
67 	/* *************************************************************** */
68 	/* BEGIN SECTION:                                                  */
69 	/* Unsort the rows to original condition                           */
70 	/* *************************************************************** */
71 
72 	BSsort_rows(A,reperm->inode_perm,reperm->inode_distr,max_row_len);
73 	CHKERR(0);
74 
75 	/* *************************************************************** */
76 	/* END SECTION:                                                    */
77 	/* *************************************************************** */
78 
79 	/* get the diagonal */
80 	BSget_diag(pA,pA->diag,procinfo); CHKERR(0);
81 	pA->map = A->map;
82 }
83