Beispiel #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);
}
Beispiel #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);
}
/** Compute a matrix vector product with a substochastic bvgraph structure
 * 
 * y = y + alpha*P'*x where P = D^{-1} A for the adjacency matrix A given
 * by a bvgraph structure.
 * 
 * @param g the bvgraph
 * @param x the right hand vector,
 * @param y the output vector y = y + alpha*P'*x
 * @param alpha the value of alpha to adjust the mutliplication by
 * @param sum_aPtx the value e^T (alpha*P'*x)
 * @return non-zero on error
 */
int mult(omptransbvgraph *tg, double *x, double *y, const double alpha, double *sum_aPtx)
{
    bvgraph_parallel_iterators *pits = tg->pits;
    int rval=0, j, n=pits->g->n;
    double sum0=0, sum1=0, *id=tg->id;
    
#pragma omp parallel shared(x,y,pits,sum0,sum1,id) \
    reduction(|:rval) num_threads(pits->niters)
    {
        int *links, tid, nsteps; unsigned int i, d; double sumy0, sumy1, t, z;
        bvgraph_iterator iter;
        tid = omp_get_thread_num();
        rval = bvgraph_parallel_iterator(pits, tid, &iter, &nsteps);
        sumy0=0.0; sumy1=0.0;
        if (rval == 0) { 
            for (; bvgraph_iterator_valid(&iter) && nsteps; 
                 bvgraph_iterator_next(&iter), nsteps--)
            {
                double yi=0.0;
                bvgraph_iterator_outedges(&iter, &links, &d);
                for (i = 0; i < d; i++) {              
                    yi += x[links[i]]*id[links[i]];
                }
                yi *= alpha;
                CSUM2(yi,sumy0,sumy1,t,z);
                y[iter.curr]=yi;
            }
            bvgraph_iterator_free(&iter);

            #pragma omp critical
            { CSUM2(FCSUM2(sumy0,sumy1),sum0,sum1,t,z) }
        } else {
            if (BVGRAPH_VERBOSE) { 
                fprintf(stderr,"bvgraph_omp_transmult failed on thread %3i\n",
                    tid);
            }
        }
    }
Beispiel #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);
    }

    


}