File: import_demo.c

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (69 lines) | stat: -rw-r--r-- 2,247 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//------------------------------------------------------------------------------
// GraphBLAS/Demo/Program/import_demo.c: test import/export
//------------------------------------------------------------------------------

// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//------------------------------------------------------------------------------

// Read a graph from a file and test import/export. Usage:
//
//  import_demo < infile

// macro used by OK(...) to free workspace if an error occurs
#define FREE_ALL            \
    GrB_Matrix_free (&A) ;  \

#include "graphblas_demos.h"

int main (int argc, char **argv)
{
    GrB_Matrix A = NULL ;
    GrB_Info info ;
    OK (GrB_init (GrB_NONBLOCKING)) ;
    int nthreads ;
    OK (GxB_Global_Option_get (GxB_GLOBAL_NTHREADS, &nthreads)) ;
    fprintf (stderr, "import_demo: nthreads: %d\n", nthreads) ;

    //--------------------------------------------------------------------------
    // get a matrix
    //--------------------------------------------------------------------------

    // usage:  ./main  < file
    //         ./main 0 dump < file
    //         ./main 1 dump < file
    //
    // default is 0-based, for the matrices in the Matrix/ folder

    bool one_based = false ;
    bool dump = false ;
    if (argc > 1) one_based = strtol (argv [1], NULL, 0) ;
    if (argc > 2) dump      = strtol (argv [2], NULL, 0) ;

    OK (read_matrix (&A, stdin, false, false, one_based, false, false)) ;

    for (int hyper = 0 ; hyper <= 1 ; hyper++)
    {
        for (int csc = 0 ; csc <= 1 ; csc++)
        {
            double h = hyper ? GxB_ALWAYS_HYPER : GxB_NEVER_HYPER ;
            GxB_Format_Value f = csc ? GxB_BY_COL : GxB_BY_ROW ;

            printf ("\n######### input A: hyper %d csc %d\n", hyper, csc) ;

            for (int format = 0 ; format <= 3 ; format++)
            {
                OK (GxB_Matrix_Option_set (A, GxB_HYPER_SWITCH, h)) ;
                OK (GxB_Matrix_Option_set (A, GxB_FORMAT, f)) ;
                OK (import_test (&A, format, dump)) ;
            }
        }
    }

    FREE_ALL ;

    OK (GrB_finalize ( )) ;
    printf ("import_demo: all tests passed\n") ;
}