Esempio n. 1
0
void load_all(const char* name)
{
    bvgraph g = {0};
    bvgraph_load(&g, name, strlen(name), 0);
    
    bvgraph_iterator git;
    int rval = bvgraph_nonzero_iterator(&g, &git);
    if (rval){
        printf("Construct nonzero iterator failed. Stop.\n");
        return;
    }

    ALL_PAIR = malloc(sizeof(int)*2*(int)g.m);

    for (; bvgraph_iterator_valid(&git); bvgraph_iterator_next(&git)) {
        int64_t*links = NULL;
        uint64_t d = 0;
        
        bvgraph_iterator_outedges(&git, &links, &d);
        
        int64_t i = 0;
        for (i=0; i<d; ++i) {
            ALL_PAIR[PAIR_SIZE].from = git.curr;
            ALL_PAIR[PAIR_SIZE].to = links[i];
            PAIR_SIZE++;
        }
    }
    bvgraph_iterator_free(&git);
}
Esempio n. 2
0
void iteration(const char* name){
    bvgraph g = {0};
    bvgraph_load(&g, name, strlen(name), 0);

    bvgraph_iterator git;
    int rval = bvgraph_nonzero_iterator(&g, &git);
    if (rval){
        printf("Construct nonzero iterator failed. Stop.\n");
        return;
    }

    for (; bvgraph_iterator_valid(&git); bvgraph_iterator_next(&git)) {
        int64_t *links = NULL;
        uint64_t d = 0;
        
        bvgraph_iterator_outedges(&git, &links, &d);

        printf("node %"PRId64" has degree %"PRId64"\n", git.curr, d);
        
        int64_t i = 0;
        for (i=0; i<d; ++i) {
            printf("node %"PRId64" links to node %"PRId64"\n", git.curr, links[i]);
        }
    }
    bvgraph_iterator_free(&git);
}
Esempio n. 3
0
int main(int argc, char** argv)
{
    bvgraph g = {0};
    //const char* name = "libbvg/data/wb-cs.stanford";
    const char* name = argv[1];
    char* method = argv[2];
    int rval = 0;

    if (method == NULL) {
        print_help();
        return 0;
    }

    //load with offsets
    rval = bvgraph_load(&g, name, strlen(name), 1);
    if (rval != 0) {
        printf("Failed to load file %s\n", name);
        return (-1);
    }

    printf("Input file: %s\n", name);
    printf("nodes = %"PRId64"\n", g.n);
    printf("edges = %"PRId64"\n", g.m);

    if (strcmp(method, "random") == 0){
        load_all(name);
        if (argv[3] == NULL){
            printf("Need node number. Stop\n");
            return 1;
        }
        int num = atoi(argv[3]);
        random_test(g, num);
    }
    else if (strcmp(method, "head-tail") == 0){
        load_all(name);
        head_tail_first_test(g);
    }
    else if (strcmp(method, "all") == 0){
        load_all(name);
        print_all(g);
    }
    else if (strcmp(method, "perform") == 0){
        // test performance
        if (argv[3] == NULL){
            printf("Need node number. Stop\n");
            return 1;
        }
        int num = atoi(argv[3]);
        test_performance(g, num);
    }
    else if (strcmp(method, "iter") == 0){
        iteration(name);
    }
    else{
        print_help();
    }

    bvgraph_close(&g);

    return 0;
}
Esempio n. 4
0
int main(int argc, char **argv) 
{
    bvgraph graph = {0};
    bvgraph *g = &graph;

    char *filename;
    int filenamelen;

    int rval;
    int i;

    if (argc < 2) { fprintf(stderr, "Usage: bvgraph_test bvgraph_basename\n"); return (-1); }

    filename = argv[1];
    filenamelen = (int)strlen(filename);

    rval = bvgraph_load(g, filename, filenamelen, -1);
    if (rval) { perror("error with initial load!"); }
    {
        size_t memrequired;
        bvgraph_required_memory(g, 0, &memrequired, NULL);
        printf("the graph %s requires %i bytes to load into memory\n", filename, memrequired);
    }
    bvgraph_close(g);

    rval = bvgraph_load(g, filename, filenamelen, 0);
    if (rval) { perror("error with full load!"); }
    {
        bvgraph_iterator iter;
        int *links;
        unsigned int d;
        // initialize a vector of column sums
        int *colsum = malloc(sizeof(int)*g->n);
        int *colsum2 = malloc(sizeof(int)*g->n);
        int rep;
        memset(colsum, 0, sizeof(int)*g->n);
        for (bvgraph_nonzero_iterator(g, &iter); 
             bvgraph_iterator_valid(&iter); 
             bvgraph_iterator_next(&iter))
        {
            bvgraph_iterator_outedges(&iter, &links, &d);
            for (i = 0; i < d; i++) {
                colsum[links[i]]++;
            }
        }
        bvgraph_iterator_free(&iter);
        for (rep = 0; rep < 10000; rep++) {
            memset(colsum2, 0, sizeof(int)*g->n);
            for (bvgraph_nonzero_iterator(g, &iter); 
                 bvgraph_iterator_valid(&iter); 
                 bvgraph_iterator_next(&iter))
            {
                bvgraph_iterator_outedges(&iter, &links, &d);
                for (i = 0; i < d; i++) {
                    colsum2[links[i]]++;
                }
            }
            bvgraph_iterator_free(&iter);
            for (i=0; i < g->n; i++) {
                if (colsum2[i] != colsum[i]) {
                    fprintf(stderr, "error, column sum of column %i is not correct (%i =? %i)", 
                        i, colsum[i], colsum2[i]);
                    perror("colsum error!");
                }
            }
        }
        free(colsum);
        free(colsum2);
    }
    bvgraph_close(g);

    for (i = 0; i < 10000000; i++) {
        rval = bvgraph_load(g, filename, filenamelen, 0);
        bvgraph_close(g);
    }

    


}