00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <parmetislib.h>
00017
00018
00019
00020
00021
00022 void PrintVector(CtrlType *ctrl, int n, int first, idxtype *vec, char *title)
00023 {
00024 int i, penum;
00025
00026 for (penum=0; penum<ctrl->npes; penum++) {
00027 if (ctrl->mype == penum) {
00028 if (ctrl->mype == 0)
00029 printf("%s\n", title);
00030 printf("\t%3d. ", ctrl->mype);
00031 for (i=0; i<n; i++)
00032 printf("[%d %hd] ", first+i, vec[i]);
00033 printf("\n");
00034 fflush(stdout);
00035 }
00036 MPI_Barrier(ctrl->comm);
00037 }
00038 }
00039
00040
00041
00042
00043
00044 void PrintVector2(CtrlType *ctrl, int n, int first, idxtype *vec, char *title)
00045 {
00046 int i, penum;
00047
00048 for (penum=0; penum<ctrl->npes; penum++) {
00049 if (ctrl->mype == penum) {
00050 if (ctrl->mype == 0)
00051 printf("%s\n", title);
00052 printf("\t%3d. ", ctrl->mype);
00053 for (i=0; i<n; i++)
00054 printf("[%d %d.%hd] ", first+i, (vec[i]>=KEEP_BIT ? 1 : 0), (vec[i]>=KEEP_BIT ? vec[i]-KEEP_BIT : vec[i]));
00055 printf("\n");
00056 fflush(stdout);
00057 }
00058 MPI_Barrier(ctrl->comm);
00059 }
00060 }
00061
00062
00063
00064
00065
00066 void PrintPairs(CtrlType *ctrl, int n, KeyValueType *pairs, char *title)
00067 {
00068 int i, penum;
00069
00070 for (penum=0; penum<ctrl->npes; penum++) {
00071 if (ctrl->mype == penum) {
00072 if (ctrl->mype == 0)
00073 printf("%s\n", title);
00074 printf("\t%3d. ", ctrl->mype);
00075 for (i=0; i<n; i++)
00076 printf("[%d %hd,%hd] ", i, pairs[i].key, pairs[i].val);
00077 printf("\n");
00078 fflush(stdout);
00079 }
00080 MPI_Barrier(ctrl->comm);
00081 }
00082 }
00083
00084
00085
00086
00087
00088
00089
00090 void PrintGraph(CtrlType *ctrl, GraphType *graph)
00091 {
00092 int i, j, penum;
00093 int firstvtx;
00094
00095 MPI_Barrier(ctrl->comm);
00096
00097 firstvtx = graph->vtxdist[ctrl->mype];
00098
00099 for (penum=0; penum<ctrl->npes; penum++) {
00100 if (ctrl->mype == penum) {
00101 printf("\t%d", penum);
00102 for (i=0; i<graph->nvtxs; i++) {
00103 if (i==0)
00104 printf("\t%2d %2d\t", firstvtx+i, graph->vwgt[i]);
00105 else
00106 printf("\t\t%2d %2d\t", firstvtx+i, graph->vwgt[i]);
00107 for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)
00108 printf("[%d %d] ", graph->adjncy[j], graph->adjwgt[j]);
00109 printf("\n");
00110 }
00111 fflush(stdout);
00112 }
00113 MPI_Barrier(ctrl->comm);
00114 }
00115 }
00116
00117
00118
00119
00120
00121
00122 void PrintGraph2(CtrlType *ctrl, GraphType *graph)
00123 {
00124 int i, j, penum;
00125 int firstvtx;
00126
00127 MPI_Barrier(ctrl->comm);
00128
00129 firstvtx = graph->vtxdist[ctrl->mype];
00130
00131 for (penum=0; penum<ctrl->npes; penum++) {
00132 if (ctrl->mype == penum) {
00133 printf("\t%d", penum);
00134 for (i=0; i<graph->nvtxs; i++) {
00135 if (i==0)
00136 printf("\t%2d %2d [%d %d %d]\t", firstvtx+i, graph->vwgt[i], graph->where[i], graph->rinfo[i].id, graph->rinfo[i].ed);
00137 else
00138 printf("\t\t%2d %2d [%d %d %d]\t", firstvtx+i, graph->vwgt[i], graph->where[i], graph->rinfo[i].id, graph->rinfo[i].ed);
00139 for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)
00140 printf("[%d %d] ", graph->adjncy[j], graph->adjwgt[j]);
00141 printf("\n");
00142 }
00143 fflush(stdout);
00144 }
00145 MPI_Barrier(ctrl->comm);
00146 }
00147 }
00148
00149
00150
00151
00152
00153 void PrintSetUpInfo(CtrlType *ctrl, GraphType *graph)
00154 {
00155 int i, j, penum;
00156
00157 MPI_Barrier(ctrl->comm);
00158
00159 for (penum=0; penum<ctrl->npes; penum++) {
00160 if (ctrl->mype == penum) {
00161 printf("PE: %d, nnbrs: %d\n", ctrl->mype, graph->nnbrs);
00162 printf("\tSending...\n");
00163 for (i=0; i<graph->nnbrs; i++) {
00164 printf("\t\tTo: %d: ", graph->peind[i]);
00165 for (j=graph->sendptr[i]; j<graph->sendptr[i+1]; j++)
00166 printf("%d ", graph->sendind[j]);
00167 printf("\n");
00168 }
00169 printf("\tReceiving...\n");
00170 for (i=0; i<graph->nnbrs; i++) {
00171 printf("\t\tFrom: %d: ", graph->peind[i]);
00172 for (j=graph->recvptr[i]; j<graph->recvptr[i+1]; j++)
00173 printf("%d ", graph->recvind[j]);
00174 printf("\n");
00175 }
00176 printf("\n");
00177 }
00178 MPI_Barrier(ctrl->comm);
00179 }
00180
00181 }
00182
00183
00184
00185
00186
00187 void PrintTransferedGraphs(CtrlType *ctrl, int nnbrs, idxtype *peind, idxtype *slens,
00188 idxtype *rlens, idxtype *sgraph, idxtype *rgraph)
00189 {
00190 int i, ii, jj, ll, penum;
00191
00192 MPI_Barrier(ctrl->comm);
00193 for (penum=0; penum<ctrl->npes; penum++) {
00194 if (ctrl->mype == penum) {
00195 printf("PE: %d, nnbrs: %d", ctrl->mype, nnbrs);
00196 for (ll=i=0; i<nnbrs; i++) {
00197 if (slens[i+1]-slens[i] > 0) {
00198 printf("\n\tTo %d\t", peind[i]);
00199 for (ii=slens[i]; ii<slens[i+1]; ii++) {
00200 printf("%d %d %d, ", sgraph[ll], sgraph[ll+1], sgraph[ll+2]);
00201 for (jj=0; jj<sgraph[ll+1]; jj++)
00202 printf("[%d %d] ", sgraph[ll+3+2*jj], sgraph[ll+3+2*jj+1]);
00203 printf("\n\t\t");
00204 ll += 3+2*sgraph[ll+1];
00205 }
00206 }
00207 }
00208
00209 for (ll=i=0; i<nnbrs; i++) {
00210 if (rlens[i+1]-rlens[i] > 0) {
00211 printf("\n\tFrom %d\t", peind[i]);
00212 for (ii=rlens[i]; ii<rlens[i+1]; ii++) {
00213 printf("%d %d %d, ", rgraph[ll], rgraph[ll+1], rgraph[ll+2]);
00214 for (jj=0; jj<rgraph[ll+1]; jj++)
00215 printf("[%d %d] ", rgraph[ll+3+2*jj], rgraph[ll+3+2*jj+1]);
00216 printf("\n\t\t");
00217 ll += 3+2*rgraph[ll+1];
00218 }
00219 }
00220 }
00221 printf("\n");
00222 }
00223 MPI_Barrier(ctrl->comm);
00224 }
00225
00226 }
00227
00228
00229
00230
00231
00232 void WriteMetisGraph(int nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt)
00233 {
00234 int i, j;
00235 FILE *fp;
00236
00237 fp = fopen("test.graph", "w");
00238
00239 fprintf(fp, "%d %d 11", nvtxs, xadj[nvtxs]/2);
00240 for (i=0; i<nvtxs; i++) {
00241 fprintf(fp, "\n%d ", vwgt[i]);
00242 for (j=xadj[i]; j<xadj[i+1]; j++)
00243 fprintf(fp, " %d %d", adjncy[j]+1, adjwgt[j]);
00244 }
00245 fclose(fp);
00246 }
00247