MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / main

Function main

deps/GraphBLAS/Demo/InProgress/gpu_reduce_demo.c:17–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15 #define N 16384
16
17int main (void)
18{
19
20 #if defined ( _OPENMP )
21 double t0 = omp_get_wtime ( ) ;
22 #endif
23
24 // start GraphBLAS
25 GrB_init (GrB_NONBLOCKING) ;
26 printf ("demo: reduce a matrix to a scalar\n") ;
27
28 int nthreads_max ;
29 GxB_get (GxB_NTHREADS, &nthreads_max) ;
30 printf ("# of threads: %d\n", nthreads_max) ;
31
32 #if defined ( _OPENMP )
33 t0 = omp_get_wtime ( ) - t0 ;
34 printf ("GPU warmup time: %g\n", t0) ;
35 t0 = omp_get_wtime ( ) ;
36 #endif
37
38 GrB_Index nrows = N ;
39 GrB_Index ncols = N ;
40 GrB_Matrix A ;
41 GrB_Matrix_new (&A, GrB_INT64, nrows, ncols) ;
42
43 GrB_Index *I = malloc (nrows * ncols * sizeof (GrB_Index)) ;
44 GrB_Index *J = malloc (nrows * ncols * sizeof (GrB_Index)) ;
45 int64_t *X = malloc (nrows * ncols * sizeof (int64_t)) ;
46
47 #pragma omp parallel for num_threads(nthreads_max) collapse(2) \
48 schedule(static)
49 for (int64_t i = 0 ; i < nrows ; i++)
50 {
51 for (int64_t j = 0 ; j < ncols ; j++)
52 {
53 int64_t k = i * N + j ;
54 // int x = (int) (rand ( ) & 0xFF) ;
55 int x = (int) (k & 0xFF) ;
56 I [k] = i ;
57 J [k] = j ;
58 X [k] = x ;
59 }
60 }
61
62 GrB_Index nvals = ((size_t) N) * ((size_t) N) ;
63 GrB_Matrix_build (A, I, J, X, nvals, GrB_PLUS_INT64) ;
64
65 GxB_print (A, 2) ;
66
67 free (I) ;
68 free (J) ;
69 free (X) ;
70
71 #if defined ( _OPENMP )
72 t0 = omp_get_wtime ( ) - t0 ;
73 printf ("time to create matrix: %g\n", t0) ;
74 #endif

Callers

nothing calls this directly

Calls 4

GrB_initFunction · 0.85
GrB_Matrix_newFunction · 0.85
GrB_Matrix_nvalsFunction · 0.85
GrB_finalizeFunction · 0.85

Tested by

no test coverage detected