00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <parmetislib.h>
00016
00017
00018
00019
00020
00021
00022
00023 void CSR_Match_SHEM(MatrixType *matrix, idxtype *match, idxtype *mlist,
00024 idxtype *skip, int ncon)
00025 {
00026 int h, i, ii, j;
00027 int nrows, edge, maxidx, count;
00028 floattype maxwgt;
00029 idxtype *rowptr, *colind;
00030 floattype *transfer;
00031 KVType *links;
00032
00033 nrows = matrix->nrows;
00034 rowptr = matrix->rowptr;
00035 colind = matrix->colind;
00036 transfer = matrix->transfer;
00037
00038 idxset(nrows, UNMATCHED, match);
00039
00040 links = (KVType *)GKmalloc(sizeof(KVType)*nrows, "links");
00041 for (i=0; i<nrows; i++) {
00042 links[i].key = i;
00043 links[i].val = 0.0;
00044 }
00045
00046 for (i=0; i<nrows; i++)
00047 for (j=rowptr[i]; j<rowptr[i+1]; j++)
00048 for (h=0; h<ncon; h++)
00049 if (links[i].val < fabs(transfer[j*ncon+h]))
00050 links[i].val = fabs(transfer[j*ncon+h]);
00051
00052 qsort(links, nrows, sizeof(KVType), myvalkeycompare);
00053
00054 count = 0;
00055 for (ii=0; ii<nrows; ii++) {
00056 i = links[ii].key;
00057
00058 if (match[i] == UNMATCHED) {
00059 maxidx = i;
00060 maxwgt = 0.0;
00061
00062
00063 for (j=rowptr[i]; j<rowptr[i+1]; j++) {
00064 edge = colind[j];
00065 if (match[edge] == UNMATCHED && edge != i && skip[j] == 0) {
00066 for (h=0; h<ncon; h++)
00067 if (maxwgt < fabs(transfer[j*ncon+h]))
00068 break;
00069
00070 if (h != ncon) {
00071 maxwgt = fabs(transfer[j*ncon+h]);
00072 maxidx = edge;
00073 }
00074 }
00075 }
00076
00077 if (maxidx != i) {
00078 match[i] = maxidx;
00079 match[maxidx] = i;
00080 mlist[count++] = amax(i, maxidx);
00081 mlist[count++] = amin(i, maxidx);
00082 }
00083 }
00084 }
00085
00086 GKfree((void **)&links, LTERM);
00087 }
00088