5 @brief SpM example to generate a sparse matrix from the spm drivers
7 @copyright 2019-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8 Univ. Bordeaux. All rights reserved.
11 @author Mathieu Faverge
12 @author Selmane Lebdaoui
16 @ingroup examples_julia
32# Two solutions to select the outpu file to pass to output functions
34my_stdout = Libc.FILE( Libc.RawFD(1), "w" ) # Select the stdout or stderr through 1 or 2
35#my_stdout = Ptr{Cvoid}(0) # Give a null pointer to use the default
37A = spm.spmatrix_t(zero)
38Aptr = Ptr{spm.spmatrix_t}(pointer_from_objref(A))
40# Example from a HB file
41#spm.spmReadDriver( spm.SpmDriverHB, "__SPM_DIR__/tests/matrix/orsirr.rua", Aptr )
43# Example from the Laplacian generator driver
44spm.spmReadDriver( spm.SpmDriverLaplacian, "10:10:10:2.:1.", Aptr )
46spm.spmPrintInfo( Aptr, my_stdout )
48# Scale A for low-rank: A / ||A||_f
49norm = spm.spmNorm( spm.SpmFrobeniusNorm, Aptr )
50spm.spmScal( 1. / norm, Aptr )
52# Generate b and x0 vectors such that A * x0 = b
56X0 = zeros( Cdouble, (n, nrhs) )
57B = zeros( Cdouble, (n, nrhs) )
58X = zeros( Cdouble, (n, nrhs) )
60spm.spmGenRHS( spm.SpmRhsRndX, nrhs, Aptr, X, n, B, n )
62# Copy x0 into x for backup
66eps = 1.e-15 # Set to 1e-7 for single precision
67spm.spmCheckAxb( eps, nrhs, Aptr, X0, n, B, n, X, n )