File: simple_demo.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (75 lines) | stat: -rw-r--r-- 1,871 bytes parent folder | download | duplicates (2)
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
70
71
72
73
74
75
//------------------------------------------------------------------------------
// GraphBLAS/Demo/Program/simple_demo.c: tests simple_rand
//------------------------------------------------------------------------------

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

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

/*
    A simple test that illustrates the use of simple_rand.
    This test does not require C11, nor GraphBLAS.  It only tests the
    simple_* Demo functions.  The output of this test should look like the
    following.  The random numbers should be the same.  On a Mac OSX system:

        first 10 random numbers:
            0.513871
            0.175726
            0.308634
            0.534532
            0.947630
            0.171728
            0.702231
            0.226417
            0.494766
            0.124699

    The random numbers are identical on linux, as desired.
*/

#include "simple_rand.h"
#include <stdio.h>
#include <stdlib.h>

#define LEN 10000000

int main (void)
{
    double *x ;
    int i ;

    fprintf (stderr, "simple_demo:\n") ;

    // calloc the space for more accurate timing
    x = (double *) calloc (LEN, sizeof (double)) ;
    if (x == NULL)
    {
        fprintf (stderr, "simple_demo: out of memory\n") ;
        exit (1) ;
    }
    
    uint64_t state = 1 ;

    // generate random numbers
    for (i = 0 ; i < LEN ; i++)
    {
        x [i] = simple_rand_x (&state) ;
    }

    // these should be the same on any system and any compiler
    printf ("first 10 random numbers:\n") ;
    for (i = 0 ; i < 10 ; i++)
    {
        printf ("%12.6f\n", x [i]) ;
    }

    // generate random uint64_t numbers
    for (i = 0 ; i < LEN ; i++)
    {
        simple_rand (&state) ;
    }

    free (x) ;
}