/* * Copyright 1997, Regents of the University of Minnesota * * wavefrontK.c * * This file contains code for the initial directed diffusion at the coarsest * graph * * Started 5/19/97, Kirk, George * * $Id: diffutil.c 13946 2013-03-30 15:51:45Z karypis $ * */ #include /************************************************************************* * This function computes the load for each subdomain **************************************************************************/ void SetUpConnectGraph(graph_t *graph, matrix_t *matrix, idx_t *workspace) { idx_t i, ii, j, jj, k, l; idx_t nvtxs, nrows; idx_t *xadj, *adjncy, *where; idx_t *rowptr, *colind; idx_t *pcounts, *perm, *marker; real_t *values; nvtxs = graph->nvtxs; xadj = graph->xadj; adjncy = graph->adjncy; where = graph->where; nrows = matrix->nrows; rowptr = matrix->rowptr; colind = matrix->colind; values = matrix->values; perm = workspace; marker = iset(nrows, -1, workspace+nvtxs); pcounts = iset(nrows+1, 0, workspace+nvtxs+nrows); for (i=0; i0; i--) pcounts[i] = pcounts[i-1]; pcounts[0] = 0; /************************/ /* Construct the matrix */ /************************/ rowptr[0] = k = 0; for (ii=0; iinnzs = rowptr[nrows]; return; } /************************************************************************* * This function computes movement statistics for adaptive refinement * schemes **************************************************************************/ void Mc_ComputeMoveStatistics(ctrl_t *ctrl, graph_t *graph, idx_t *nmoved, idx_t *maxin, idx_t *maxout) { idx_t i, nvtxs, nparts, myhome; idx_t *vwgt, *where; idx_t *lend, *gend, *lleft, *gleft, *lstart, *gstart; nvtxs = graph->nvtxs; vwgt = graph->vwgt; where = graph->where; nparts = ctrl->nparts; lstart = ismalloc(nparts, 0, "ComputeMoveStatistics: lstart"); gstart = ismalloc(nparts, 0, "ComputeMoveStatistics: gstart"); lleft = ismalloc(nparts, 0, "ComputeMoveStatistics: lleft"); gleft = ismalloc(nparts, 0, "ComputeMoveStatistics: gleft"); lend = ismalloc(nparts, 0, "ComputeMoveStatistics: lend"); gend = ismalloc(nparts, 0, "ComputeMoveStatistics: gend"); for (i=0; ips_relation == PARMETIS_PSR_COUPLED) ? ctrl->mype : graph->home[i]; lstart[myhome] += (graph->vsize == NULL) ? 1 : graph->vsize[i]; lend[where[i]] += (graph->vsize == NULL) ? 1 : graph->vsize[i]; if (where[i] != myhome) lleft[myhome] += (graph->vsize == NULL) ? 1 : graph->vsize[i]; } /* PrintVector(ctrl, ctrl->npes, 0, lend, "Lend: "); */ gkMPI_Allreduce((void *)lstart, (void *)gstart, nparts, IDX_T, MPI_SUM, ctrl->comm); gkMPI_Allreduce((void *)lleft, (void *)gleft, nparts, IDX_T, MPI_SUM, ctrl->comm); gkMPI_Allreduce((void *)lend, (void *)gend, nparts, IDX_T, MPI_SUM, ctrl->comm); *nmoved = isum(nparts, gleft, 1); *maxout = imax(nparts, gleft); for (i=0; invtxs; i++) { if (graph->where[i] != home[i]) totalv += (graph->vsize == NULL) ? graph->vwgt[i*graph->ncon] : graph->vsize[i]; } return totalv; } /************************************************************************* * This function computes the load for each subdomain **************************************************************************/ void ComputeLoad(graph_t *graph, idx_t nparts, real_t *load, real_t *tpwgts, idx_t index) { idx_t i; idx_t nvtxs, ncon; idx_t *where; real_t *nvwgt; nvtxs = graph->nvtxs; ncon = graph->ncon; where = graph->where; nvwgt = graph->nvwgt; rset(nparts, 0.0, load); for (i=0; inrows; rowptr = A->rowptr; colind = A->colind; values = A->values; /* Initial Setup */ p = workspace; r = workspace + n; q = workspace + 2*n; z = workspace + 3*n; M = workspace + 4*n; for (i=0; i 0.0) { error = rnorm2(n, r, 1) / bnrm2; if (error > tol) { /* Begin Iterations */ for (k=0; knrows; i++) w[i] = 0.0; for (i = 0; i < A->nrows; i++) for (j = A->rowptr[i]; j < A->rowptr[i+1]; j++) w[i] += A->values[j] * v[A->colind[j]]; return; } /************************************************************************* * This function sets up the transfer vectors **************************************************************************/ void ComputeTransferVector(idx_t ncon, matrix_t *matrix, real_t *solution, real_t *transfer, idx_t index) { idx_t j, k; idx_t nrows; idx_t *rowptr, *colind; nrows = matrix->nrows; rowptr = matrix->rowptr; colind = matrix->colind; for (j=0; j solution[colind[k]]) { transfer[k*ncon+index] = solution[j] - solution[colind[k]]; } else { transfer[k*ncon+index] = 0.0; } } } }