static void checkNotInstDeps(rpmts ts, depCache dcache, rpmte te, rpmTag depTag, const char *dep) { char *ndep = rmalloc(strlen(dep) + 2); ndep[0] = '!'; strcpy(ndep + 1, dep); checkInstDeps(ts, dcache, te, depTag, ndep); free(ndep); }
/* * Allocates an empty RedditLink structure */ EXPORT_SYMBOL RedditLink *redditLinkNew () { RedditLink *link = rmalloc(sizeof(RedditLink)); /* Just initialize everything as NULL or zero */ memset(link, 0, sizeof(RedditLink)); return link; }
// EmptyCrossCallProcedureTable creates an empty table. CrossCallProcedureTable EmptyCrossCallProcedureTable (void) { CrossCallProcedureTable ccpt = rmalloc (sizeof (struct _crosscallproceduretable)); ccpt->ccpt_size = 0; ccpt->ccpt_first = NULL; ccpt->ccpt_last = NULL; return ccpt; }
static void addDepToHash(depexistsHash hash, char *key, size_t keylen) { char *keystr; if (!keylen) return; keystr = rmalloc(keylen + 1); strncpy(keystr, key, keylen); keystr[keylen] = 0; depexistsHashAddEntry(hash, keystr); }
// NewCrossCallEntry creates a CrossCallEntry with cce_next field NULL. CrossCallEntry NewCrossCallEntry (int cce_code, CrossCallProcedure cce_proc) { CrossCallEntry cce = rmalloc (sizeof (struct _crosscallentry)); cce->cce_code = cce_code; cce->cce_proc = cce_proc; cce->cce_next = NULL; return cce; }
static void redditCommentAddMore (TokenParser *parser, RedditComment *parent) { int i; redditCommentFreeChildren(parent); parent->directChildrenCount = parser->tokens[parser->currentToken].full_size; parent->directChildrenIds = rmalloc(parent->directChildrenCount * sizeof(char*)); for (i = 0; i < parent->directChildrenCount; i++) { parser->currentToken++; parent->directChildrenIds[i] = getCopyOfToken(parser->block->memory, parser->tokens[parser->currentToken]); } }
// GetAppFileName used by OsThreadFunction only. static void GetAppFileName (void) { char path[MAX_PATH + 1]; int length, index; int start, end; BOOL newword; length = GetModuleFileName (NULL, path, MAX_PATH); for (index = length - 1; path[index] != '.'; index--) ; end = index - 1; for (index = end; path[index] != '/' && path[index] != '\\' && path[index] != ':'; index--) ; start = index + 1; if (end - start > 31) end = start + 31; if (end - start >= 0) { gAppName = rmalloc (end - start + 2); for (index = 0; index <= end - start; index++) gAppName[index] = path[start + index]; gAppName[index] = '\0'; } else { gAppName = "Clean Application"; } newword = TRUE; for (index = 0; gAppName[index] != '\0'; index++) { if (gAppName[index] >= 'A' && gAppName[index] <= 'Z' && !newword) gAppName[index] = gAppName[index] - ('A' - 'a'); if (gAppName[index] == ' ') newword = TRUE; else newword = FALSE; } }
/* SANDWICH: Catenate a prefix and suffix to a string. The result has an EOS but no length. Return 0 if the result if longer than LITLEN. */ UNCH *sandwich(UNCH *s, /* String, with EOS. */ UNCH *pref, /* Prefix, with length and EOS. */ UNCH *suff) /* Suffix, with length and EOS. */ { UNCH *pt; UNS slen, tlen; slen = ustrlen(s); tlen = slen + (*pref - 2) + (*suff - 2); if (tlen > LITLEN) return 0; pt = (UNCH *)rmalloc(tlen + 1); memcpy(pt, pref + 1, *pref - 2); memcpy(pt + (*pref - 2), s, slen); memcpy(pt + (*pref - 2) + slen, suff + 1, *suff - 1); return pt; }
/* * Finds a comment in the list of comments who's id matches the parentId we're looking for * Note: Only checks linear parents from directParent. Could be improved to check every reply in the true * But that could be heavy for larger trees. */ static RedditComment *redditCommentFindParent (RedditComment *base, char *parentId) { char pid[8]; RedditComment *current; int stackSize = 100; RedditComment **stack = rmalloc(sizeof(RedditComment*) * stackSize);; int top = 0; /* We might have, Ex. 't1_idvalu', we just want 'idvalu' from that */ if (parentId[2] == '_') strcpy(pid, parentId + 3); else strcpy(pid, parentId); stack[0] = base; top = 0; /* Keep looping and decrementing our stack index until it's under zero */ for(; top >= 0; top--) { /* Grab the RedditComment on the top of the stack */ current = stack[top]; /* If it's the right one, jump to the cleanup code */ if (strcmp(pid, current->id) == 0) goto cleanup; /* If it's not and it has some replies to it, add all the replies to * the stack and keep going */ if (current->replyCount > 0) { if (top + current->replyCount >= stackSize) { stackSize += current->replyCount; stack = realloc(stack, sizeof(RedditComment*) * stackSize); } /* Copy the contents of the replies array right onto the stack. */ memcpy(stack + top, current->replies, current->replyCount * sizeof(RedditComment*)); top += current->replyCount; } } current = NULL; cleanup:; free(stack); return current; }
VOID storedatt(PNE pne) { int i; NEAL(pne) = (struct ad *)rmalloc((1+ADN(al))*ADSZ); memcpy((UNIV)NEAL(pne), (UNIV)al, (1+ADN(al))*ADSZ); for (i = 1; i <= (int)ADN(al); i++) { if (GET(ADFLAGS(al, i), ASPEC)) ds.attdef += ADLEN(al, i); if (NEAL(pne)[i].addef != 0) NEAL(pne)[i].addef = savestr(NEAL(pne)[i].addef); } ds.attcnt += AN(al); /* Number of attributes defined. */ #if 0 /* I can't see any reason to increase AVGRPCNT here. */ ds.attgcnt += ADN(al) - AN(al); /* Number of att grp members. */ #endif }
END_TEST START_TEST(refcount_bad_release) { if(fork()) { int x; wait(&x); ck_assert_int_eq(WEXITSTATUS(x), BAD_REF_RELEASE); } else { void * x = rmalloc(2 * sizeof(int)); rrelease(x); rrelease(x); } }
/* Convert a tline array into an array of description pointers, writing the line out to a file */ descr_ptr *convert_qa(tline *qa) { int i; descr_ptr *qa_ptr; descr_line txt[2]; qa_ptr=rmalloc(sizeof(descr_ptr)*MaxQuestion); txt[1]=NULL; if (qa!=NULL) for(i=0;i<MaxQuestion;i++) { txt[0]=qa[i]; write_descr(&qa_ptr[i],txt); } else for(i=0;i<MaxQuestion;i++) { qa_ptr[i].start=0; qa_ptr[i].size=0; } return qa_ptr; }
static DFREE HUGE *dfree_new(void) { DFREE HUGE *d, HUGE *ca; register int i; FNAME(dfree_new); d = (DFREE HUGE *) rmalloc((MAX_SIZ_TYP) sizeof(DFREE)); if (!d) error(fun, "rmalloc"); for (i=0 ; i != DHEADSIZE ; ++i) { d->nfree[i] = 0L; d->diskaddr[i] = -1L; } d->next = NULL; if (DMflist) { for (ca=DMflist ; ca->next ; ca=ca->next); ca->next = d; } else DMflist = d; return(d); }
static void checkInstFileDeps(rpmts ts, depCache dcache, rpmte te, rpmTag depTag, rpmfi fi, int is_not, filedepHash cache, fingerPrintCache *fpcp) { fingerPrintCache fpc = *fpcp; fingerPrint * fp = NULL; const char *basename = rpmfiBN(fi); const char *dirname; const char **dirnames = 0; int ndirnames = 0; int i; filedepHashGetEntry(cache, basename, &dirnames, &ndirnames, NULL); if (!ndirnames) return; if (!fpc) *fpcp = fpc = fpCacheCreate(1001, NULL); dirname = rpmfiDN(fi); fpLookup(fpc, dirname, basename, &fp); for (i = 0; i < ndirnames; i++) { char *fpdep = 0; const char *dep; if (!strcmp(dirnames[i], dirname)) { dep = rpmfiFN(fi); } else if (fpLookupEquals(fpc, fp, dirnames[i], basename)) { fpdep = rmalloc(strlen(dirnames[i]) + strlen(basename) + 1); strcpy(fpdep, dirnames[i]); strcat(fpdep, basename); dep = fpdep; } else { continue; } if (!is_not) checkInstDeps(ts, dcache, te, depTag, dep); else checkNotInstDeps(ts, dcache, te, depTag, dep); _free(fpdep); } _free(fp); }
/************************************************************************* * Let the game begin **************************************************************************/ int main(int argc, char *argv[]) { idx_t i, j, npes, mype, optype, nparts, adptf, options[10]; idx_t *part=NULL, *sizes=NULL; graph_t graph; real_t ipc2redist, *xyz=NULL, *tpwgts=NULL, ubvec[MAXNCON]; MPI_Comm comm; idx_t numflag=0, wgtflag=0, ndims, edgecut; char xyzfilename[8192]; MPI_Init(&argc, &argv); MPI_Comm_dup(MPI_COMM_WORLD, &comm); gkMPI_Comm_size(comm, &npes); gkMPI_Comm_rank(comm, &mype); if (argc != 8) { if (mype == 0) printf("Usage: %s <graph-file> <op-type> <nparts> <adapth-factor> <ipc2redist> <dbglvl> <seed>\n", argv[0]); MPI_Finalize(); exit(0); } optype = atoi(argv[2]); nparts = atoi(argv[3]); adptf = atoi(argv[4]); ipc2redist = atof(argv[5]); options[0] = 1; options[PMV3_OPTION_DBGLVL] = atoi(argv[6]); options[PMV3_OPTION_SEED] = atoi(argv[7]); if (mype == 0) printf("reading file: %s\n", argv[1]); ParallelReadGraph(&graph, argv[1], comm); /* Remove the edges for testing */ /*iset(graph.vtxdist[mype+1]-graph.vtxdist[mype]+1, 0, graph.xadj); */ rset(graph.ncon, 1.05, ubvec); tpwgts = rmalloc(nparts*graph.ncon, "tpwgts"); rset(nparts*graph.ncon, 1.0/(real_t)nparts, tpwgts); /* ChangeToFortranNumbering(graph.vtxdist, graph.xadj, graph.adjncy, mype, npes); numflag = 1; nvtxs = graph.vtxdist[mype+1]-graph.vtxdist[mype]; nedges = graph.xadj[nvtxs]; printf("%"PRIDX" %"PRIDX"\n", isum(nvtxs, graph.xadj, 1), isum(nedges, graph.adjncy, 1)); */ if (optype >= 20) { sprintf(xyzfilename, "%s.xyz", argv[1]); xyz = ReadTestCoordinates(&graph, xyzfilename, &ndims, comm); } if (mype == 0) printf("finished reading file: %s\n", argv[1]); part = ismalloc(graph.nvtxs, mype%nparts, "main: part"); sizes = imalloc(2*npes, "main: sizes"); switch (optype) { case 1: wgtflag = 3; ParMETIS_V3_PartKway(graph.vtxdist, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, &wgtflag, &numflag, &graph.ncon, &nparts, tpwgts, ubvec, options, &edgecut, part, &comm); WritePVector(argv[1], graph.vtxdist, part, MPI_COMM_WORLD); break; case 2: wgtflag = 3; options[PMV3_OPTION_PSR] = PARMETIS_PSR_COUPLED; ParMETIS_V3_RefineKway(graph.vtxdist, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, &wgtflag, &numflag, &graph.ncon, &nparts, tpwgts, ubvec, options, &edgecut, part, &comm); WritePVector(argv[1], graph.vtxdist, part, MPI_COMM_WORLD); break; case 3: options[PMV3_OPTION_PSR] = PARMETIS_PSR_COUPLED; graph.vwgt = ismalloc(graph.nvtxs, 1, "main: vwgt"); if (npes > 1) { AdaptGraph(&graph, adptf, comm); } else { wgtflag = 3; ParMETIS_V3_PartKway(graph.vtxdist, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, &wgtflag, &numflag, &graph.ncon, &nparts, tpwgts, ubvec, options, &edgecut, part, &comm); printf("Initial partitioning with edgecut of %"PRIDX"\n", edgecut); for (i=0; i<graph.ncon; i++) { for (j=0; j<graph.nvtxs; j++) { if (part[j] == i) graph.vwgt[j*graph.ncon+i] = adptf; else graph.vwgt[j*graph.ncon+i] = 1; } } } wgtflag = 3; ParMETIS_V3_AdaptiveRepart(graph.vtxdist, graph.xadj, graph.adjncy, graph.vwgt, NULL, graph.adjwgt, &wgtflag, &numflag, &graph.ncon, &nparts, tpwgts, ubvec, &ipc2redist, options, &edgecut, part, &comm); break; case 4: ParMETIS_V3_NodeND(graph.vtxdist, graph.xadj, graph.adjncy, &numflag, options, part, sizes, &comm); /* WriteOVector(argv[1], graph.vtxdist, part, comm); */ break; case 5: ParMETIS_SerialNodeND(graph.vtxdist, graph.xadj, graph.adjncy, &numflag, options, part, sizes, &comm); /* WriteOVector(argv[1], graph.vtxdist, part, comm); */ printf("%"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX"\n", sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], sizes[5], sizes[6]); break; case 11: /* TestAdaptiveMETIS(graph.vtxdist, graph.xadj, graph.adjncy, part, options, adptf, comm); */ break; case 20: wgtflag = 3; ParMETIS_V3_PartGeomKway(graph.vtxdist, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, &wgtflag, &numflag, &ndims, xyz, &graph.ncon, &nparts, tpwgts, ubvec, options, &edgecut, part, &comm); break; case 21: ParMETIS_V3_PartGeom(graph.vtxdist, &ndims, xyz, part, &comm); break; } /* printf("%"PRIDX" %"PRIDX"\n", isum(nvtxs, graph.xadj, 1), isum(nedges, graph.adjncy, 1)); */ gk_free((void **)&part, &sizes, &tpwgts, &graph.vtxdist, &graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, &xyz, LTERM); MPI_Comm_free(&comm); MPI_Finalize(); return 0; }
/************************************************************************* * This function performs a k-way directed diffusion **************************************************************************/ real_t WavefrontDiffusion(ctrl_t *ctrl, graph_t *graph, idx_t *home) { idx_t ii, i, j, k, l, nvtxs, nedges, nparts; idx_t from, to, edge, done, nswaps, noswaps, totalv, wsize; idx_t npasses, first, second, third, mind, maxd; idx_t *xadj, *adjncy, *adjwgt, *where, *perm; idx_t *rowptr, *colind, *ed, *psize; real_t *transfer, *tmpvec; real_t balance = -1.0, *load, *solution, *workspace; real_t *nvwgt, *npwgts, flowFactor, cost, ubfactor; matrix_t matrix; ikv_t *cand; idx_t ndirty, nclean, dptr, clean; nvtxs = graph->nvtxs; nedges = graph->nedges; xadj = graph->xadj; nvwgt = graph->nvwgt; adjncy = graph->adjncy; adjwgt = graph->adjwgt; where = graph->where; nparts = ctrl->nparts; ubfactor = ctrl->ubvec[0]; matrix.nrows = nparts; flowFactor = 0.35; flowFactor = (ctrl->mype == 2) ? 0.50 : flowFactor; flowFactor = (ctrl->mype == 3) ? 0.75 : flowFactor; flowFactor = (ctrl->mype == 4) ? 1.00 : flowFactor; /* allocate memory */ solution = rmalloc(4*nparts+2*nedges, "WavefrontDiffusion: solution"); tmpvec = solution + nparts; npwgts = solution + 2*nparts; load = solution + 3*nparts; matrix.values = solution + 4*nparts; transfer = matrix.transfer = solution + 4*nparts + nedges; perm = imalloc(2*nvtxs+2*nparts+nedges+1, "WavefrontDiffusion: perm"); ed = perm + nvtxs; psize = perm + 2*nvtxs; rowptr = matrix.rowptr = perm + 2*nvtxs + nparts; colind = matrix.colind = perm + 2*nvtxs + 2*nparts + 1; /*GKTODO - Potential problem with this malloc */ wsize = gk_max(sizeof(real_t)*nparts*6, sizeof(idx_t)*(nvtxs+nparts*2+1)); workspace = (real_t *)gk_malloc(wsize, "WavefrontDiffusion: workspace"); cand = ikvmalloc(nvtxs, "WavefrontDiffusion: cand"); /*****************************/ /* Populate empty subdomains */ /*****************************/ iset(nparts, 0, psize); for (i=0; i<nvtxs; i++) psize[where[i]]++; mind = iargmin(nparts, psize); maxd = iargmax(nparts, psize); if (psize[mind] == 0) { for (i=0; i<nvtxs; i++) { k = (RandomInRange(nvtxs)+i)%nvtxs; if (where[k] == maxd) { where[k] = mind; psize[mind]++; psize[maxd]--; break; } } } iset(nvtxs, 0, ed); rset(nparts, 0.0, npwgts); for (i=0; i<nvtxs; i++) { npwgts[where[i]] += nvwgt[i]; for (j=xadj[i]; j<xadj[i+1]; j++) ed[i] += (where[i] != where[adjncy[j]] ? adjwgt[j] : 0); } ComputeLoad(graph, nparts, load, ctrl->tpwgts, 0); done = 0; /* zero out the tmpvec array */ rset(nparts, 0.0, tmpvec); npasses = gk_min(nparts/2, NGD_PASSES); for (l=0; l<npasses; l++) { /* Set-up and solve the diffusion equation */ nswaps = 0; /************************/ /* Solve flow equations */ /************************/ SetUpConnectGraph(graph, &matrix, (idx_t *)workspace); /* check for disconnected subdomains */ for(i=0; i<matrix.nrows; i++) { if (matrix.rowptr[i]+1 == matrix.rowptr[i+1]) { cost = (real_t)(ctrl->mype); goto CleanUpAndExit; } } ConjGrad2(&matrix, load, solution, 0.001, workspace); ComputeTransferVector(1, &matrix, solution, transfer, 0); GetThreeMax(nparts, load, &first, &second, &third); if (l%3 == 0) { FastRandomPermute(nvtxs, perm, 1); } else { /*****************************/ /* move dirty vertices first */ /*****************************/ ndirty = 0; for (i=0; i<nvtxs; i++) { if (where[i] != home[i]) ndirty++; } dptr = 0; for (i=0; i<nvtxs; i++) { if (where[i] != home[i]) perm[dptr++] = i; else perm[ndirty++] = i; } PASSERT(ctrl, ndirty == nvtxs); ndirty = dptr; nclean = nvtxs-dptr; FastRandomPermute(ndirty, perm, 0); FastRandomPermute(nclean, perm+ndirty, 0); } if (ctrl->mype == 0) { for (j=nvtxs, k=0, ii=0; ii<nvtxs; ii++) { i = perm[ii]; if (ed[i] != 0) { cand[k].key = -ed[i]; cand[k++].val = i; } else { cand[--j].key = 0; cand[j].val = i; } } ikvsorti(k, cand); } for (ii=0; ii<nvtxs/3; ii++) { i = (ctrl->mype == 0) ? cand[ii].val : perm[ii]; from = where[i]; /* don't move out the last vertex in a subdomain */ if (psize[from] == 1) continue; clean = (from == home[i]) ? 1 : 0; /* only move from top three or dirty vertices */ if (from != first && from != second && from != third && clean) continue; /* Scatter the sparse transfer row into the dense tmpvec row */ for (j=rowptr[from]+1; j<rowptr[from+1]; j++) tmpvec[colind[j]] = transfer[j]; for (j=xadj[i]; j<xadj[i+1]; j++) { to = where[adjncy[j]]; if (from != to) { if (tmpvec[to] > (flowFactor * nvwgt[i])) { tmpvec[to] -= nvwgt[i]; INC_DEC(psize[to], psize[from], 1); INC_DEC(npwgts[to], npwgts[from], nvwgt[i]); INC_DEC(load[to], load[from], nvwgt[i]); where[i] = to; nswaps++; /* Update external degrees */ ed[i] = 0; for (k=xadj[i]; k<xadj[i+1]; k++) { edge = adjncy[k]; ed[i] += (to != where[edge] ? adjwgt[k] : 0); if (where[edge] == from) ed[edge] += adjwgt[k]; if (where[edge] == to) ed[edge] -= adjwgt[k]; } break; } } } /* Gather the dense tmpvec row into the sparse transfer row */ for (j=rowptr[from]+1; j<rowptr[from+1]; j++) { transfer[j] = tmpvec[colind[j]]; tmpvec[colind[j]] = 0.0; } ASSERT(fabs(rsum(nparts, tmpvec, 1)) < .0001) } if (l % 2 == 1) { balance = rmax(nparts, npwgts)*nparts; if (balance < ubfactor + 0.035) done = 1; if (GlobalSESum(ctrl, done) > 0) break; noswaps = (nswaps > 0) ? 0 : 1; if (GlobalSESum(ctrl, noswaps) > ctrl->npes/2) break; } } graph->mincut = ComputeSerialEdgeCut(graph); totalv = Mc_ComputeSerialTotalV(graph, home); cost = ctrl->ipc_factor * (real_t)graph->mincut + ctrl->redist_factor * (real_t)totalv; CleanUpAndExit: gk_free((void **)&solution, (void **)&perm, (void **)&workspace, (void **)&cand, LTERM); return cost; }
HWND CreateCancelDialog(void) { HWND hwndButton,dlgHdl; WORD *p, *pdlgtemplate,baseunitX,baseunitY; int nchar; int scrnWidth,scrnHeight; int buttonX, buttonY, buttonWidth, buttonHeight; int textX, textY, textWidth, textHeight; DWORD lStyle,baseunits; HDC screen; LOGFONT lf; /* allocate some memory to play with */ pdlgtemplate = p = (PWORD) rmalloc (1000); screen = CreateDC ("DISPLAY", NULL, NULL, NULL); scrnWidth = GetDeviceCaps (screen, HORZRES); scrnHeight = GetDeviceCaps (screen, VERTRES); DeleteDC (screen); baseunits = GetDialogBaseUnits(); /* start to fill in the dlgtemplate information. addressing by WORDs */ lStyle = WS_CAPTION | DS_MODALFRAME | WS_SYSMENU; baseunitX=LOWORD(baseunits); baseunitY=HIWORD(baseunits); *p++ = LOWORD (lStyle); *p++ = HIWORD (lStyle); *p++ = 0; /* LOWORD (lExtendedStyle) */ *p++ = 0; /* HIWORD (lExtendedStyle) */ *p++ = 0; /* NumberOfItems */ *p++ = ((scrnWidth*4)/3)/baseunitX; // x *p++ = ((scrnHeight*8)/3)/baseunitY; // y *p++ = DIALOG_WIDTH; /* cx */ *p++ = DIALOG_HEIGHT; /* cy */ *p++ = 0; /* Menu */ *p++ = 0; /* Class */ /* copy the title of the dialog */ nchar = nCopyAnsiToWideChar (p, (char *) "Printing in Progress"); p += nchar; dlgHdl = CreateDialogIndirectParam (ghInst, (LPDLGTEMPLATE) pdlgtemplate, ghMainWindow, (DLGPROC) PrintDlgProc, (LPARAM) 0); rfree(pdlgtemplate); // Add a text field textWidth = 19*baseunitX; textHeight = baseunitY; textX = (((DIALOG_WIDTH*baseunitX)/4) - textWidth) / 2; textY = (((DIALOG_HEIGHT*baseunitY)/8) - textHeight) / 4; hwndText = CreateWindow ("static", "",WS_VISIBLE | WS_CHILD | SS_CENTER, textX, textY, textWidth, textHeight, dlgHdl, (HMENU) 0, ghInst, 0); // Add a Cancel button: buttonWidth = 10*baseunitX; buttonHeight = (3*baseunitY)/2; buttonX = (((DIALOG_WIDTH*baseunitX)/4) - buttonWidth) / 2; buttonY = (3 * (((DIALOG_HEIGHT*baseunitY)/8) - buttonHeight)) / 5; hwndButton = CreateWindow ("button", "Cancel", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, buttonX, buttonY, buttonWidth, buttonHeight, dlgHdl, (HMENU) 0, ghInst, 0); SetLogFontData (&lf,"MS Sans Serif",0,8); SendMessage(hwndButton,WM_SETFONT,(WPARAM)CreateFontIndirect (&lf),MAKELPARAM (TRUE,0)); SendMessage(hwndText,WM_SETFONT,(WPARAM)CreateFontIndirect (&lf),MAKELPARAM (TRUE,0)); ShowWindow (dlgHdl,SW_SHOWNORMAL); return dlgHdl; }
/************************************************************************* * This function extracts a subgraph from a graph given an indicator array. **************************************************************************/ graph_t *ExtractGraph(ctrl_t *ctrl, graph_t *graph, idx_t *indicator, idx_t *map, idx_t *rmap) { idx_t h, i, j; idx_t nvtxs, envtxs, enedges, ncon; idx_t vtx, count; idx_t *xadj, *vsize, *adjncy, *adjwgt, *where; idx_t *exadj, *evsize, *eadjncy, *eadjwgt, *ewhere; real_t *nvwgt, *envwgt; graph_t *egraph; nvtxs = graph->nvtxs; ncon = graph->ncon; xadj = graph->xadj; nvwgt = graph->nvwgt; vsize = graph->vsize; adjncy = graph->adjncy; adjwgt = graph->adjwgt; where = graph->where; count = 0; for (i=0; i<nvtxs; i++) { if (indicator[i] == 1) { map[count] = i; rmap[i] = count; count++; } } if (count == 0) return NULL; /*******************/ /* allocate memory */ /*******************/ egraph = CreateGraph(); envtxs = egraph->nvtxs = count; egraph->ncon = graph->ncon; exadj = egraph->xadj = imalloc(envtxs*3+1, "exadj"); ewhere = egraph->where = exadj + envtxs + 1; evsize = egraph->vsize = exadj + 2*envtxs + 1; envwgt = egraph->nvwgt = rmalloc(envtxs*ncon, "envwgt"); /************************************************/ /* compute xadj, where, nvwgt, and vsize arrays */ /************************************************/ iset(envtxs+1, 0, exadj); for (i=0; i<envtxs; i++) { vtx = map[i]; ewhere[i] = where[vtx]; for (h=0; h<ncon; h++) envwgt[i*ncon+h] = nvwgt[vtx*ncon+h]; if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) evsize[i] = vsize[vtx]; for (j=xadj[vtx]; j<xadj[vtx+1]; j++) if (indicator[adjncy[j]] == 1) exadj[i]++; } MAKECSR(i, envtxs, exadj); /************************************/ /* compute adjncy and adjwgt arrays */ /************************************/ enedges = egraph->nedges = exadj[envtxs]; eadjncy = egraph->adjncy = imalloc(enedges*2, "eadjncy"); eadjwgt = egraph->adjwgt = eadjncy + enedges; for (i=0; i<envtxs; i++) { vtx = map[i]; for (j=xadj[vtx]; j<xadj[vtx+1]; j++) { if (indicator[adjncy[j]] == 1) { eadjncy[exadj[i]] = rmap[adjncy[j]]; eadjwgt[exadj[i]++] = adjwgt[j]; } } } for (i=envtxs; i>0; i--) exadj[i] = exadj[i-1]; exadj[0] = 0; return egraph; }
/* * Creates a new blank list of comments */ EXPORT_SYMBOL RedditCommentList *redditCommentListNew () { RedditCommentList *list = rmalloc(sizeof(RedditCommentList)); memset(list, 0, sizeof(RedditCommentList)); return list; }
/* MDELEM: Process ELEMENT declaration. */ VOID mdelem(UNCH *tbuf) /* Work area for tokenization (tbuf). */ { UNCH *ranksuff = lbuf; /* Rank suffix. */ UNS dctype = 0; /* Declared content type (from dctab). */ UNCH fmin = 0; /* Minimization bit flags. */ int i; /* Loop counter. */ UNS u; /* Temporary variable. */ struct etd **mexgrp, **pexgrp; /* Ptr to model exceptions array. */ struct thdr *cmod, *cmodsv; /* Ptr to content model. */ UNCH *etdgi; /* GI of current etd (when going through group).*/ int minomitted = 0; /* Tag minimization parameters omitted. */ mdname = key[KELEMENT]; /* Identify declaration for messages. */ subdcl = NULL; /* No subject as yet. */ parmno = 0; /* No parameters as yet. */ mdessv = es; /* Save es level for entity nesting check. */ ranksuff[0] = 0; mexgrp = pexgrp = 0; /* PARAMETER 1: Element name or a group of them. */ parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); TRACEMD("1: element name or grp"); switch (pcbmd.action) { case NAS: nmgrp[0] = etddef(tbuf); nmgrp[1] = 0; break; case GRPS: parsegrp(nmgrp, &pcbgrnm, tbuf); break; default: mderr(121, (UNCH *)0, (UNCH *)0); return; } /* Save first GI for trace and error messages. */ if (nmgrp[0]) subdcl = nmgrp[0]->etdgi+1; /* PARAMETER 1A: Rank suffix (optional). */ parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); TRACEMD("1A: rank suffix"); switch (pcbmd.action) { case NUM: ustrcpy(ranksuff, tbuf); parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); default: break; } /* PARAMETER 2A: Start-tag minimization. */ TRACEMD("2A: start min"); switch (pcbmd.action) { case CDR: break; case NAS: if (!ustrcmp(tbuf+1, key[KO])) { if (OMITTAG==YES) SET(fmin, SMO); break; } /* fall through */ default: if (OMITTAG==NO) {minomitted=1; break;} mderr(129, tbuf+1, (UNCH *)0); return; } /* Must omit omitted end-tag minimization, if omitted start-tag minimization was omitted (because OMITTAG == NO). */ if (!minomitted) { /* PARAMETER 2B: End-tag minimization. */ parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); TRACEMD("2B: end min"); switch (pcbmd.action) { case NAS: if (ustrcmp(tbuf+1, key[KO])) {mderr(129, tbuf+1, (UNCH *)0); return;} if (OMITTAG==YES) SET(fmin, EMO); break; case CDR: SET(fmin, EMM); break; default: mderr(129, tbuf+1, (UNCH *)0); return; } /* PARAMETER 3: Declared content. */ parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); } TRACEMD("3: declared content"); switch (pcbmd.action) { case NAS: dctype = mapsrch(dctab, tbuf+1); if (!dctype) {mderr(24, tbuf+1, (UNCH *)0); return;} /* Eliminate incompatibilities among parameters. */ if (GET(fmin, SMO) && GET(dctype, MNONE+MCDATA+MRCDATA)) { mderr(58, (UNCH *)0, (UNCH *)0); RESET(fmin, SMO); } if (GET(dctype, MNONE) && BITON(fmin, EMM)) { mderr(87, (UNCH *)0, (UNCH *)0); SET(fmin, EMO); } /* If valid, process like a content model. */ case GRPS: cmodsv = parsemod((int)(pcbmd.action==GRPS ? 0 : dctype)); if (cmodsv==0) return; u = (dctype ? 1 : cmodsv->tu.tnum+2) * THSZ; cmod = (struct thdr *)rmalloc(u); memcpy((UNIV)cmod , (UNIV)cmodsv, u ); ds.modcnt += cmod->tu.tnum; TRACEMOD(cmod); break; default: mderr(130, (UNCH *)0, (UNCH *)0); return; } /* PARAMETERS 3A, 3B: Exceptions or end. */ parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); if (BITOFF(cmod->ttype, MCDATA+MRCDATA+MNONE)) { /* PARAMETER 3A: Minus exceptions. */ TRACEMD("3A: -grp"); switch (pcbmd.action) { case MGRP: /* We cheat and use nnmgrp for this. */ mexgrp = copygrp((PETD *)nnmgrp, u = parsegrp((PETD *)nnmgrp, &pcbgrnm, tbuf)); ++ds.pmexgcnt; ds.pmexcnt += u-1; TRACEGRP(mexgrp); parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); default: break; } /* PARAMETER 3B: Plus exceptions. */ TRACEMD("3B: +grp"); switch (pcbmd.action) { case PGRP: pexgrp = copygrp((PETD *)nnmgrp, u = parsegrp((PETD *)nnmgrp, &pcbgrnm, tbuf)); ++ds.pmexgcnt; ds.pmexcnt += u-1; TRACEGRP(pexgrp); parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); default: break; } } /* PARAMETER 4: End of declaration. */ TRACEMD(emd); if (pcbmd.action!=EMD) mderr(126, (UNCH *)0, (UNCH *)0); if (es!=mdessv) synerr(37, &pcbmd); /* EXECUTE: Store the definition for each element name specified. */ TRACEGRP(nmgrp); for (i = -1; nmgrp[++i];) { etdgi = nmgrp[i]->etdgi; if (*ranksuff) { if ((tbuf[0] = *etdgi + ustrlen(ranksuff)) - 2 > NAMELEN) { mderr(131, etdgi+1, ranksuff); continue; } memcpy(tbuf+1, etdgi+1, *etdgi-1); ustrcpy(tbuf+*etdgi-1, ranksuff); etdcan(etdgi); nmgrp[i] = etddef(tbuf); } if (nmgrp[i]->etdmod) {mderr(56, etdgi+1, (UNCH *)0); continue;} etdset(nmgrp[i], fmin+ETDDCL, cmod, mexgrp, pexgrp, nmgrp[i]->etdsrm); ++ds.etdcnt; if (nmgrp[i]->adl) etdadl(nmgrp[i]); /* Check ETD conflicts. */ TRACEETD(nmgrp[i]); } }
/* MDADL: Process ATTLIST declaration. */ VOID mdadl(UNCH *tbuf) /* Work area for tokenization (tbuf). */ { int i; /* Loop counter; temporary variable. */ int adlim; /* Number of unused ad slots in al. */ struct ad *alperm = 0; /* Attribute definition list. */ int stored = 0; mdname = key[KATTLIST]; /* Identify declaration for messages. */ subdcl = 0; /* No subject as yet. */ parmno = 0; /* No parameters as yet. */ mdessv = es; /* Save es level for entity nesting check. */ reqadn = noteadn = 0; /* No required attributes yet. */ idadn = conradn = 0; /* No special atts yet.*/ AN(al) = 0; /* Number of attributes defined. */ ADN(al) = 0; /* Number of ad's in al (atts + name vals).*/ /* PARAMETER 1: Element name or a group of them. */ parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); TRACEMD("1: element name or group"); switch (pcbmd.action) { case NAS: nmgrp[0] = etddef(tbuf); nmgrp[1] = 0; break; case GRPS: parsegrp(nmgrp, &pcbgrnm, tbuf); break; case RNS: /* Reserved name started. */ if (ustrcmp(tbuf+1, key[KNOTATION])) { mderr(118, tbuf+1, key[KNOTATION]); return; } mdnadl(tbuf); return; default: mderr(121, (UNCH *)0, (UNCH *)0); return; } /* Save first GI for error msgs. */ if (nmgrp[0]) subdcl = nmgrp[0]->etdgi+1; /* PARAMETER 2: Attribute definition list. */ parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); TRACEMD("2: attribute list"); if (pcbmd.action!=NAS) { mderr(120, (UNCH *)0, (UNCH *)0); return; } while (pcbmd.action==NAS) { al[ADN(al)+1].adname = savenm(tbuf); if ((adlim = ATTCNT-((int)++ADN(al)))<0) { mderr(111, (UNCH *)0, (UNCH *)0); adlfree(al, 1); return; } ++AN(al); if (mdattdef(adlim, 0)) { adlfree(al, 1); return; } parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); } if (AN(al)>0) { /* Save list only if 1 or more good atts. */ if (reqadn) SET(ADLF(al), ADLREQ); /* Element must have start-tag. */ if (noteadn) SET(ADLF(al), ADLNOTE); /* Element cannot be EMPTY. */ if (conradn) SET(ADLF(al), ADLCONR); /* Element cannot be EMPTY. */ alperm = (struct ad *)rmalloc((1+ADN(al))*ADSZ); memcpy((UNIV)alperm, (UNIV)al, (1+ADN(al))*ADSZ ); ds.attcnt += AN(al); /* Number of attributes defined. */ ds.attgcnt += ADN(al) - AN(al); /* Number of att grp members. */ TRACEADL(alperm); } /* Clear attribute list for next declaration. */ MEMZERO((UNIV)al, (1+ADN(al))*ADSZ); /* PARAMETER 3: End of declaration. */ /* Next pcb.action was set during attribute definition loop. */ TRACEMD(emd); if (pcbmd.action!=EMD) {mderr(126, (UNCH *)0, (UNCH *)0); return;} if (es!=mdessv) synerr(37, &pcbmd); /* EXECUTE: Store the definition for each element name specified. */ TRACEGRP(nmgrp); for (i = 0; nmgrp[i]; i++) { if (nmgrp[i]->adl) { /* Error if an ADL exists. */ mderr(112, (UNCH *)0, (UNCH *)0); continue; } nmgrp[i]->adl = alperm; /* If virgin, store the adl ptr. */ stored = 1; if (alperm && nmgrp[i]->etdmod) etdadl(nmgrp[i]); /* Check for conflicts with ETD. */ } if (!stored && alperm) { adlfree(alperm, 1); frem((UNIV)alperm); } }
/* MDATTDEF: Process an individual attribute definition. The attribute name is parsed by the caller. Duplicate attributes are parsed, but removed from list. Returns 0 if successful, otherwise returns 1. */ int mdattdef(int adlim, /* Remaining capacity of al (in tokens).*/ int datt) /* Non-zero if a data attribute. */ { int deftype; /* Default value type: 0=not keyword. */ int errsw = 0; /* 1=semantic error; ignore att. */ int novalsw = 0; /* 1=semantic error; treat as IMPLIED. */ int attadn = (int)ADN(al); /* Save ad number of this attribute. */ struct parse *grppcb = NULL; /* PCB for name/token grp parse. */ int errcode; /* Error type returned by PARSEVAL, ANMTGRP. */ UNCH *advalsv; /* Save area for permanent value ptr. */ /* PARAMETER 1: Attribute name (parsed by caller). */ TRACEMD("1: attribute name"); if (anmget((int)ADN(al)-1, al[attadn].adname)) { errsw = 1; mderr(99, ADNAME(al,attadn), (UNCH *)0); } ADNUM(al,attadn) = ADFLAGS(al,attadn) = ADLEN(al,attadn) = 0; ADVAL(al,attadn) = 0; ADDATA(al,attadn).x = 0; ADTYPE(al,attadn) = ANMTGRP; /* PARAMETER 2: Declared value. */ parsemd(lbuf, NAMECASE, &pcblitp, NAMELEN); TRACEMD("2: declared value"); switch (pcbmd.action) { case NAS: /* Keyword for value type. */ switch (ADTYPE(al,attadn) = (UNCH)mapsrch(dvtab, lbuf+1)) { case 0: mderr(100, ADNAME(al,attadn), lbuf+1); return 1; case ANOTEGRP: if (datt) { errsw = 1; mderr(156, (UNCH *)0, (UNCH *)0); } else if (!noteadn) noteadn = ADN(al); else { errsw = 1; mderr(101, ADNAME(al,attadn), (UNCH *)0); } grppcb = &pcbgrnm; /* NOTATION requires name grp. */ parsemd(lbuf, NAMECASE, &pcblitp, NAMELEN);/* Get GRPO*/ break; case AID: if (datt) { errsw = 1; mderr(144, (UNCH *)0, (UNCH *)0); } else if (!idadn) idadn = attadn; else { errsw = 1; mderr(102, ADNAME(al,attadn), (UNCH *)0); } break; case AIDREF: case AIDREFS: if (datt) { errsw = 1; mderr(155, (UNCH *)0, (UNCH *)0); } break; case AENTITY: case AENTITYS: if (datt) { errsw = 1; mderr(154, (UNCH *)0, (UNCH *)0); } break; } break; case GRPS: grppcb = &pcbgrnt; /* Normal grp is name token grp. */ break; case EMD: mderr(103, ADNAME(al,attadn), (UNCH *)0); return 1; default: mderr(104, ADNAME(al,attadn), (UNCH *)0); return 1; } /* PARAMETER 2A: Name token group. */ if (grppcb != NULL) { TRACEMD("2A: name group"); switch (pcbmd.action) { case GRPS: /* Name token list. */ SET(ADFLAGS(al,attadn), AGROUP); /* Call routine to parse group, create ad entries in adl. */ errcode = anmtgrp(grppcb, al+attadn, (GRPCNT<adlim ? GRPCNT+1 : adlim+1), &al[attadn].adnum, ADN(al)); if (errcode<=0) { if (adlim < GRPCNT) mderr(111, (UNCH *)0, (UNCH *)0); else mderr(105, ADNAME(al,attadn), (UNCH *)0); return 1; } ADN(al) += ADNUM(al,attadn); /* Add grp size to total ad cnt.*/ break; default: mderr(106, ADNAME(al,attadn), (UNCH *)0); return 1; } } /* PARAMETER 3: Default value keyword. */ parsemd(lbuf, AVALCASE, (ADTYPE(al,attadn)==ACHARS) ? &pcblitr : &pcblitt, LITLEN); TRACEMD("3: default keyword"); switch (pcbmd.action) { case RNS: /* Keyword. */ deftype = mapsrch(deftab, lbuf+1); switch (deftype) { case DFIXED: /* FIXED */ SET(ADFLAGS(al,attadn), AFIXED); parsemd(lbuf, AVALCASE, (ADTYPE(al,attadn)==ACHARS) ? &pcblitr : &pcblitt, LITLEN); /* Real default. */ goto parm3x; /* Go process specified value. */ case DCURR: /* CURRENT: If ID, treat as IMPLIED. */ if (ADTYPE(al,attadn)==AID) { mderr(80, ADNAME(al,attadn), (UNCH *)0); break; } if (datt) { mderr(157, (UNCH *)0, (UNCH *)0); break; } SET(ADFLAGS(al,attadn), ACURRENT); break; case DREQ: /* REQUIRED */ SET(ADFLAGS(al,attadn), AREQ); ++reqadn; break; case DCONR: /* CONREF */ if (ADTYPE(al,attadn)==AID) { mderr(107, ADNAME(al,attadn), (UNCH *)0); break; } if (datt) { mderr(158, (UNCH *)0, (UNCH *)0); break; } SET(ADFLAGS(al,attadn), ACONREF); conradn = 1; case DNULL: /* IMPLIED */ break; default: /* Unknown keyword is an error. */ mderr(108, ADNAME(al,attadn), lbuf+1); errsw = 1; } if (errsw) { /* Ignore erroneous att. */ adlfree(al, attadn); --AN(al); ADN(al) = (UNCH)attadn-1; } return(0); default: break; } /* PARAMETER 3x: Default value (non-keyword). */ parm3x: TRACEMD("3x: default (non-keyword)"); if (ADTYPE(al,attadn)==AID) { /* If ID, treat as IMPLIED. */ mderr(81, ADNAME(al,attadn), (UNCH *)0); novalsw = 1; /* Keep parsing to keep things straight. */ } switch (pcbmd.action) { case LIT: /* Literal. */ case LITE: /* Literal. */ /* Null string (except CDATA) is error: msg and treat as IMPLIED. */ if (*lbuf == '\0' && ADTYPE(al,attadn)!=ACHARS) { mderr(82, ADNAME(al,attadn), (UNCH *)0); novalsw = 1; } break; case NAS: /* Name character string. */ case NMT: /* Name character string. */ case NUM: /* Number or number token string. */ /* The name won't have a length byte because AVALCASE was specified. */ break; case CDR: parsetkn(lbuf, NMC, LITLEN); break; case EMD: mderr(109, ADNAME(al,attadn), (UNCH *)0); return 1; default: mderr(110, ADNAME(al,attadn), (UNCH *)0); return 1; } if (errsw) { /* Ignore erroneous att. */ adlfree(al, attadn); --AN(al); ADN(al) = (UNCH)attadn-1; return(0); } if (novalsw) return(0); /* PARAMETER 3y: Validate and store default value. */ if (ADTYPE(al,attadn)==ACHARS) { UNS len = vallen(ACHARS, 0, lbuf); if (len > LITLEN) { /* Treat as implied. */ sgmlerr(224, &pcbmd, ADNAME(al,attadn), (UNCH *)0); return 0; } /* No more checking for CDATA value. */ ADNUM(al,attadn) = 0; /* CDATA is 0 tokens. */ ADVAL(al,attadn) = savestr(lbuf);/* Store default; save ptr. */ ADLEN(al,attadn) = len; ds.attdef += len; return 0; } /* Parse value and save token count (GROUP implies 1 token). */ advalsv = (UNCH *)rmalloc(ustrlen(lbuf)+2); /* Storage for tokenized value. */ errcode = parseval(lbuf, (UNS)ADTYPE(al,attadn), advalsv); if (BITOFF(ADFLAGS(al,attadn), AGROUP)) ADNUM(al,attadn) = (UNCH)tokencnt; /* If value was invalid, or was a group member that was not in the group, issue an appropriate message and set the error switch. */ if (errcode) {sgmlerr((UNS)errcode, &pcbmd, ADNAME(al,attadn), lbuf); errsw = 1;} else if ( BITON(ADFLAGS(al,attadn), AGROUP) && !amemget(&al[attadn], (int)ADNUM(al,attadn), advalsv) ) { sgmlerr(79, &pcbmd, ADNAME(al,attadn), advalsv+1); errsw = 1; } ADLEN(al,attadn) = vallen(ADTYPE(al,attadn), ADNUM(al,attadn), advalsv); if (ADLEN(al,attadn) > LITLEN) { sgmlerr(224, &pcbmd, ADNAME(al,attadn), (UNCH *)0); ADLEN(al,attadn) = 0; errsw = 1; } /* For valid tokenized value, save it and update statistics. */ if (!errsw) { ADVAL(al,attadn) = advalsv; ds.attdef += ADLEN(al,attadn); return 0; } /* If value was bad, free the value's storage and treat as IMPLIED or REQUIRED. */ frem((UNIV)advalsv); /* Release storage for value. */ ADVAL(al,attadn) = NULL; /* And make value NULL. */ return 0; }
/* MDNADL: Process ATTLIST declaration for notation. TO DO: Pass deftab and dvtab as parameters so that prohibited types can be handled by leaving them out of the tables. */ VOID mdnadl(UNCH *tbuf) /* Work area for tokenization (tbuf). */ { int i; /* Loop counter; temporary variable. */ int adlim; /* Number of unused ad slots in al. */ struct ad *alperm = 0; /* Attribute definition list. */ int stored = 0; /* PARAMETER 1: Notation name or a group of them. */ parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); TRACEMD("1: notation name or group"); switch (pcbmd.action) { case NAS: nnmgrp[0] = dcndef(tbuf); nnmgrp[1] = 0; break; case GRPS: parsngrp(nnmgrp, &pcbgrnm, tbuf); break; default: mderr(121, (UNCH *)0, (UNCH *)0); return; } subdcl = nnmgrp[0]->ename+1; /* Save first name for error msgs. */ /* PARAMETER 2: Attribute definition list. */ parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); TRACEMD("2: attribute list"); if (pcbmd.action!=NAS) { mderr(120, (UNCH *)0, (UNCH *)0); return; } while (pcbmd.action==NAS) { al[ADN(al)+1].adname = savenm(tbuf); if ((adlim = ATTCNT-((int)ADN(al)++))<0) { mderr(111, (UNCH *)0, (UNCH *)0); adlfree(al, 1); return; } ++AN(al); if (mdattdef(adlim, 1)) { adlfree(al, 1); return; } parsemd(tbuf, NAMECASE, &pcblitp, NAMELEN); } if (AN(al)>0) { /* Save list only if 1 or more good atts. */ alperm = (struct ad *)rmalloc((1+ADN(al))*ADSZ); memcpy((UNIV)alperm, (UNIV)al, (1+ADN(al))*ADSZ ); ds.attcnt += AN(al); /* Number of attributes defined. */ ds.attgcnt += ADN(al) - AN(al); /* Number of att grp members. */ TRACEADL(alperm); } /* Clear attribute list for next declaration. */ MEMZERO((UNIV)al, (1+ADN(al))*ADSZ); /* PARAMETER 3: End of declaration. */ /* Next pcb.action was set during attribute definition loop. */ TRACEMD(emd); if (pcbmd.action!=EMD) {mderr(126, (UNCH *)0, (UNCH *)0); return;} if (es!=mdessv) synerr(37, &pcbmd); /* EXECUTE: Store the definition for each notation name specified. */ TRACENGR(nnmgrp); for (i = 0; nnmgrp[i]; i++) { if (nnmgrp[i]->adl) { /* Error if an ADL exists. */ mderr(112, (UNCH *)0, (UNCH *)0); continue; } nnmgrp[i]->adl = alperm; /* If virgin, store the adl ptr. */ if (nnmgrp[i]->entsw) fixdatt(nnmgrp[i]); stored = 1; TRACEDCN(nnmgrp[i]); } if (!stored && alperm) { adlfree(alperm, 1); frem((UNIV)alperm); } }
ctrl_t *SetupCtrl(moptype_et optype, idx_t *options, idx_t ncon, idx_t nparts, real_t *tpwgts, real_t *ubvec) { idx_t i, j; ctrl_t *ctrl; ctrl = (ctrl_t *)gk_malloc(sizeof(ctrl_t), "SetupCtrl: ctrl"); memset((void *)ctrl, 0, sizeof(ctrl_t)); switch (optype) { case METIS_OP_PMETIS: ctrl->objtype = GETOPTION(options, METIS_OPTION_OBJTYPE, METIS_OBJTYPE_CUT); ctrl->ctype = GETOPTION(options, METIS_OPTION_CTYPE, METIS_CTYPE_SHEM); ctrl->rtype = METIS_RTYPE_FM; ctrl->ncuts = GETOPTION(options, METIS_OPTION_NCUTS, 1); ctrl->niter = GETOPTION(options, METIS_OPTION_NITER, 10); ctrl->seed = GETOPTION(options, METIS_OPTION_SEED, -1); ctrl->dbglvl = GETOPTION(options, METIS_OPTION_DBGLVL, 0); if (ncon == 1) { ctrl->iptype = GETOPTION(options, METIS_OPTION_IPTYPE, METIS_IPTYPE_GROW); ctrl->ufactor = GETOPTION(options, METIS_OPTION_UFACTOR, PMETIS_DEFAULT_UFACTOR); ctrl->CoarsenTo = 20; } else { ctrl->iptype = GETOPTION(options, METIS_OPTION_IPTYPE, METIS_IPTYPE_RANDOM); ctrl->ufactor = GETOPTION(options, METIS_OPTION_UFACTOR, MCPMETIS_DEFAULT_UFACTOR); ctrl->CoarsenTo = 100; } break; case METIS_OP_KMETIS: ctrl->objtype = GETOPTION(options, METIS_OPTION_OBJTYPE, METIS_OBJTYPE_CUT); ctrl->ctype = GETOPTION(options, METIS_OPTION_CTYPE, METIS_CTYPE_SHEM); ctrl->iptype = METIS_IPTYPE_METISRB; ctrl->rtype = METIS_RTYPE_GREEDY; ctrl->ncuts = GETOPTION(options, METIS_OPTION_NCUTS, 1); ctrl->niter = GETOPTION(options, METIS_OPTION_NITER, 10); ctrl->ufactor = GETOPTION(options, METIS_OPTION_UFACTOR, KMETIS_DEFAULT_UFACTOR); ctrl->minconn = GETOPTION(options, METIS_OPTION_MINCONN, 0); ctrl->contig = GETOPTION(options, METIS_OPTION_CONTIG, 0); ctrl->seed = GETOPTION(options, METIS_OPTION_SEED, -1); ctrl->dbglvl = GETOPTION(options, METIS_OPTION_DBGLVL, 0); break; case METIS_OP_OMETIS: ctrl->objtype = GETOPTION(options, METIS_OPTION_OBJTYPE, METIS_OBJTYPE_NODE); ctrl->ctype = GETOPTION(options, METIS_OPTION_CTYPE, METIS_CTYPE_SHEM); ctrl->rtype = GETOPTION(options, METIS_OPTION_RTYPE, METIS_RTYPE_SEP1SIDED); ctrl->iptype = GETOPTION(options, METIS_OPTION_IPTYPE, METIS_IPTYPE_EDGE); ctrl->nseps = GETOPTION(options, METIS_OPTION_NSEPS, 1); ctrl->niter = GETOPTION(options, METIS_OPTION_NITER, 10); ctrl->ufactor = GETOPTION(options, METIS_OPTION_UFACTOR, OMETIS_DEFAULT_UFACTOR); ctrl->compress = GETOPTION(options, METIS_OPTION_COMPRESS, 1); ctrl->ccorder = GETOPTION(options, METIS_OPTION_CCORDER, 0); ctrl->seed = GETOPTION(options, METIS_OPTION_SEED, -1); ctrl->dbglvl = GETOPTION(options, METIS_OPTION_DBGLVL, 0); ctrl->pfactor = 0.1*GETOPTION(options, METIS_OPTION_PFACTOR, 0); ctrl->CoarsenTo = 100; break; default: gk_errexit(SIGERR, "Unknown optype of %d\n", optype); } ctrl->numflag = GETOPTION(options, METIS_OPTION_NUMBERING, 0); ctrl->optype = optype; ctrl->ncon = ncon; ctrl->nparts = nparts; ctrl->maxvwgt = ismalloc(ncon, 0, "SetupCtrl: maxvwgt"); /* setup the target partition weights */ if (ctrl->optype != METIS_OP_OMETIS) { ctrl->tpwgts = rmalloc(nparts*ncon, "SetupCtrl: ctrl->tpwgts"); if (tpwgts) { rcopy(nparts*ncon, tpwgts, ctrl->tpwgts); } else { for (i=0; i<nparts; i++) { for (j=0; j<ncon; j++) ctrl->tpwgts[i*ncon+j] = 1.0/nparts; } } } else { /* METIS_OP_OMETIS */ /* this is required to allow the pijbm to be defined properly for the edge-based refinement during initial partitioning */ ctrl->tpwgts = rsmalloc(2, .5, "SetupCtrl: ctrl->tpwgts"); } /* setup the ubfactors */ ctrl->ubfactors = rsmalloc(ctrl->ncon, I2RUBFACTOR(ctrl->ufactor), "SetupCtrl: ubfactors"); if (ubvec) rcopy(ctrl->ncon, ubvec, ctrl->ubfactors); for (i=0; i<ctrl->ncon; i++) ctrl->ubfactors[i] += 0.0000499; /* Allocate memory for balance multipliers. Note that for PMETIS/OMETIS routines the memory allocated is more than required as balance multipliers for 2 parts is sufficient. */ ctrl->pijbm = rmalloc(nparts*ncon, "SetupCtrl: ctrl->pijbm"); InitRandom(ctrl->seed); IFSET(ctrl->dbglvl, METIS_DBG_INFO, PrintCtrl(ctrl)); if (!CheckParams(ctrl)) { FreeCtrl(&ctrl); return NULL; } else { return ctrl; } }
int VM_rest(char *f) { short mb; register int i, b; VMPTR p; int h, s = (sizeof(VMHEAD) * VMLEGSIZ); VMHEAD HUGE *v; char HUGE *t; FNAME(VM_rest); TEST(fun, 0); VM_end(); VM_init(); h = OPEN(f, O_RDONLY | O_BINARY); if (h == -1) return(1); if (sizeof(VMfree) != read(h, (char *) &VMfree, sizeof(VMfree))) { rest_clean(1, h, -1, -1); return(2); } if (sizeof(mb) != read(h, (char *) &mb, sizeof(mb))) { rest_clean(1, h, -1, -1); return(2); } for (i=0 ; i != mb ; ++i) { VMbase[i] = (VMHEAD HUGE *) rmalloc((MAX_SIZ_TYP) s); if (!VMbase[i]) { rest_clean(2, h, -1, -1); return(3); } if (s != read(h, (char HUGE *) VMbase[i], s)) { rest_clean(2, h, -1, -1); return(2); } } for (b=0 ; b != mb ; ++b) { v = VMbase[b]; for (i=b?0:1 ; i != VMLEGSIZ ; ++i) { if (v[i].type != MT_NOTUSED && !(v[i].type & MT_IMEDIATE)) VMtotal += v[i].size; if (v[i].type != MT_NOTUSED && (!(v[i].type & MT_DISK) || v[i].diskadd != -1L)) VMlive++; if (v[i].type & MT_MEMORY || v[i].type & MT_DISK && v[i].diskadd != -1L) { v[i].type = MT_MEMORY | MT_DIRTY; if (!(t = rmalloc(v[i].size))) { rest_clean(3, h, b, i); return(3); } /* this must be done because rmalloc calls compact which may change the address of VMbase[x] */ v = VMbase[b]; v[i].mem = t; if ((long) v[i].size != longread(h, v[i].mem, (long) v[i].size)) { rest_clean(3, h, b, i+1); return(2); } p.p.b = b; p.p.l = i; vm_link(&v[i], p.i); v[i].diskadd = -1L; } } } if (-1 == close(h)) error(fun, "close"); TEST(fun, 1); return(0); }
void * rcalloc(size_t size, size_t count) { return rmalloc(size * count); }
/* MDENTITY: Process ENTITY declaration. */ VOID mdentity(UNCH *tbuf) /* Work area for tokenization[LITLEN+2]. */ { struct fpi fpicb; /* Formal public identifier structure. */ struct fpi *fpis = &fpicb; /* Ptr to current or #DEFAULT fpi. */ union etext etx; /* Ptr to entity text. */ UNCH estore = ESM; /* Entity storage class. */ struct entity *ecb; /* Ptr to entity control block. */ int parmsw = 0; /* 1=parameter entity declaration; 0 = not. */ int defltsw = 0; /* 1=#DEFAULT declaration; 0=not. */ PNE pne = 0; /* Ptr to N/C/SDATA entity control block. */ mdname = key[KENTITY]; /* Declaration name for messages. */ subdcl = NULL; /* No subject as yet. */ parmno = 0; /* No parameters as yet. */ mdessv = es; /* Save es for checking entity nesting. */ /* PARAMETER 1: Entity name. */ pcbmd.newstate = 0; parsemd(nmbuf, ENTCASE, &pcblitp, NAMELEN); TRACEMD("1: entity nm"); switch (pcbmd.action) { case PEN: parsemd(nmbuf + 1, ENTCASE, &pcblitp, NAMELEN); if (pcbmd.action!=NAS) {mderr(120, (UNCH *)0, (UNCH *)0); return;} if (nmbuf[1] == NAMELEN + 2) { /* It was too long. */ nmbuf[0] = NAMELEN + 2; nmbuf[NAMELEN + 1] = '\0'; mderr(65, (UNCH *)0, (UNCH *)0); } else nmbuf[0] = nmbuf[1] + 1; /* Increment length for PERO. */ nmbuf[1] = lex.d.pero; /* Prefix PERO to name. */ parmsw = 1; /* Indicate parameter entity. */ case NAS: break; case RNS: /* Reserved name started. */ if (ustrcmp(nmbuf+1, key[KDEFAULT])) { mderr(118, nmbuf+1, key[KDEFAULT]); return; } memcpy(nmbuf, indefent, *indefent);/* Copy #DEFAULT to name buffer. */ fpis = &fpidf; /* Use #DEFAULT fpi if external. */ defltsw = 1; /* Indicate #DEFAULT is being defined.*/ break; default: mderr(122, (UNCH *)0, (UNCH *)0); return; } subdcl = nmbuf+1; /* Subject name for error messages. */ /* PARAMETER 2: Entity text keyword (optional). */ pcbmd.newstate = 0; parsemd(tbuf, NAMECASE, &pcblitp, LITLEN); TRACEMD("2: keyword"); switch (pcbmd.action) { case NAS: if ((estore = (UNCH)mapsrch(enttab, tbuf+1))==0) { estore = parmsw ? ESP : ESF; pne = (PNE)rmalloc(NESZ); if (mdextid(tbuf, fpis, nmbuf+1+parmsw, &estore, pne)==0) return; if (defltsw) etx.x = NULL; else if ((etx.x = entgen(&fpicb))==0) { if (parmsw) mderr(148, nmbuf+2, (UNCH *)0); else mderr(147, nmbuf+1, (UNCH *)0); } goto parm4; } if (parmsw && (estore==ESX || estore==ESC)) { mderr(38, tbuf+1, (UNCH *)0); estore = ESM; } pcbmd.newstate = 0; parsemd(tbuf, NAMECASE, &pcblitp, LITLEN); break; default: estore = ESM; break; } /* PARAMETER 3: Parameter literal. */ TRACEMD("3: literal"); switch (pcbmd.action) { case LITE: case LIT: switch (estore) { case ESM: /* LITERAL: parameter literal required. */ case ESC: /* CDATA: parameter literal required. */ case ESX: /* SDATA: parameter literal required. */ case ESI: /* PI: parameter literal required. */ etx.c = savestr(tbuf); break; case ESMD: /* MD: parameter literal required. */ etx.c = sandwich(tbuf, lex.m.mdo, lex.m.mdc); goto bcheck; case ESMS: /* MS: parameter literal required. */ etx.c = sandwich(tbuf, lex.m.mss, lex.m.mse); goto bcheck; case ESS: /* STARTTAG: parameter literal required. */ etx.c = sandwich(tbuf, lex.m.stag, lex.m.tagc); goto bcheck; case ESE: /* ENDTAG: parameter literal required. */ etx.c = sandwich(tbuf, lex.m.etag, lex.m.tagc); bcheck: if (etx.c == 0) { mderr(225, (UNCH *)0, (UNCH *)0); return; } break; } break; default: mderr(123, (UNCH *)0, (UNCH *)0); return; } /* PARAMETER 4: End of declaration. */ pcbmd.newstate = 0; parsemd(tbuf, NAMECASE, &pcblitp, LITLEN); parm4: TRACEMD(emd); if (pcbmd.action!=EMD) mderr(126, (UNCH *)0, (UNCH *)0); if (es!=mdessv) synerr(37, &pcbmd); /* EXECUTE: If the entity already exists, ignore the new definition. If it is a new entity, store the definition. */ if ((ecb = entfind(nmbuf))!=0 && ecb->estore) { if (ecb->dflt) { mderr(228, nmbuf + 1, (UNCH *)0); hout((THASH)etab, nmbuf, hash(nmbuf, ENTHASH)); if (ecb->estore == ESN) { frem((UNIV)NEID(ecb->etx.n)); frem((UNIV)ecb->etx.n); } else if (ecb->estore >= ESFM) frem((UNIV)ecb->etx.x); frem((UNIV)ecb); } else { /* Duplicate definition: not an error. */ if (sw.swdupent) mderr(68, nmbuf+1, (UNCH *)0); if (estore<ESFM) frem((UNIV)etx.c); return; } } ++ds.ecbcnt; /* Do capacity before NOTATION. */ ds.ecbtext += estore<ESFM ? ustrlen(etx.c) : entlen; ecb = entdef(nmbuf, estore, &etx); /* Define the entity. */ if (estore==ESN) { /* If entity is external: */ NEENAME(pne) = ecb->ename; /* Store entity name in ne. */ NEID(pne) = etx.x; /* Store system fileid in ne. */ NESYSID(pne) = fpis->fpisysis ? savestr(fpis->fpisysis) : 0; NEPUBID(pne) = fpis->fpipubis ? savestr(fpis->fpipubis) : 0; ecb->etx.n = pne; /* Store ne control block in etx. */ TRACEESN(pne); } else if (pne) frem((UNIV)pne); if (defltsw) { ecbdeflt = ecb; /* If #DEFAULT save ecb. */ if (fpidf.fpipubis) fpidf.fpipubis = savestr(fpidf.fpipubis); if (fpidf.fpisysis) fpidf.fpisysis = savestr(fpidf.fpisysis); } }
/* The callback routine for the main window. PA: The WM_CREATE message registers the main window as a clipboard viewer. The WM_DESTROY message unregisters the main window. */ static LRESULT CALLBACK MainWindowProcedure (HWND hWin, UINT uMess, WPARAM wPara, LPARAM lPara) { switch (uMess) { case WM_NCPAINT: break; /* WM_ENTERIDLE message is used to let Clean evaluate the initialisation action of a modal dialog by sending the CcWmIDLEDIALOG message. */ case WM_ENTERIDLE: { HWND hwndModalDialog; hwndModalDialog = (HWND)lPara; if (wPara == MSGF_DIALOGBOX && hwndModalDialog != ghwndLastModalDialog) { SendMessage1ToClean (CcWmIDLEDIALOG,(int)hwndModalDialog); ghwndLastModalDialog = hwndModalDialog; } else { SendMessage0ToClean (CcWmIDLETIMER); } return 0; } break; case WM_TIMER: { SendMessage2ToClean (CcWmTIMER, wPara, GetMessageTime ()); } break; case WM_ENABLE: { HWND hwin; char title[64]; hwin = GetWindow (ghMainWindow, GW_HWNDFIRST); while (hwin != NULL) { GetWindowText (hwin, title, 63); if (GetWindow (hwin, GW_OWNER) == ghMainWindow) { RECT r; GetWindowRect (hwin, &r); if (r.top != -1 || r.left != -1 || r.right != 0 || r.bottom != 0) { EnableWindow (hwin, (BOOL) wPara); } } hwin = GetWindow (hwin, GW_HWNDNEXT); } } break; /* PM_SOCKET_EVENT and PM_DNS_EVENT are intercepted by MainWindowProcedure. If ghTCPWindow != NULL, then these messages are passed on to ghTCPWindow. */ case PM_SOCKET_EVENT: case PM_DNS_EVENT: { if (ghTCPWindow != NULL) SendMessage (ghTCPWindow, uMess, wPara, lPara); return 0; } break; case WM_DDE_INITIATE: { static char apptext[256], topictext[256]; ATOM aApp, aTopic; /* RWS ... */ BOOL handleTopic; /* ... RWS */ GlobalGetAtomName (HIWORD (lPara), topictext, 256); if (lstrcmp (topictext, "CLEANOPEN") == 0) /* RWS: compare application name */ { GlobalGetAtomName (LOWORD (lPara), apptext, 256); handleTopic = CompareStringA (LOCALE_USER_DEFAULT, NORM_IGNORECASE, apptext, lstrlen (apptext), gAppName, lstrlen (gAppName)) == 2; /* 2 means they are equal */ } else handleTopic = FALSE; if (handleTopic) { /* ... RWS */ aApp = GlobalAddAtom (apptext); aTopic = GlobalAddAtom (topictext); SendMessage ((HWND) wPara, WM_DDE_ACK, (WPARAM) hWin, MAKELONG (aApp, aTopic)); GlobalDeleteAtom (aApp); GlobalDeleteAtom (aTopic); } else { return DefWindowProc (hWin, uMess, wPara, lPara); } } break; case WM_DDE_EXECUTE: { char *commandstring; char *pcommand; int len; union { DDEACK ddeack; WORD w; } da; pcommand = GlobalLock ((HANDLE) lPara); len = lstrlen (pcommand) + 1; commandstring = rmalloc (len); /* this pointer is passed to and freed in the Clean code. */ lstrcpyn (commandstring, pcommand, len); GlobalUnlock ((HANDLE) lPara); SendMessage1ToClean (CcWmDDEEXECUTE, commandstring); da.ddeack.bAppReturnCode = 0; da.ddeack.fBusy = 0; da.ddeack.fAck = 1; PostMessage ((HWND) wPara, WM_DDE_ACK, (WPARAM) hWin, PackDDElParam (WM_DDE_ACK, (UINT) da.w, lPara)); return 0; } break; case WM_DDE_TERMINATE: { PostMessage ((HWND) wPara, WM_DDE_TERMINATE, (WPARAM) hWin, 0); } return 0; default: return DefWindowProc (hWin, uMess, wPara, lPara); break; } return 0; } /* MainWindowProcedure */
void InitKWayPartitioningRB(ctrl_t *ctrl, graph_t *graph) { idx_t i, options[METIS_NOPTIONS], curobj=0; idx_t *bestwhere=NULL; real_t *ubvec=NULL; int status; METIS_SetDefaultOptions(options); options[METIS_OPTION_NITER] = 10; options[METIS_OPTION_OBJTYPE] = METIS_OBJTYPE_CUT; options[METIS_OPTION_NO2HOP] = ctrl->no2hop; options[METIS_OPTION_ONDISK] = ctrl->ondisk; ubvec = rmalloc(graph->ncon, "InitKWayPartitioning: ubvec"); for (i=0; i<graph->ncon; i++) ubvec[i] = (real_t)pow(ctrl->ubfactors[i], 1.0/log(ctrl->nparts)); switch (ctrl->objtype) { case METIS_OBJTYPE_CUT: case METIS_OBJTYPE_VOL: options[METIS_OPTION_NCUTS] = ctrl->nIparts; status = METIS_PartGraphRecursive(&graph->nvtxs, &graph->ncon, graph->xadj, graph->adjncy, graph->vwgt, graph->vsize, graph->adjwgt, &ctrl->nparts, ctrl->tpwgts, ubvec, options, &curobj, graph->where); if (status != METIS_OK) gk_errexit(SIGERR, "Failed during initial partitioning\n"); break; #ifdef XXX /* This does not seem to help */ case METIS_OBJTYPE_VOL: bestwhere = imalloc(graph->nvtxs, "InitKWayPartitioning: bestwhere"); options[METIS_OPTION_NCUTS] = 2; ntrials = (ctrl->nIparts+1)/2; for (i=0; i<ntrials; i++) { status = METIS_PartGraphRecursive(&graph->nvtxs, &graph->ncon, graph->xadj, graph->adjncy, graph->vwgt, graph->vsize, graph->adjwgt, &ctrl->nparts, ctrl->tpwgts, ubvec, options, &curobj, graph->where); if (status != METIS_OK) gk_errexit(SIGERR, "Failed during initial partitioning\n"); curobj = ComputeVolume(graph, graph->where); if (i == 0 || bestobj > curobj) { bestobj = curobj; if (i < ntrials-1) icopy(graph->nvtxs, graph->where, bestwhere); } if (bestobj == 0) break; } if (bestobj != curobj) icopy(graph->nvtxs, bestwhere, graph->where); break; #endif default: gk_errexit(SIGERR, "Unknown objtype: %d\n", ctrl->objtype); } gk_free((void **)&ubvec, &bestwhere, LTERM); }
void TestParMetis_GPart(char *filename, char *xyzfile, MPI_Comm comm) { idx_t ncon, nparts, npes, mype, opt2, realcut; graph_t graph, mgraph; idx_t *part, *mpart, *savepart, *order, *sizes; idx_t numflag=0, wgtflag=0, options[10], edgecut, ndims; real_t ipc2redist, *xyz=NULL, *tpwgts = NULL, ubvec[MAXNCON]; gkMPI_Comm_size(comm, &npes); gkMPI_Comm_rank(comm, &mype); ParallelReadGraph(&graph, filename, comm); if (xyzfile) xyz = ReadTestCoordinates(&graph, xyzfile, &ndims, comm); gkMPI_Barrier(comm); part = imalloc(graph.nvtxs, "TestParMetis_V3: part"); tpwgts = rmalloc(MAXNCON*npes*2, "TestParMetis_V3: tpwgts"); rset(MAXNCON, 1.05, ubvec); graph.vwgt = ismalloc(graph.nvtxs*5, 1, "TestParMetis_GPart: vwgt"); /*====================================================================== / ParMETIS_V3_PartKway /=======================================================================*/ options[0] = 1; options[1] = 3; options[2] = 1; wgtflag = 2; numflag = 0; edgecut = 0; for (nparts=2*npes; nparts>=npes/2 && nparts > 0; nparts = nparts/2) { for (ncon=1; ncon<=NCON; ncon++) { if (ncon > 1 && nparts > 1) Mc_AdaptGraph(&graph, part, ncon, nparts, comm); else iset(graph.nvtxs, 1, graph.vwgt); if (mype == 0) printf("\nTesting ParMETIS_V3_PartKway with ncon: %"PRIDX", nparts: %"PRIDX"\n", ncon, nparts); rset(nparts*ncon, 1.0/(real_t)nparts, tpwgts); ParMETIS_V3_PartKway(graph.vtxdist, graph.xadj, graph.adjncy, graph.vwgt, NULL, &wgtflag, &numflag, &ncon, &nparts, tpwgts, ubvec, options, &edgecut, part, &comm); realcut = ComputeRealCut(graph.vtxdist, part, filename, comm); if (mype == 0) { printf("ParMETIS_V3_PartKway reported a cut of %"PRIDX" [%s:%"PRIDX"]\n", edgecut, (edgecut == realcut ? "OK" : "ERROR"), realcut); } if (mype == 0) printf("\nTesting ParMETIS_V3_RefineKway with ncon: %"PRIDX", nparts: %"PRIDX"\n", ncon, nparts); options[3] = PARMETIS_PSR_UNCOUPLED; ParMETIS_V3_RefineKway(graph.vtxdist, graph.xadj, graph.adjncy, graph.vwgt, NULL, &wgtflag, &numflag, &ncon, &nparts, tpwgts, ubvec, options, &edgecut, part, &comm); realcut = ComputeRealCut(graph.vtxdist, part, filename, comm); if (mype == 0) { printf("ParMETIS_V3_RefineKway reported a cut of %"PRIDX" [%s:%"PRIDX"]\n", edgecut, (edgecut == realcut ? "OK" : "ERROR"), realcut); } } } /*====================================================================== / ParMETIS_V3_PartGeomKway /=======================================================================*/ if (xyzfile != NULL) { options[0] = 1; options[1] = 3; options[2] = 1; wgtflag = 2; numflag = 0; for (nparts=2*npes; nparts>=npes/2 && nparts > 0; nparts = nparts/2) { for (ncon=1; ncon<=NCON; ncon++) { if (ncon > 1) Mc_AdaptGraph(&graph, part, ncon, nparts, comm); else iset(graph.nvtxs, 1, graph.vwgt); if (mype == 0) printf("\nTesting ParMETIS_V3_PartGeomKway with ncon: %"PRIDX", nparts: %"PRIDX"\n", ncon, nparts); rset(nparts*ncon, 1.0/(real_t)nparts, tpwgts); ParMETIS_V3_PartGeomKway(graph.vtxdist, graph.xadj, graph.adjncy, graph.vwgt, NULL, &wgtflag, &numflag, &ndims, xyz, &ncon, &nparts, tpwgts, ubvec, options, &edgecut, part, &comm); realcut = ComputeRealCut(graph.vtxdist, part, filename, comm); if (mype == 0) printf("ParMETIS_V3_PartGeomKway reported a cut of %"PRIDX" [%s:%"PRIDX"]\n", edgecut, (edgecut == realcut ? "OK" : "ERROR"), realcut); } } } /*====================================================================== / ParMETIS_V3_PartGeom /=======================================================================*/ if (xyz != NULL) { wgtflag = 0; numflag = 0; if (mype == 0) printf("\nTesting ParMETIS_V3_PartGeom\n"); ParMETIS_V3_PartGeom(graph.vtxdist, &ndims, xyz, part, &comm); realcut = ComputeRealCut(graph.vtxdist, part, filename, comm); if (mype == 0) printf("ParMETIS_V3_PartGeom reported a cut of %"PRIDX"\n", realcut); } /*====================================================================== / Coupled ParMETIS_V3_RefineKway /=======================================================================*/ options[0] = 1; options[1] = 3; options[2] = 1; options[3] = PARMETIS_PSR_COUPLED; nparts = npes; wgtflag = 0; numflag = 0; ncon = 1; rset(nparts*ncon, 1.0/(real_t)nparts, tpwgts); if (mype == 0) printf("\nTesting coupled ParMETIS_V3_RefineKway with default options (before move)\n"); ParMETIS_V3_RefineKway(graph.vtxdist, graph.xadj, graph.adjncy, NULL, NULL, &wgtflag, &numflag, &ncon, &nparts, tpwgts, ubvec, options, &edgecut, part, &comm); /* Compute a good partition and move the graph. Do so quietly! */ options[0] = 0; nparts = npes; wgtflag = 0; numflag = 0; ncon = 1; rset(nparts*ncon, 1.0/(real_t)nparts, tpwgts); ParMETIS_V3_PartKway(graph.vtxdist, graph.xadj, graph.adjncy, NULL, NULL, &wgtflag, &numflag, &ncon, &npes, tpwgts, ubvec, options, &edgecut, part, &comm); TestMoveGraph(&graph, &mgraph, part, comm); gk_free((void **)&(graph.vwgt), LTERM); mpart = ismalloc(mgraph.nvtxs, mype, "TestParMetis_V3: mpart"); savepart = imalloc(mgraph.nvtxs, "TestParMetis_V3: savepart"); /*====================================================================== / Coupled ParMETIS_V3_RefineKway /=======================================================================*/ options[0] = 1; options[1] = 3; options[2] = 1; options[3] = PARMETIS_PSR_COUPLED; nparts = npes; wgtflag = 0; numflag = 0; for (ncon=1; ncon<=NCON; ncon++) { if (mype == 0) printf("\nTesting coupled ParMETIS_V3_RefineKway with ncon: %"PRIDX", nparts: %"PRIDX"\n", ncon, nparts); rset(nparts*ncon, 1.0/(real_t)nparts, tpwgts); ParMETIS_V3_RefineKway(mgraph.vtxdist, mgraph.xadj, mgraph.adjncy, NULL, NULL, &wgtflag, &numflag, &ncon, &nparts, tpwgts, ubvec, options, &edgecut, mpart, &comm); realcut = ComputeRealCutFromMoved(graph.vtxdist, mgraph.vtxdist, part, mpart, filename, comm); if (mype == 0) printf("ParMETIS_V3_RefineKway reported a cut of %"PRIDX" [%s:%"PRIDX"]\n", edgecut, (edgecut == realcut ? "OK" : "ERROR"), realcut); } /*ADAPTIVE:*/ /*====================================================================== / ParMETIS_V3_AdaptiveRepart /=======================================================================*/ mgraph.vwgt = ismalloc(mgraph.nvtxs*NCON, 1, "TestParMetis_V3: mgraph.vwgt"); mgraph.vsize = ismalloc(mgraph.nvtxs, 1, "TestParMetis_V3: mgraph.vsize"); AdaptGraph(&mgraph, 4, comm); options[0] = 1; options[1] = 7; options[2] = 1; options[3] = PARMETIS_PSR_COUPLED; wgtflag = 2; numflag = 0; for (nparts=2*npes; nparts>=npes/2; nparts = nparts/2) { options[0] = 0; ncon = 1; wgtflag = 0; rset(nparts*ncon, 1.0/(real_t)nparts, tpwgts); ParMETIS_V3_PartKway(mgraph.vtxdist, mgraph.xadj, mgraph.adjncy, NULL, NULL, &wgtflag, &numflag, &ncon, &nparts, tpwgts, ubvec, options, &edgecut, savepart, &comm); options[0] = 1; wgtflag = 2; for (ncon=1; ncon<=NCON; ncon++) { rset(nparts*ncon, 1.0/(real_t)nparts, tpwgts); if (ncon > 1) Mc_AdaptGraph(&mgraph, savepart, ncon, nparts, comm); else AdaptGraph(&mgraph, 4, comm); for (ipc2redist=1000.0; ipc2redist>=0.001; ipc2redist/=1000.0) { icopy(mgraph.nvtxs, savepart, mpart); if (mype == 0) printf("\nTesting ParMETIS_V3_AdaptiveRepart with ipc2redist: %.3"PRREAL", ncon: %"PRIDX", nparts: %"PRIDX"\n", ipc2redist, ncon, nparts); ParMETIS_V3_AdaptiveRepart(mgraph.vtxdist, mgraph.xadj, mgraph.adjncy, mgraph.vwgt, mgraph.vsize, NULL, &wgtflag, &numflag, &ncon, &nparts, tpwgts, ubvec, &ipc2redist, options, &edgecut, mpart, &comm); realcut = ComputeRealCutFromMoved(graph.vtxdist, mgraph.vtxdist, part, mpart, filename, comm); if (mype == 0) printf("ParMETIS_V3_AdaptiveRepart reported a cut of %"PRIDX" [%s:%"PRIDX"]\n", edgecut, (edgecut == realcut ? "OK" : "ERROR"), realcut); } } } gk_free((void **)&tpwgts, &part, &mpart, &savepart, &xyz, &mgraph.vwgt, &mgraph.vsize, LTERM); }