virtual void SetUp(){
    //SetUp is called before every test
    LOG_INIT("test.log", NULL, 0);
    creator.set_file_name("data/1dc.128.txt");
    creator.set_graph_type("DIMACS");
    mg = creator.create_mutable_graph();
}
Esempio n. 2
0
void parmetis_with_metmmd(){
    DEBUG("########## Testing Function : %s #################\n", __FUNCTION__);
    int size, rank;
    MPI_Comm comm;
    Graph::GraphEOUtil eoutil;
    Graph::VertexWeightedGraph *wmg;
    Graph::GraphCreatorFile creator;

    int output[] =
    {
        102,58,128,121,86,64,96,112,103,117,120,87,124,126,127,63,95,108,110,111,91,107,109,119,123,125,115,59,61,62,90,93,122,114,106,118,32,116,55,100,16,79,84,78,24,48,52,56,44,54,60,80,28,30,31,40,46,47,72,76,88,92,94,104,8,101,1,42,4,25,97,81,6,7,3,2,73,49,13,5,9,11,17,33,65,66,67,69,10,18,19,21,34,35,37,41,113,15,68,105,77,50,14,43,20,57,12,70,53,51,23,22,36,38,82,83,98,99,74,26,27,29,39,45,71,75,85,89
    };

    MPI_Comm_dup(MPI_COMM_WORLD, &comm);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    creator.set_file_name("data/1dc.128.txt");
    creator.set_graph_type("DIMACS");
    wmg = creator.create_weighted_mutable_graph();

    vector<int> ordering(wmg->get_num_nodes(), -1);
    eoutil.parmetis_elimination_ordering(wmg, ordering, GD_METIS_MMD, false, comm);
    if(rank == 0){
        int n = wmg->get_num_nodes();
        for(int i = 0; i < n; i++){
            assert (output[i] == ordering[i]);
        }
        cout << "Parmetis Test " << ++testcount << " : Passed" << endl;
    }
} // parmetis_with_metmmd
Esempio n. 3
0
int main(int argc, char **argv){
    if((argc != 2) || (strcmp(argv[1],"-h") == 0) || (strcmp(argv[1],"--help") == 0) ){
        usage(argv[0]);
    }

    Graph::VertexWeightedGraph *G;

    Graph::GraphCreatorFile creator;
    creator.set_file_name(argv[1]);
    creator.set_graph_type("DIMACS");
    G = creator.create_weighted_mutable_graph();
    G->complement();
    Graph::GraphWriter writer;

    char comp_DIMACS_file[200];
    char normalized_comp_DIMACS_file[200];
    sprintf(comp_DIMACS_file,"%s.comp",argv[1]);
    writer.write_graph(G,comp_DIMACS_file,"DIMACS",true,false);
    // Now normalize it
    sprintf(normalized_comp_DIMACS_file,"%s.norm",comp_DIMACS_file);
    normalize_DIMACS_file(comp_DIMACS_file,normalized_comp_DIMACS_file);
    fprintf(stderr,"Complement graph of %s written to %s in normalized DIMACS form\n",
            argv[1],normalized_comp_DIMACS_file);

    delete G;
    return 1;
} // main
Esempio n. 4
0
virtual void SetUp(){
    LOG_INIT("test.log", NULL, 0);
    //creator.set_file_name("../data/1dc.128.txt");
    creator.set_file_name("data/1dc.128.txt");
    creator.set_graph_type("DIMACS");
    g = creator.create_graph();
    g_five = new Graph::Graph(5);
}
virtual void SetUp(){
    //SetUp is called before every test
    LOG_INIT("test.log", NULL, 0);
    creator.set_file_name("data/1dc.128.adj");
    creator.set_graph_type("adjmatrix");
    g = creator.create_graph();

    in_file = ("data/1dc.128.met");
}
	virtual void SetUp()
	{
		LOG_INIT("test.log", NULL, 0);
		gr = factory.create_reader("DIMACS");
		gr->read_graph("data/1dc.128.txt");

		creator.set_file_name("data/1dc.128.txt");
		creator.set_graph_type("DIMACS");
		g = creator.create_graph();
	}
