Esempio n. 1
0
double 
compute_cube_edata (
    struct refine_edata *edata,	/* desire data for current edge */
    struct refine_vdata *vdata,	/* data for all vertices */
    int nsets_tot,		/* total number of processors */
    struct vtx_data **comm_graph,	/* communication graph */
    int *node2vtx		/* maps mesh nodes to graph vertices */
)
{
    double    desire;		/* edge's interest in flipping */
    float     ewgt;		/* edge weight */
    int       offset;		/* offset into vdata array */
    int       vtx1, vtx2;	/* vertices on either side of wire */
    int       is_an_edge();

    vtx1 = node2vtx[edata->node1];
    vtx2 = node2vtx[edata->node2];
    offset = nsets_tot * edata->dim;

    desire = (vdata[offset + vtx1].above - vdata[offset + vtx1].same) +
       (vdata[offset + vtx2].above - vdata[offset + vtx2].same);

    /* Subtract off potential doubly counted edge. */
    if (is_an_edge(comm_graph[vtx1], vtx2, &ewgt)) {
	desire -= 2 * ewgt;
    }

    return (desire);
}
Esempio n. 2
0
double 
compute_mesh_edata (
    struct refine_edata *edata,	/* desire data for current edge */
    struct refine_vdata *vdata,	/* data for all vertices */
    int mesh_dims[3],		/* dimensions of processor mesh */
    struct vtx_data **comm_graph,	/* communication graph */
    int *node2vtx		/* maps mesh nodes to graph vertices */
)
{
    double    desire;		/* edge's interest in flipping */
    float     ewgt;		/* edge weight */
    int       vtx1, vtx2;	/* vertices on either side of wire */
    int       off;		/* index into vdata */
    int       is_an_edge();

    vtx1 = node2vtx[edata->node1];
    vtx2 = node2vtx[edata->node2];

    off = edata->dim * mesh_dims[0] * mesh_dims[1] * mesh_dims[2];

    desire =
       (vdata[off + vtx1].above - vdata[off + vtx1].below - vdata[off + vtx1].same) +
       (vdata[off + vtx2].below - vdata[off + vtx2].above - vdata[off + vtx2].same);

    /* Subtract off potential doubly counted edge. */
    if (is_an_edge(comm_graph[vtx1], vtx2, &ewgt))
	desire -= 2 * ewgt;

    return (desire);
}
Esempio n. 3
0
int 
check_graph (
    struct vtx_data **graph,	/* graph data structure */
    int nvtxs,		/* number of vertices */
    int nedges		/* number of edges */
)
{
    extern FILE *Output_File;   /* output file or null */
    float     eweight;		/* edge weight */
    double    wgt_sum=0.0;		/* sum of edge weights */
    int       flag;		/* flag for error free graph */
    int       no_edge_count;	/* warning flag for isolated vertex */
    int       bad_vwgt_count;	/* number of vertices with bad vwgts */
    int       using_ewgts;	/* are edge weights being used? */
    int       narcs;		/* number of neighbors of a vertex */
    int       neighbor;		/* neighbor of a vertex */
    int       i, j;		/* loop counters */
    int       is_an_edge();

    flag = FALSE;
    no_edge_count = 0;
    bad_vwgt_count = 0;
    using_ewgts = (graph[1]->ewgts != NULL);
    narcs = 0;
    for (i = 1; i <= nvtxs; i++) {
	narcs += graph[i]->nedges - 1;

	if (graph[i]->edges[0] != i) {
	    printf(" Self edge wrong for vtx %d\n", i);
	    flag = TRUE;
	}

	if (graph[i]->nedges == 1) {
	    if (!no_edge_count) {
		printf("WARNING: Vertex %d has no neighbors\n", i);
    		if (Output_File != NULL) {
		    fprintf(Output_File,
			"WARNING: Vertex %d has no neighbors\n", i);
		}
	    }
	    ++no_edge_count;
	}

	if (graph[i]->vwgt <= 0) {
	    if (!bad_vwgt_count)
		printf("Vertex %d has bad vertex weight %d.\n",
		       i, graph[i]->vwgt);
	    ++bad_vwgt_count;
	    flag = TRUE;
	}

	if (using_ewgts)
	    wgt_sum = graph[i]->ewgts[0];

	for (j = 1; j < graph[i]->nedges; j++) {
	    neighbor = graph[i]->edges[j];
	    if (using_ewgts)
		wgt_sum += graph[i]->ewgts[j];

/* Move it to the end and delete instead? */
	    if (neighbor == i) {
		printf("Self edge (%d,%d) not allowed\n", i, neighbor);
		flag = TRUE;
	    }

	    if (neighbor < 1 || neighbor > nvtxs) {
		printf("Edge (%d,%d) included, but nvtxs = %d\n",
		       i, neighbor, nvtxs);
		flag = TRUE;
	    }

/* Move it to the end and delete instead? */
	    if (using_ewgts && graph[i]->ewgts[j] <= 0) {
		printf("Bad edge weight %g for edge (%d, %d)\n",
		       graph[i]->ewgts[j], i, neighbor);
		flag = TRUE;
	    }

	    if (!is_an_edge(graph[neighbor], i, &eweight)) {
		printf("Edge (%d,%d) included but not (%d,%d)\n",
		       i, neighbor, neighbor, i);
		flag = TRUE;
	    }
	    else if (using_ewgts && eweight != graph[i]->ewgts[j]) {
		printf("Weight of (%d,%d)=%g, but weight of (%d,%d)=%g\n",
		       i, neighbor, graph[i]->ewgts[j], neighbor, i, eweight);
		flag = TRUE;
	    }
	}

	if (using_ewgts && fabs(wgt_sum) > 1.0e-7 * fabs(graph[i]->ewgts[0])) {
	    printf("Sum of edge weights for vertex %d = %g\n", i, wgt_sum);
	    flag = TRUE;
	}
    }

    if (no_edge_count > 1) {
	printf("WARNING: %d vertices have no neighbors\n", no_edge_count);
        if (Output_File != NULL) {
	    fprintf(Output_File,
		"WARNING: %d vertices have no neighbors\n", no_edge_count);
	}
    }

    if (bad_vwgt_count > 1)
	printf("%d vertices have bad vertex weights\n", bad_vwgt_count);

    if (narcs != 2 * nedges) {
	printf(" twice nedges = %d, but I count %d\n", 2 * nedges, narcs);
	flag = TRUE;
    }
    return (flag);
}