#include "LAGraph_demo.h"
#define NTHREAD_LIST 1
#define THREAD_LIST 0
#define LG_FREE_ALL \
{ \
GrB_free (&A) ; \
GrB_free (&Abool) ; \
GrB_free (&PR) ; \
LAGraph_Delete (&G, msg) ; \
if (f != NULL) fclose (f) ; \
}
int main (int argc, char **argv)
{
char msg [LAGRAPH_MSG_LEN] ;
LAGraph_Graph G = NULL ;
GrB_Matrix A = NULL ;
GrB_Matrix Abool = NULL ;
GrB_Vector PR = NULL ;
FILE *f = NULL ;
bool burble = false ;
demo_init (burble) ;
int nt = NTHREAD_LIST ;
int Nthreads [20] = { 0, THREAD_LIST } ;
int nthreads_max, nthreads_outer, nthreads_inner ;
LAGRAPH_TRY (LAGraph_GetNumThreads (&nthreads_outer, &nthreads_inner, msg)) ;
nthreads_max = nthreads_outer * nthreads_inner ;
if (Nthreads [1] == 0)
{
Nthreads [1] = nthreads_max ;
for (int t = 2 ; t <= nt ; t++)
{
Nthreads [t] = Nthreads [t-1] / 2 ;
if (Nthreads [t] == 0) nt = t-1 ;
}
}
printf ("threads to test: ") ;
for (int t = 1 ; t <= nt ; t++)
{
int nthreads = Nthreads [t] ;
if (nthreads > nthreads_max) continue ;
printf (" %d", nthreads) ;
}
printf ("\n") ;
char *matrix_name = (argc > 1) ? argv [1] : "stdin" ;
LAGRAPH_TRY (readproblem (&G, NULL,
false, false, true, NULL, false, argc, argv)) ;
GrB_Index n, nvals ;
GRB_TRY (GrB_Matrix_nrows (&n, G->A)) ;
GRB_TRY (GrB_Matrix_nvals (&nvals, G->A)) ;
LAGRAPH_TRY (LAGraph_Cached_OutDegree (G, msg)) ;
GrB_Index nsinks ;
GRB_TRY (GrB_Vector_nvals (&nvals, G->out_degree)) ;
nsinks = n - nvals ;
printf ("nsinks: %" PRIu64 "\n", nsinks) ;
fflush (stdout) ; fflush (stderr) ;
float damping = 0.85 ;
float tol = 1e-4 ;
int iters = 0, itermax = 100 ;
double t1 = LAGraph_WallClockTime ( ) ;
LAGRAPH_TRY (LAGraph_SetNumThreads (1, nthreads_max, msg)) ;
LAGRAPH_TRY (LAGr_PageRankGAP (&PR, &iters, G,
damping, tol, itermax, msg)) ;
t1 = LAGraph_WallClockTime ( ) - t1 ;
printf ("warmup: %10.4f sec\n", t1) ;
fflush (stdout) ; fflush (stderr) ;
int ntrials = 16 ;
printf ("# of trials: %d\n", ntrials) ;
for (int kk = 1 ; kk <= nt ; kk++)
{
int nthreads = Nthreads [kk] ;
if (nthreads > nthreads_max) continue ;
LAGRAPH_TRY (LAGraph_SetNumThreads (1, nthreads, msg)) ;
printf ("\n--------------------------- nthreads: %2d\n", nthreads) ;
double total_time = 0 ;
for (int trial = 0 ; trial < ntrials ; trial++)
{
GrB_free (&PR) ;
double t1 = LAGraph_WallClockTime ( ) ;
LAGRAPH_TRY (LAGr_PageRankGAP (&PR, &iters, G,
damping, tol, itermax, msg)) ;
t1 = LAGraph_WallClockTime ( ) - t1 ;
printf ("trial: %2d time: %10.4f sec\n", trial, t1) ;
fflush (stdout) ; fflush (stderr) ;
total_time += t1 ;
}
float rsum ;
GRB_TRY (GrB_reduce (&rsum, NULL, GrB_PLUS_MONOID_FP32, PR, NULL)) ;
double t = total_time / ntrials ;
printf ( "Avg: PR(gap) threads %3d: %10.3f sec (%2d iters), graph: %s\n",
nthreads, t, iters, matrix_name) ;
fprintf (stderr, "Avg: PR(gap) threads %3d: %10.3f sec (%2d iters), graph: %s\n",
nthreads, t, iters, matrix_name) ;
fflush (stdout) ; fflush (stderr) ;
}
#if 0#endif
LG_FREE_ALL ;
LAGRAPH_TRY (LAGraph_Finalize (msg)) ;
return (GrB_SUCCESS) ;
}