1 #include "BSprivate.h"
2 
3 /*@ BSsetup_factor - Set up the communication for factorization
4 
5     Input Parameters:
6 .   A - a sparse matrix
7 .   procinfo - the usual processor stuff
8 
9     Returns:
10     the communication structure for factorization
11 
12  @*/
BSsetup_factor(BSpar_mat * A,BSprocinfo * procinfo)13 BScomm *BSsetup_factor(BSpar_mat *A, BSprocinfo *procinfo)
14 {
15 	BMcomp_msg *to_msg, *from_msg;
16 	BScomm *comm_ptr;
17 	BMphase *phase_ptr;
18 	BMmsg *msg;
19 	int	i;
20 	int	cl_ind, in_ind;
21 	int	count;
22 	int	*setup_data, *user_data;
23 	BScl_2_inode *clique2inode;
24 	BSnumbering *color2clique;
25 	BSinode *inodes;
26 
27 	/* initialize communication structures */
28 	to_msg = BMcomp_init(COMP_MSG_BASE); CHKERRN(0);
29 	from_msg = BMcomp_init(COMP_MSG_BASE); CHKERRN(0);
30 
31 	/* initialize variables for ease of use */
32 	color2clique = A->color2clique;
33 	clique2inode = A->clique2inode;
34 	inodes = A->inodes->list;
35 
36 	/* now go through and figure out everyone that we need stuff from */
37 	/* do it by color, where each color is a phase */
38 	for (i=0;i<color2clique->length-1;i++) {
39 		for (cl_ind = color2clique->numbers[i];
40 			cl_ind < color2clique->numbers[i+1];cl_ind++) {
41 			/* figure out the message size and destination */
42 			if (clique2inode->proc[cl_ind] != procinfo->my_id) {
43 				for (in_ind=clique2inode->inode_index[cl_ind];
44 					in_ind<clique2inode->inode_index[cl_ind+1];in_ind++) {
45 					if (inodes[in_ind].length > 0) {
46 						msg = BMcreate_msg(i,-1,MPI_BYTE,
47 							clique2inode->proc[cl_ind]); CHKERRN(0);
48 						BMadd_msg(from_msg,msg,procinfo); CHKERRN(0);
49 						MY_MALLOCN(setup_data,(int *),sizeof(int)*3,1);
50 						setup_data[0] = inodes[in_ind].gcol_num;
51 						setup_data[1] = inodes[in_ind].length;
52 						setup_data[2] = inodes[in_ind].num_cols;
53 						BMset_setup_data(msg,setup_data,3,BSfree_comm_data);
54 						CHKERRN(0);
55 						MY_MALLOCN(user_data,(int *),sizeof(int)*2,1);
56 						user_data[0] = cl_ind;
57 						user_data[1] = in_ind;
58 						BMset_user_data(msg,user_data,2,BSfree_comm_data);
59 						CHKERRN(0);
60 					}
61 				}
62 			}
63 		}
64 
65 		/* now, let's work out what I need to send */
66 		phase_ptr = BMget_phase(from_msg,i); CHKERRN(0);
67 		count = BMfix_send(SETUP_FACTOR_MSG,COMP_MSG_BASE,MPI_BYTE,to_msg,
68 			phase_ptr,BSfree_comm_data,procinfo); CHKERRN(0);
69 
70 		/* now free up the setup data */
71 		msg = NULL;
72 		while ((msg = BMnext_msg(phase_ptr,msg)) != NULL) {
73 			CHKERRN(0);
74 			BMfree_setup_data(msg);
75 			CHKERRN(0);
76 		}
77 		CHKERRN(0);
78 	}
79 
80 	MY_MALLOCN(comm_ptr,(BScomm *),sizeof(BScomm),1);
81 	comm_ptr->to_msg = to_msg;
82 	comm_ptr->from_msg = from_msg;
83 	return(comm_ptr);
84 }
85