Exemplo n.º 1
0
void metis_mcpartgraphrecursive__(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part)
{
  METIS_mCPartGraphRecursive(nvtxs, ncon, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part);
}
Exemplo n.º 2
0
/*************************************************************************
* Let the game begin
**************************************************************************/
main(int argc, char *argv[])
{
    int i, nparts, options[10];
    idxtype *part;
    float lbvec[MAXNCON];
    GraphType graph;
    char filename[256];
    int numflag = 0, wgtflag = 0, edgecut;
    timer TOTALTmr, METISTmr, IOTmr;


    if (argc != 3) {
        printf("Usage: %s <GraphFile> <Nparts>\n",argv[0]);
        exit(0);
    }

    strcpy(filename, argv[1]);
    nparts = atoi(argv[2]);

    if (nparts < 2) {
        printf("The number of partitions should be greater than 1!\n");
        exit(0);
    }

    cleartimer(TOTALTmr);
    cleartimer(METISTmr);
    cleartimer(IOTmr);

    starttimer(TOTALTmr);
    starttimer(IOTmr);
    ReadGraph(&graph, filename, &wgtflag);
    if (graph.nvtxs <= 0) {
        printf("Empty graph. Nothing to do.\n");
        exit(0);
    }
    stoptimer(IOTmr);

    printf("**********************************************************************\n");
    printf("%s", METISTITLE);
    printf("Graph Information ---------------------------------------------------\n");
    printf("  Name: %s, #Vertices: %d, #Edges: %d, #Parts: %d\n", filename, graph.nvtxs, graph.nedges/2, nparts);
    if (graph.ncon > 1)
        printf("  Balancing Constraints: %d\n", graph.ncon);
    printf("\nRecursive Partitioning... -------------------------------------------\n");

    part = idxmalloc(graph.nvtxs, "main: part");
    options[0] = 0;

    starttimer(METISTmr);
    if (graph.ncon == 1) {
        METIS_PartGraphRecursive(&graph.nvtxs, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt,
                                 &wgtflag, &numflag, &nparts, options, &edgecut, part);
    }
    else {
        METIS_mCPartGraphRecursive(&graph.nvtxs, &graph.ncon, graph.xadj, graph.adjncy, graph.vwgt,
                                   graph.adjwgt, &wgtflag, &numflag, &nparts, options, &edgecut, part);
    }

    stoptimer(METISTmr);

    ComputePartitionBalance(&graph, nparts, part, lbvec);

    printf("  %d-way Edge-Cut: %7d, Balance: ", nparts, edgecut);
    for (i=0; i<graph.ncon; i++)
        printf("%5.2f ", lbvec[i]);
    printf("\n");


    starttimer(IOTmr);
    WritePartition(filename, part, graph.nvtxs, nparts);
    stoptimer(IOTmr);
    stoptimer(TOTALTmr);

    printf("\nTiming Information --------------------------------------------------\n");
    printf("  I/O:          \t\t %7.3f\n", gettimer(IOTmr));
    printf("  Partitioning: \t\t %7.3f   (PMETIS time)\n", gettimer(METISTmr));
    printf("  Total:        \t\t %7.3f\n", gettimer(TOTALTmr));
    printf("**********************************************************************\n");


    GKfree(&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, &part, LTERM);
}
Exemplo n.º 3
0
void METIS_MCPARTGRAPHRECURSIVE(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part)
{
  METIS_mCPartGraphRecursive(nvtxs, ncon, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part);
}
Exemplo n.º 4
0
JNIEXPORT jint JNICALL Java_jprime_JMetis_mcPartitionGraph(
		JNIEnv * env,
		jobject obj,
		jboolean j_force_PartGraphRecursive,
		jboolean j_force_PartGraphKway,
		jint j_num_vertices,
		jint j_num_constraints,
		jintArray j_xadj,
		jintArray j_adjncy,
		jintArray j_vwgt,
		jintArray j_adjwgt,
		jint j_wgtflag,
		jint j_nparts,
		jintArray j_options,
		jintArray j_partioned_nodes) {
	mysrand(7654321L);
	//delcare vars
	jint * xadj=NULL, * adjncy=NULL,* vwgt=NULL, * adjwgt=NULL, * options=NULL, * partioned_nodes=NULL;
	int idx, edges_cut=-1, num_vertices=0, num_constraints, nparts=0, wgtflag=0, numflag=0;
	float* ubvec=0;
	jsize xadj_len, adjncy_len, vwgt_len, adjwgt_len, options_len, partioned_nodes_len;

	//copy the jsize vars
	num_vertices=j_num_vertices;
	num_constraints=j_num_constraints;
	nparts=j_nparts;
	wgtflag=j_wgtflag;

	//get array lengths
	xadj_len            = (*env)->GetArrayLength(env,j_xadj);
	adjncy_len          = (*env)->GetArrayLength(env,j_adjncy);
	vwgt_len            = (*env)->GetArrayLength(env,j_vwgt);
	adjwgt_len          = (*env)->GetArrayLength(env,j_adjwgt);
	options_len         = (*env)->GetArrayLength(env,j_options);
	partioned_nodes_len = (*env)->GetArrayLength(env,j_partioned_nodes);

	//create/get local copies
	xadj                      = (*env)->GetIntArrayElements(env,j_xadj,0);
	adjncy                    = (*env)->GetIntArrayElements(env,j_adjncy,0);
	if(vwgt_len>0)    vwgt    = (*env)->GetIntArrayElements(env,j_vwgt,0);
	if(adjwgt_len>0)  adjwgt  = (*env)->GetIntArrayElements(env,j_adjwgt,0);
	if(options_len>0) options = (*env)->GetIntArrayElements(env,j_options,0);
	partioned_nodes           = (int*)malloc(sizeof(int)*partioned_nodes_len);

	//call func
	if((j_nparts<8 || j_force_PartGraphRecursive) && !j_force_PartGraphKway) {
		//printf("[0]nparts=%i, num_vertices=%i, num_constraints=%i, wgtflag=%i, xadj_len=%i, adjncy_len=%i, vwgt_len=%i, adjwgt_len=%i, options_len=%i, partioned_nodes_len=%i\n",
		//		nparts, num_vertices, num_constraints, wgtflag, xadj_len, adjncy_len, vwgt_len, adjwgt_len, options_len, partioned_nodes_len);
		METIS_mCPartGraphRecursive(
				&num_vertices,
				&num_constraints,
				xadj,
				adjncy,
				vwgt,
				adjwgt,
				&wgtflag,
				&numflag,
				&nparts,
				options,
				&edges_cut,
				partioned_nodes);
	}
	else {
		//printf("[1]nparts=%i, num_vertices=%i, num_constraints=%i, wgtflag=%i, xadj_len=%i, adjncy_len=%i, vwgt_len=%i, adjwgt_len=%i, options_len=%i, partioned_nodes_len=%i\n",
		//		nparts, num_vertices, num_constraints, wgtflag, xadj_len, adjncy_len, vwgt_len, adjwgt_len, options_len, partioned_nodes_len);
		ubvec = (float*)malloc(sizeof(float)*num_constraints);
		for(idx=0;idx<num_constraints;idx++) {
			ubvec[idx]=1.1; //manual says should be larger than 1.03 so 1.1 seems reasonable
		}
		METIS_mCPartGraphKway(
				&num_vertices, //int *nvtxs,
				&num_constraints,//int *ncon,
				xadj,//idxtype *xadj,
				adjncy,//idxtype *adjncy,
				vwgt,//idxtype *vwgt,
				adjwgt,//idxtype *adjwgt,
				&wgtflag,//int *wgtflag,
				&numflag,//int *numflag,
				&nparts, //int *nparts,
				ubvec,//float *rubvec,
				options,//int *options,
				&edges_cut,//int *edgecut,
				partioned_nodes); //idxtype *part)
		free(ubvec);
	}

	//pop partioned_nodes
	(*env)->SetIntArrayRegion(env,j_partioned_nodes,0,partioned_nodes_len,partioned_nodes);

	//free local copies
	free(partioned_nodes);
	(*env)->ReleaseIntArrayElements(env, j_xadj, xadj, 0);
	(*env)->ReleaseIntArrayElements(env, j_adjncy, adjncy, 0);
	if(vwgt_len>0) (*env)->ReleaseIntArrayElements(env, j_vwgt, vwgt, 0);
	if(adjwgt_len>0) (*env)->ReleaseIntArrayElements(env, j_adjwgt, adjwgt, 0);
	if(options_len>0) (*env)->ReleaseIntArrayElements(env, j_options, options, 0);
	return edges_cut;
}