1 #include "BSprivate.h"
2 
3 int BSnonlocalnz(BSspmat *,int *,BSprocinfo *);
4 
5 /*+ BScount_nz - Count the number of nonzeroes in a sparse matrix
6                  stored in the parallel format
7 
8     Input Parameters:
9 .   A - The sparse matrix (stored in parallel format)
10 .   procinfo - the usual processor info
11 
12     Returns:
13 	the number of nonzeros
14 
15 +*/
BScount_nz(BSpar_mat * A,BSprocinfo * procinfo)16 int BScount_nz(BSpar_mat *A, BSprocinfo *procinfo)
17 {
18 	int	i;
19 	int	cl_ind, in_ind;
20 	int	size, num_cols;
21 	BScl_2_inode *clique2inode;
22 	BSnumbering *color2clique;
23 	BSinode *inodes;
24 	int	nnz;
25 
26 	color2clique = A->color2clique;
27 	clique2inode = A->clique2inode;
28 	inodes = A->inodes->list;
29 
30 	nnz = 0;
31 	for (i=0;i<color2clique->length-1;i++) {
32 		/* do some local work */
33 		for (cl_ind=color2clique->numbers[i];
34 			cl_ind<color2clique->numbers[i+1];cl_ind++) {
35 			if (procinfo->my_id == clique2inode->proc[cl_ind]) {
36 				size = clique2inode->d_mats[cl_ind].size;
37 				if(A->icc_storage)
38 					nnz += (size*(size+1))/2;
39 				else
40 					nnz += (size*size);
41 			}
42 			for (in_ind=clique2inode->inode_index[cl_ind];
43 				in_ind<clique2inode->inode_index[cl_ind+1];in_ind++) {
44 				size = inodes[in_ind].length;
45 				num_cols = inodes[in_ind].num_cols;
46 				nnz += size*num_cols;
47 			}
48 		}
49 	}
50 
51 	if(!A->icc_storage) nnz = (nnz + A->num_rows)/2;
52 
53 	return(nnz);
54 }
55 
56 /*+ BSnonlocalnz - Count the number of nonzeroes in a sparse matrix
57                    stored in the original format
58 
59     Input Parameters:
60 .   A - The sparse matrix (stored in original format)
61 .   max_row_len - pointer to the the maximum length of any row
62 .                 set on output
63 .   procinfo - the usual processor info
64 
65     Returns:
66     number of nonlocal nonzeros
67 
68 +*/
BSnonlocalnz(BSspmat * A,int * max_row_len,BSprocinfo * procinfo)69 int	BSnonlocalnz(BSspmat *A,int *max_row_len,BSprocinfo *procinfo)
70 {
71 	int	count;
72 	int	i, j;
73 	void	(*map)(int,int *,int *,BSprocinfo *,BSmapping *);
74 	BSsprow	*row;
75 	int	mrow_len = 0;
76 	int	*iwork;
77 
78 	count = 0;
79 	for (i=0;i<A->num_rows;i++) {
80 		if (A->rows[i]->length > mrow_len) mrow_len = A->rows[i]->length;
81 	}
82 	MY_MALLOCN(iwork,(int *),sizeof(int)*mrow_len,1);
83 	map = A->map->fglobal2proc;
84 	for (i=0;i<A->num_rows;i++) {
85 		row = A->rows[i];
86      	(*map)(row->length,row->col,iwork,procinfo,A->map); CHKERRN(0);
87 		for (j=0;j<row->length;j++) {
88 			if (iwork[j] != procinfo->my_id) count++;
89 		}
90 	}
91 	MY_FREE(iwork);
92 	(*max_row_len) = mrow_len;
93 	return(count);
94 }
95 
96