5 @brief Julia SpM example using a laplacian matrix.
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
34A = spm.spmatrix_t(zero)
35Aptr = pointer_from_objref(A)
38# Two solutions to select the outpu file to pass to output functions
40my_stdout = Libc.FILE( Libc.RawFD(1), "w" ) # Select the stdout or stderr through 1 or 2
41#my_stdout = Ptr{Cvoid}(0) # Give a null pointer to use the default
44#Generate a 10x10x10 complex Laplacian in IJV format
50nnz = (2*(dim1)-1) * dim2 * dim3 + (dim2-1)*dim1*dim3 + dim2*dim1*(dim3-1)
52#Create the spm out of the internal data
55A.mtxtype = spm.SpmSymmetric
56A.flttype = spm.SpmDouble
62spm.spmUpdateComputedFields( Aptr )
64# Allocate the arrays of the spm through C functions
67# Get the pointer to the allocated arrays
68row = unsafe_wrap(Array, A.rowptr, A.nnzexp, own = false)
69col = unsafe_wrap(Array, A.colptr, A.nnzexp, own = false)
70val = unsafe_wrap(Array{Cdouble,1}, convert( Ptr{Cdouble}, A.values ), A.nnzexp, own = false)
77 row[m] = (i-1) + dim1 * (j-1) + dim1 * dim2 * (k-1) + 1
78 col[m] = (i-1) + dim1 * (j-1) + dim1 * dim2 * (k-1) + 1
101 row[m] = i + dim1 * (j-1) + dim1 * dim2 * (k-1) + 1
102 col[m] = (i-1) + dim1 * (j-1) + dim1 * dim2 * (k-1) + 1
107 row[m] = (i-1) + dim1 * j + dim1 * dim2 * (k-1) + 1
108 col[m] = (i-1) + dim1 * (j-1) + dim1 * dim2 * (k-1) + 1
113 row[m] = (i-1) + dim1 * (j-1) + dim1 * dim2 * k + 1
114 col[m] = (i-1) + dim1 * (j-1) + dim1 * dim2 * (k-1) + 1
123 println( "m ", m, "nnz ", nnz )
126A2 = spm.spmatrix_t( zero )
127A2ptr = Ptr{spm.spmatrix_t}( pointer_from_objref(A2) )
128rc = spm.spmCheckAndCorrect( Aptr, A2ptr )
138spm.spmPrintInfo( Aptr, my_stdout )
140# 2- The right hand side
143x0 = zeros( Cdouble, ( A.nexp, nrhs ) )
144b = zeros( Cdouble, ( A.nexp, nrhs ) )
145x = zeros( Cdouble, ( A.nexp, nrhs ) )
147spm.spmGenRHS( spm.SpmRhsRndX, nrhs, Aptr, x0, n, b, n )
149# Copy x0 into x for backup
152# Check that A * x = b
153eps = 1.e-15 # Set to 1e-7 for single precision
154spm.spmCheckAxb( eps, nrhs, Aptr, x, n, b, n, x0, n )