Esempio n. 7
0
	virtual void SetUp()
	{
		//SetUp is called before every test
		LOG_INIT("test.log", NULL, 0);
		creator.set_file_name("../data/1dc.128.adj");
		creator.set_graph_type("adjmatrix");
		g = creator.create_graph();

		string out_file("../data/1dc.128.out");
		dim_writer = new Graph::DIMACSGraphWriter(out_file);
	}
Esempio n. 8
0
	virtual void SetUp()
	{
		//SetUp is called before every test
		LOG_INIT("test.log", NULL, 0);
		creator.set_file_name("data/1dc.128.adj");
		creator.set_graph_type("adjmatrix");
		g = creator.create_graph();

		string in_file("data/1dc.128.met");
		mr = new Graph::MetisGraphReader(in_file);
	}
Esempio n. 9
0
int ORD::find_elim_ordering() {
    int ws;
    int wr;

    char eoname[512];
    char eoname_other[512];

    // Get size and rank from the communicator
    MPI_Comm_size(comm, &ws);
    MPI_Comm_rank(comm, &wr);

    double xtime = MPI_Wtime();
    sprintf(eoname, "%s.order.%d", this->filename.c_str(), ws);
    sprintf(eoname_other, "%s.order_other.%d", this->filename.c_str(), ws);

    DEBUG("size: %d, rank %d \n", ws, wr);
    int n = G->get_num_nodes();
    int x = n/ws;
    int xm = n%ws;
    int i = 0;
    DEBUG("n: %d x: %d xm: %d \n", n, x, xm);

    vector<int> xadj;
    vector<int> adjncy;

    vector<int> vtxdist(ws + 1, 0);
    vector<int> sizes(2*ws,0);
    vector<int> ordering(x+1, 0);
    vector<int> recvcnt(ws, 0);
    vector<int> displ(ws, 0);

    int numflag = 0;




    int options[10];

    options[0] = 0;
    vtxdist[0] = 0;
    for (i = 1; i <= ws; i++)
    {
        vtxdist[i] = vtxdist[i - 1] + x;
        if (i <= xm)
            vtxdist[i]++;
    }

    // prepareing displacement and receive counts to use with MPI_Gatherv
    for (i = 0; i < ws; i++)
    {
        recvcnt[i] = x;
        if (i < xm)
            recvcnt[i] ++;

        if (i > 0)
            displ[i] += displ[i - 1] + recvcnt[i - 1];
    }

    DEBUG("range: %d, %d\n", vtxdist[wr], vtxdist[wr + 1]);
    int j = 0;
    xadj.push_back(0);
    for (i = vtxdist[wr]; i < vtxdist[wr + 1]; i++)
    {
        Graph::Node *no = G->get_node(i);
        list<int> *l = no->get_nbrs_ptr();
        list<int>::iterator it = l->begin();

        for (; it != l->end(); ++it)
        {
            adjncy.push_back(*it);
            j++;
        }
        xadj.push_back(j);
    }

    if (METIS_OK != ParMETIS_V3_NodeND(&vtxdist.front(), &xadj.front(), &adjncy.front(), &numflag, options, &ordering.front(), &sizes.front(), &comm))
    {
        FERROR("error occured while processing parmetis, aborting\n");
        MPI_Abort(MPI_COMM_WORLD, -1);
    }

    DEBUG("output from ParMETIS\n");
    double parmet_time = MPI_Wtime() - xtime;

    vector<int> recvbuf;
    n = G->get_num_nodes();
    if (wr == 0)
    {
        recvbuf = vector<int>(n, 0);
    }

    if (MPI_SUCCESS !=
        MPI_Gatherv((void *)&ordering.front(), recvcnt[wr], MPI_INT,
                    (void *)&recvbuf.front(), &recvcnt.front(), &displ.front(), MPI_INT,
                    0, comm))
    {
        FERROR("MPI error occured at Gatherv, Abort!\n");
        MPI_Abort(comm, -1);
    }

    vector<int> eo(n, 0);
    if (wr == 0)
    {
        for (int i = 0; i < n; i++)
        {
            eo[recvbuf[i]] = i;
        }

        FILE *f = fopen(eoname_other, "w");
        for (int i = 0; i < n; i++)
            fprintf(f, "%d\n", eo[i] + 1);
        fclose(f);
        DEBUG("ParMetis NodeND elimination ordering is in : %s\n", eoname_other);
    }

    ordering.clear();
    ordering.resize(recvcnt[wr], 0);

    if (MPI_SUCCESS !=
        MPI_Scatterv ((void *)&eo.front(), &recvcnt.front(), &displ.front(), MPI_INT,
                      (void *)&ordering.front(), recvcnt[wr], MPI_INT,
                      0, comm))
    {
        FERROR("MPI error occured at Scatterv, Abort! \n");
        MPI_Abort(comm, -1);
    }

    DEBUG("Scatterv completed\n");

    Graph::GraphCreatorFile gf;
    Graph::VertexWeightedGraph *wg;
    Graph::GraphEOUtil eoutil;
    Graph::GraphProperties prop;
    list<int>members(ordering.begin(), ordering.end());

    wg = gf.create_component(G, &members, false);
    prop.make_canonical(wg);

    vector<int> ord(recvcnt[wr], 0);
    vector<int> ordsend(recvcnt[wr, 0]);
    double xxtime = MPI_Wtime();
    eoutil.find_elimination_ordering(wg, &ord, GD_AMD, false);
    DEBUG("eo time : %f\n", MPI_Wtime() - xxtime);
    
    int sz = recvcnt[wr];

    for (int i = 0; i < sz; i++)
        ordsend[i] = wg->get_node(ord[i])->get_label();


    recvbuf.assign(n, -1);
    if (MPI_SUCCESS !=
        MPI_Gatherv((void *)&ordsend.front(), recvcnt[wr], MPI_INT, (void *)&recvbuf.front(), &recvcnt.front(), &displ.front(), MPI_INT, 0, comm))
    {
        FERROR("MPI error occured at Gatherv, Abort!\n");
        MPI_Abort(comm, -1);
    }

    double p_amd_time = MPI_Wtime() - xtime;
    if (wr == 0)
    {
        FILE *f = fopen(eoname, "w");
        for (int i = 0; i < n && wr == 0; i++)
            fprintf(f, "%d\n", recvbuf[i]);
        fclose(f);
    } 
    DEBUG("ordering is written into %s\n", eoname);
    DEBUG("%f,%f\n", parmet_time, p_amd_time);

    return 0;
}
Esempio n. 10
0
int main(int argc, char **argv){
    // This is a utility to generate partial k-trees with specified parameters for use in other applications.

    // Check for a cry for help
    if((argc == 1) || ((argc == 2) && (strcmp(argv[1],"-h") == 0)) || ((argc == 2) && (strcmp(argv[1],"--help") == 0))
       || ((argc == 2) && (strcmp(argv[1],"--h") == 0) ) ){
        usage(argv[0]);
        exit(-1);
    }

    ORB_t t1=0, t2=0, t3=0;
    int i;
    int t = 1;
    int ktree_n = -1, ktree_k = -1, ktree_p = -1;
    int seed = 0;
    Graph::VertexWeightedGraph *G = NULL, *H = NULL;
    time_t start, stop;
    char filename[100];
    char *prefix = (char *)"pkt";
    string out_format = "DIMACS";

    bool random = false;
    bool timings = false;
    bool exact_filename = false;
    char lfname[100];
    char efname[100];
    sprintf(lfname, "genpkt.log");
    sprintf(efname, "genpkt.log");
    //0: debug, 5: critical
    LOG_INIT(lfname, efname, 0);

    // Parse arguments
    for(i = 0; i < argc; i++){
        if(strcmp(argv[i],"-t") == 0){
            t = atoi(argv[i + 1]);
        }
        if(strcmp(argv[i],"-k") == 0){
            ktree_k = atoi(argv[i + 1]);
        }
        if(strcmp(argv[i],"-n") == 0){
            ktree_n = atoi(argv[i + 1]);
        }
        if(strcmp(argv[i],"-p") == 0){
            ktree_p = atoi(argv[i + 1]);
        }
        if(strcmp(argv[i],"-o") == 0){
            out_format = string(argv[i + 1]);
        }
        if(strcmp(argv[i],"-s") == 0){
            seed = atoi(argv[i + 1]);
        }
        if(strcmp(argv[i],"-fn") == 0){
            prefix = argv[i + 1];
        }
        if(strcmp(argv[i],"-fe") == 0){
            prefix = argv[i + 1];
            exact_filename = true;
        }
        if(strcmp(argv[i],"-m") == 0){
            timings = true;
        }
        if(strcmp(argv[i],"-r") == 0){
            random = true;
        }
    }

    if((true == exact_filename) && (t != 1)){
        cerr << "Error: cannot specify both -t and -fe flags\n";
        exit(1);
    }

    if(("adjlist" != out_format) && ("dimacs" != out_format)){
        cerr << "Error: only allowed output formats are: adjlist, dimacs\n";
        exit(1);
    }

    // Spin the RNG seed times
    for(int ss = 0; ss < seed; ss++){
        Graph::lcgrand(0);
    }

    //Make sure we set all the parameters to viable values.
    if((ktree_k < 0) || (ktree_n < 0) || (ktree_p < 0)){
        fatal_error("Failed to input viable parameters for n, k, p (%d,%d,%d)\n",
                    ktree_k, ktree_n, ktree_p);
    }

    Graph::GraphCreatorFile creator;
    Graph::GraphProperties prop;
    Graph::GraphWriter writer;

    //ORB_calibrate();

    DEBUG("Graph generation loop\n");
    DEBUG("n : %d k: %d\n", ktree_n, ktree_p);
    for(i = 0; i < t; i++){
        // Create the Ktree
        //H = new Graph::Graph(ktree_n, ktree_k);
        cout << "Generating k-tree\n";
        H = creator.initialize_ktree(ktree_n, ktree_k);
        // Generate an n-node Graph G that is a partial k-tree derived from the k-tree
        start = clock();
        cout << "Deriving partial k-tree\n";
        //ORB_read(t1);
        G = creator.create_random_edge_subgraph(H, ktree_p);
        //ORB_read(t2);
        stop = clock();
        if(timings){
            print_time("Generation time", t1, t2);
        }
        fprintf(stderr,"Generated random partial k-tree (%d,%d) in %f sec.\n",
                ktree_n, ktree_k, ((double)(stop - start)) / CLOCKS_PER_SEC);
        //write it to a file
        if(!exact_filename){
            sprintf(filename, "%s.%d.%d.%d_%d.dimacs", prefix, ktree_n,ktree_k,ktree_p, i);
        }
        else {
            strncpy(filename,prefix, 99);
        }

        print_message(0,"Writing file %s\n",filename);

        //writer->set_out_file_name(filename);

        if(random){
            writer.set_shuffle(true);
            writer.set_shuffle_seed(seed);
        }

        //ORB_read(t2);
        writer.write_graph(G,filename, out_format);
        //ORB_read(t3);
        if(timings){
            print_time("Output time", t2, t3);
            print_time("Total time", t1, t3);
            cout << "Output edges: " << G->get_num_edges() << "\nOutput vertices: " << G->get_num_nodes();
            cout << "\nOutput format: " << out_format << "\nOutput filename: " << filename << "\n";
        }

        delete G;
        delete H;
    }

    LOG_CLOSE();
    exit(0);
} // main
Esempio n. 11
0
int main(int argc, char **argv)
{
    // This is a utility to generate partial k-trees with specified parameters for use in other applications.

    // Check for a cry for help
    if(argc==1 || (argc==2 && strcmp(argv[1],"-h")==0) || (argc==2 && strcmp(argv[1],"--help")==0) 
        || (argc==2 && strcmp(argv[1],"--h")==0) )
    {
        usage(argv[0]);
        exit(-1);
    }

    int i;
    int t = 1;
    int ktree_n=-1, ktree_k=-1, ktree_p=-1;
    int seed=0;
	Graph::WeightedMutableGraph *G=NULL, *H=NULL; 
    time_t start, stop;
    char filename[100];
    char *prefix= (char *)"pkt";
    
    bool random = false, write_scotch=false;
    char lfname[100];
    char efname[100];
    sprintf(lfname, "genpkt.log");
    sprintf(efname, "genpkt.log");
    //0: debug, 5: critical
    LOG_INIT(lfname, efname, 0);

    // Parse arguments
    for(i=0;i<argc;i++)
    {
        if(strcmp(argv[i],"-t")==0)
        {
            t=atoi(argv[i+1]);
        }
        if(strcmp(argv[i],"-k")==0)
        {
            ktree_k=atoi(argv[i+1]);
        }
        if(strcmp(argv[i],"-n")==0)
        {
            ktree_n=atoi(argv[i+1]);
        }
        if(strcmp(argv[i],"-p")==0)
        {
            ktree_p=atoi(argv[i+1]);
        }
        if(strcmp(argv[i],"-s")==0)
        {
            seed=atoi(argv[i+1]);
        }
        if(strcmp(argv[i],"-fn")==0)
            prefix = argv[i+1];
        if(strcmp(argv[i],"-r")==0)
            random = true;
        if(strcmp(argv[i],"-scotch")==0)
            write_scotch = true;
    }

    if(!seed)
        // Set the seed to a rand int in 0,2^24
        seed=Graph::rand_int(0,0xffffff);
    // Spin the RNG seed times
    for(int ss=0;ss<seed;ss++)
        Graph::lcgrand(0);

    //Make sure we set all the parameters to viable values. 
    if(ktree_k < 0 || ktree_n < 0 || ktree_p < 0)
	{
	    fatal_error("Failed to input viable parameters for n, k, p (%d,%d,%d)\n",
            ktree_k, ktree_n, ktree_p);
	}
    
    Graph::GraphCreatorFile creator;
    Graph::GraphWriter *writer;
    Graph::GraphReaderWriterFactory rwf;
    Graph::GraphProperties prop;

    writer = rwf.create_writer("DIMACS", "t");

    DEBUG("Graph generation loop\n");
    DEBUG("n : %d k: %d\n", ktree_n, ktree_p);
    for(i = 0; i < t; i++)
    {
	    // Create the Ktree
	    //H = new Graph::Graph(ktree_n, ktree_k);
        H = creator.initialize_ktree(ktree_n, ktree_k);
	    // Generate an n-node Graph G that is a partial k-tree derived from the k-tree
	    start=clock();
	    G= creator.create_random_edge_subgraph(H, ktree_p);
	    stop=clock();
	    fprintf(stderr,"Generated random partial k-tree (%d,%d) in %f sec.\n",
		   ktree_n, ktree_k, ((double)(stop-start))/CLOCKS_PER_SEC);
	    //write it to a file
	    sprintf(filename, "%s.%d.%d.%d_%d.dimacs", prefix, ktree_n,ktree_k,ktree_p, i);
        print_message(0,"Writing file %s\n",filename);

        writer->set_out_file_name(filename);

        if (random)
            writer->shuffle(G, seed);

        writer->write_graph(G);

 	    delete G; 
	    delete H; 
	}

    LOG_CLOSE();
    return 0;
}