void mexFunction ( int nargout, mxArray *pargout [ ], int nargin, const mxArray *pargin [ ] ) { bool malloc_debug = GB_mx_get_global (true) ; GrB_Matrix A = NULL, E = NULL, L = NULL, U = NULL ; // check inputs GB_WHERE (USAGE) ; if (nargout > 2 || nargin != 5) { mexErrMsgTxt ("Usage: " USAGE) ; } #define GET_DEEP_COPY ; #define FREE_DEEP_COPY ; // get the method. Default is Sandia method (outer product) int GET_SCALAR (0, int, method, 3) ; // get A, E, L, and U A = GB_mx_mxArray_to_Matrix (pargin [1], "A", false, true) ; E = GB_mx_mxArray_to_Matrix (pargin [2], "E", false, true) ; L = GB_mx_mxArray_to_Matrix (pargin [3], "L", false, true) ; U = GB_mx_mxArray_to_Matrix (pargin [4], "U", false, true) ; // count the triangles double t [2] ; int64_t ntri ; METHOD (tricount (&ntri, method, A, E, L, U, t)) ; // return ntri to MATLAB pargout [0] = mxCreateDoubleScalar ((double) ntri) ; // return t to MATLAB (compute time) if (nargout > 0) { pargout [1] = mxCreateDoubleScalar (t [0] + t [1]) ; } FREE_ALL ; GrB_finalize ( ) ; }
int main (int argc, char **argv) { //-------------------------------------------------------------------------- // initializations //-------------------------------------------------------------------------- GrB_Info info ; GrB_Matrix A = NULL ; PageRank *Pd = NULL, *P2 = NULL ; iPageRank *Pi = NULL ; double tic [2], t ; OK (GrB_init (GrB_NONBLOCKING)) ; fprintf (stderr, "\npagerank_demo:\n") ; printf ( "\npagerank_demo:\n") ; //-------------------------------------------------------------------------- // read a matrix from stdin //-------------------------------------------------------------------------- bool one_based = false ; if (argc > 1) one_based = strtol (argv [1], NULL, 0) ; OK (read_matrix (&A, stdin, // read matrix from stdin false, // unsymmetric false, // self edges OK one_based, // 0-based or 1-based, depending on input arg true, // read input file as Boolean true)) ; // print status to stdout GrB_Index n, nvals ; OK (GrB_Matrix_nrows (&n, A)) ; OK (GrB_Matrix_nvals (&nvals, A)) ; //-------------------------------------------------------------------------- // compute the page rank via a real semiring //-------------------------------------------------------------------------- simple_tic (tic) ; OK (dpagerank (&Pd, A)) ; t = simple_toc (tic) ; fprintf (stderr, "n %g edges %g dpagerank time : %14.6f iters: 20\n", (double) n, (double) nvals, t) ; printf ( "n %g edges %g dpagerank time : %14.6f iters: 20\n", (double) n, (double) nvals, t) ; //-------------------------------------------------------------------------- // compute the page rank via an integer semiring //-------------------------------------------------------------------------- simple_tic (tic) ; OK (ipagerank (&Pi, A)) ; t = simple_toc (tic) ; fprintf (stderr, "n %g edges %g ipagerank time : %14.6f iters: 20\n", (double) n, (double) nvals, t) ; printf ( "n %g edges %g ipagerank time : %14.6f iters: 20\n", (double) n, (double) nvals, t) ; //-------------------------------------------------------------------------- // compute the page rank via an extreme semiring //-------------------------------------------------------------------------- int iters ; simple_tic (tic) ; OK (dpagerank2 (&P2, A, 100, 1e-5, &iters, GxB_DEFAULT)) ; t = simple_toc (tic) ; fprintf (stderr, "n %g edges %g dpagerank time : %14.6f iters: %d\n", (double) n, (double) nvals, t, iters) ; printf ( "n %g edges %g dpagerank time : %14.6f iters: %d\n", (double) n, (double) nvals, t, iters) ; //-------------------------------------------------------------------------- // print results //-------------------------------------------------------------------------- int64_t limit = MIN (n, 5000) ; printf ("Top %g nodes:\n", (double) limit) ; for (int64_t i = 0 ; i < limit ; i++) { printf ("%5g d:[%6g : %16.8e] i:[%6g : %16.8e] x:[%6g : %16.8e]", (double) i, (double) Pd [i].page, (double) Pd [i].pagerank, (double) Pi [i].page, (double) Pi [i].pagerank, (double) P2 [i].page, (double) P2 [i].pagerank) ; if (Pd [i].page != Pi [i].page || Pd [i].page != P2 [i].page) { printf ("mismatch") ; } printf ("\n") ; } //-------------------------------------------------------------------------- // free all workspace //-------------------------------------------------------------------------- FREE_ALL ; GrB_finalize ( ) ; }