1 /*
2  * Copyright 1997, Regents of the University of Minnesota
3  *
4  * debug.c
5  *
6  * This file contains various functions that are used to display debuging
7  * information
8  *
9  * Started 10/20/96
10  * George
11  *
12  * $Id: debug.c 10391 2011-06-23 19:00:08Z karypis $
13  *
14  */
15 
16 #include <parmetislib.h>
17 
18 
19 /*************************************************************************
20 * This function prints a vector stored in each processor
21 **************************************************************************/
PrintVector(ctrl_t * ctrl,idx_t n,idx_t first,idx_t * vec,char * title)22 void PrintVector(ctrl_t *ctrl, idx_t n, idx_t first, idx_t *vec, char *title)
23 {
24   idx_t i, penum;
25 
26   for (penum=0; penum<ctrl->npes; penum++) {
27     if (ctrl->mype == penum) {
28       if (ctrl->mype == 0)
29         fprintf(stdout, "%s\n", title);
30       fprintf(stdout, "\t%3"PRIDX". ", ctrl->mype);
31       for (i=0; i<n; i++)
32         fprintf(stdout, "[%"PRIDX" %"PRIDX"] ", first+i, vec[i]);
33       fprintf(stdout, "\n");
34       fflush(stdout);
35     }
36     gkMPI_Barrier(ctrl->comm);
37   }
38 }
39 
40 
41 /*************************************************************************
42 * This function prints a vector stored in each processor
43 **************************************************************************/
PrintVector2(ctrl_t * ctrl,idx_t n,idx_t first,idx_t * vec,char * title)44 void PrintVector2(ctrl_t *ctrl, idx_t n, idx_t first, idx_t *vec, char *title)
45 {
46   idx_t i, penum;
47 
48   for (penum=0; penum<ctrl->npes; penum++) {
49     if (ctrl->mype == penum) {
50       if (ctrl->mype == 0)
51         printf("%s\n", title);
52       printf("\t%3"PRIDX". ", ctrl->mype);
53       for (i=0; i<n; i++)
54         printf("[%"PRIDX" %"PRIDX".%"PRIDX"] ", first+i,
55             (idx_t)(vec[i]>=KEEP_BIT ? 1 : 0),
56             (idx_t)(vec[i]>=KEEP_BIT ? vec[i]-KEEP_BIT : vec[i]));
57       printf("\n");
58       fflush(stdout);
59     }
60     gkMPI_Barrier(ctrl->comm);
61   }
62 }
63 
64 
65 /*************************************************************************
66 * This function prints a vector stored in each processor
67 **************************************************************************/
PrintPairs(ctrl_t * ctrl,idx_t n,ikv_t * pairs,char * title)68 void PrintPairs(ctrl_t *ctrl, idx_t n, ikv_t *pairs, char *title)
69 {
70   idx_t i, penum;
71 
72   for (penum=0; penum<ctrl->npes; penum++) {
73     if (ctrl->mype == penum) {
74       if (ctrl->mype == 0)
75         printf("%s\n", title);
76       printf("\t%3"PRIDX". ", ctrl->mype);
77       for (i=0; i<n; i++)
78         printf("[%"PRIDX" %"PRIDX", %"PRIDX"] ", i, pairs[i].key, pairs[i].val);
79       printf("\n");
80       fflush(stdout);
81     }
82     gkMPI_Barrier(ctrl->comm);
83   }
84 }
85 
86 
87 
88 /*************************************************************************
89 * This function prints the local portion of the graph stored at each
90 * processor
91 **************************************************************************/
PrintGraph(ctrl_t * ctrl,graph_t * graph)92 void PrintGraph(ctrl_t *ctrl, graph_t *graph)
93 {
94   idx_t i, j, penum;
95   idx_t firstvtx;
96 
97   gkMPI_Barrier(ctrl->comm);
98 
99   firstvtx = graph->vtxdist[ctrl->mype];
100 
101   for (penum=0; penum<ctrl->npes; penum++) {
102     if (ctrl->mype == penum) {
103       printf("\t%"PRIDX"", penum);
104       for (i=0; i<graph->nvtxs; i++) {
105         if (i==0)
106           printf("\t%2"PRIDX" %2"PRIDX"\t", firstvtx+i, graph->vwgt[i]);
107         else
108           printf("\t\t%2"PRIDX" %2"PRIDX"\t", firstvtx+i, graph->vwgt[i]);
109         for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)
110           printf("[%"PRIDX" %"PRIDX"] ", graph->adjncy[j], graph->adjwgt[j]);
111         printf("\n");
112       }
113       fflush(stdout);
114     }
115     gkMPI_Barrier(ctrl->comm);
116   }
117 }
118 
119 
120 /*************************************************************************
121 * This function prints the local portion of the graph stored at each
122 * processor along with degree information during refinement
123 **************************************************************************/
PrintGraph2(ctrl_t * ctrl,graph_t * graph)124 void PrintGraph2(ctrl_t *ctrl, graph_t *graph)
125 {
126   idx_t i, j, penum;
127   idx_t firstvtx;
128 
129   gkMPI_Barrier(ctrl->comm);
130 
131   firstvtx = graph->vtxdist[ctrl->mype];
132 
133   for (penum=0; penum<ctrl->npes; penum++) {
134     if (ctrl->mype == penum) {
135       printf("\t%"PRIDX"", penum);
136       for (i=0; i<graph->nvtxs; i++) {
137         if (i==0)
138           printf("\t%2"PRIDX" %2"PRIDX" [%"PRIDX" %"PRIDX" %"PRIDX"]\t", firstvtx+i, graph->vwgt[i], graph->where[i], graph->ckrinfo[i].id, graph->ckrinfo[i].ed);
139         else
140           printf("\t\t%2"PRIDX" %2"PRIDX" [%"PRIDX" %"PRIDX" %"PRIDX"]\t", firstvtx+i, graph->vwgt[i], graph->where[i], graph->ckrinfo[i].id, graph->ckrinfo[i].ed);
141         for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)
142           printf("[%"PRIDX" %"PRIDX"] ", graph->adjncy[j], graph->adjwgt[j]);
143         printf("\n");
144       }
145       fflush(stdout);
146     }
147     gkMPI_Barrier(ctrl->comm);
148   }
149 }
150 
151 
152 /*************************************************************************
153 * This function prints the information computed during setup
154 **************************************************************************/
PrintSetUpInfo(ctrl_t * ctrl,graph_t * graph)155 void PrintSetUpInfo(ctrl_t *ctrl, graph_t *graph)
156 {
157   idx_t i, j, penum;
158 
159   gkMPI_Barrier(ctrl->comm);
160 
161   for (penum=0; penum<ctrl->npes; penum++) {
162     if (ctrl->mype == penum) {
163       printf("PE: %"PRIDX", nnbrs: %"PRIDX"\n", ctrl->mype, graph->nnbrs);
164       printf("\tSending...\n");
165       for (i=0; i<graph->nnbrs; i++) {
166         printf("\t\tTo: %"PRIDX": ", graph->peind[i]);
167         for (j=graph->sendptr[i]; j<graph->sendptr[i+1]; j++)
168           printf("%"PRIDX" ", graph->sendind[j]);
169         printf("\n");
170       }
171       printf("\tReceiving...\n");
172       for (i=0; i<graph->nnbrs; i++) {
173         printf("\t\tFrom: %"PRIDX": ", graph->peind[i]);
174         for (j=graph->recvptr[i]; j<graph->recvptr[i+1]; j++)
175           printf("%"PRIDX" ", graph->recvind[j]);
176         printf("\n");
177       }
178       printf("\n");
179     }
180     gkMPI_Barrier(ctrl->comm);
181   }
182 
183 }
184 
185 
186 /*************************************************************************
187 * This function prints information about the graphs that were sent/received
188 **************************************************************************/
PrintTransferedGraphs(ctrl_t * ctrl,idx_t nnbrs,idx_t * peind,idx_t * slens,idx_t * rlens,idx_t * sgraph,idx_t * rgraph)189 void PrintTransferedGraphs(ctrl_t *ctrl, idx_t nnbrs, idx_t *peind,
190          idx_t *slens, idx_t *rlens, idx_t *sgraph, idx_t *rgraph)
191 {
192   idx_t i, ii, jj, ll, penum;
193 
194   gkMPI_Barrier(ctrl->comm);
195   for (penum=0; penum<ctrl->npes; penum++) {
196     if (ctrl->mype == penum) {
197       printf("PE: %"PRIDX", nnbrs: %"PRIDX"", ctrl->mype, nnbrs);
198       for (ll=i=0; i<nnbrs; i++) {
199         if (slens[i+1]-slens[i] > 0) {
200           printf("\n\tTo %"PRIDX"\t", peind[i]);
201           for (ii=slens[i]; ii<slens[i+1]; ii++) {
202             printf("%"PRIDX" %"PRIDX" %"PRIDX", ", sgraph[ll], sgraph[ll+1], sgraph[ll+2]);
203             for (jj=0; jj<sgraph[ll+1]; jj++)
204               printf("[%"PRIDX" %"PRIDX"] ", sgraph[ll+3+2*jj], sgraph[ll+3+2*jj+1]);
205             printf("\n\t\t");
206             ll += 3+2*sgraph[ll+1];
207           }
208         }
209       }
210 
211       for (ll=i=0; i<nnbrs; i++) {
212         if (rlens[i+1]-rlens[i] > 0) {
213           printf("\n\tFrom %"PRIDX"\t", peind[i]);
214           for (ii=rlens[i]; ii<rlens[i+1]; ii++) {
215             printf("%"PRIDX" %"PRIDX" %"PRIDX", ", rgraph[ll], rgraph[ll+1], rgraph[ll+2]);
216             for (jj=0; jj<rgraph[ll+1]; jj++)
217               printf("[%"PRIDX" %"PRIDX"] ", rgraph[ll+3+2*jj], rgraph[ll+3+2*jj+1]);
218             printf("\n\t\t");
219             ll += 3+2*rgraph[ll+1];
220           }
221         }
222       }
223       printf("\n");
224     }
225     gkMPI_Barrier(ctrl->comm);
226   }
227 
228 }
229 
230 
231 /*************************************************************************
232 * This function writes a graph in the format used by serial METIS
233 **************************************************************************/
WriteMetisGraph(idx_t nvtxs,idx_t * xadj,idx_t * adjncy,idx_t * vwgt,idx_t * adjwgt)234 void WriteMetisGraph(idx_t nvtxs, idx_t *xadj, idx_t *adjncy, idx_t *vwgt, idx_t *adjwgt)
235 {
236   idx_t i, j;
237   FILE *fp;
238 
239   fp = fopen("test.graph", "w");
240 
241   fprintf(fp, "%"PRIDX" %"PRIDX" 11", nvtxs, xadj[nvtxs]/2);
242   for (i=0; i<nvtxs; i++) {
243     fprintf(fp, "\n%"PRIDX" ", vwgt[i]);
244     for (j=xadj[i]; j<xadj[i+1]; j++)
245       fprintf(fp, " %"PRIDX" %"PRIDX"", adjncy[j]+1, adjwgt[j]);
246   }
247   fclose(fp);
248 }
249 
250