diff --git a/include/spm.h b/include/spm.h index ba5e97cf17d96ebd3499dd9c6f8b957d8a78ce9c..ab4406ff7dbd844ac88a7c9e6f32fb0f3a730cb8 100644 --- a/include/spm.h +++ b/include/spm.h @@ -187,6 +187,7 @@ int spmGenVec( spm_rhstype_t type, void *x, spm_int_t incx ); int spmGenRHS( spm_rhstype_t type, + spm_coeftype_t flttype, spm_int_t nrhs, const spmatrix_t *spm, void * opt_X, diff --git a/src/spm_rhs.c b/src/spm_rhs.c index 4b299359f827ec6ff9181ae57c3013bdfdc72698..5715508ede17b430e9b146a84a3859b98fc67444 100644 --- a/src/spm_rhs.c +++ b/src/spm_rhs.c @@ -91,6 +91,11 @@ spmPrintRHS( const spmatrix_t *spm, * x is a random vector in the range [-0.5, 0.5] * - SpmRhsRndB: b is computed randomly and x is not computed. * + * @param[in] flttype + * If spm->flttype == SpmPatern and flttype != SpmPatern then flttype + * is the type of b and x. + * If spm->flttype != SpmPatern then b and x are spm->flttype. + * * @param[in] nrhs * Defines the number of right hand side that must be generated. * @@ -122,6 +127,7 @@ spmPrintRHS( const spmatrix_t *spm, *******************************************************************************/ int spmGenRHS( spm_rhstype_t type, + spm_coeftype_t flttype, spm_int_t nrhs, const spmatrix_t *spm, void *x, @@ -129,14 +135,19 @@ spmGenRHS( spm_rhstype_t type, void *b, spm_int_t ldb ) { + int id; static int (*ptrfunc[4])( spm_rhstype_t, int, const spmatrix_t *, void *, int, void *, int ) = { s_spmGenRHS, d_spmGenRHS, c_spmGenRHS, z_spmGenRHS }; - - int id = spm->flttype - SpmFloat; + if ( spm->flttype == SpmPattern ) { + id = flttype - SpmFloat; + } + else { + id = spm->flttype - SpmFloat; + } if ( (x != NULL) && (ldx < spm_imax( 1, spm->nexp )) ) { fprintf( stderr, "spmGenRHS: ldx must be >= max( 1, spm->nexp )\n" ); diff --git a/src/z_spm_genrhs.c b/src/z_spm_genrhs.c index 293a9f05c0140449b906e6966982c54aebac2bb6..f51e2dc792c10548f9de50cddf6c1d7c695fe7a9 100644 --- a/src/z_spm_genrhs.c +++ b/src/z_spm_genrhs.c @@ -111,11 +111,17 @@ z_spmGenRHS( spm_rhstype_t type, /* If random b, we do it and exit */ if ( type == SpmRhsRndB ) { - /* Compute the spm norm to scale the b vector */ - spm_complex64_t norm = z_spmNorm( SpmFrobeniusNorm, spm ); - if ( norm == 0. ) { + spm_complex64_t norm; + if ( spm->flttype == SpmPattern ) { norm = 1.; } + else { + /* Compute the spm norm to scale the b vector */ + norm = z_spmNorm( SpmFrobeniusNorm, spm ); + if ( norm == 0. ) { + norm = 1.; + } + } z_spmGenMat( type, nrhs, spm, &norm, 24356, bptr, ldb ); return SPM_SUCCESS; diff --git a/tests/spm_dist_genrhs_tests.c b/tests/spm_dist_genrhs_tests.c index cf343bfc556a0720ff95ed1928a3413ca876338e..60299452bd00c8c335e04ebf95a4389bf9b34c8b 100644 --- a/tests/spm_dist_genrhs_tests.c +++ b/tests/spm_dist_genrhs_tests.c @@ -76,7 +76,7 @@ int main (int argc, char **argv) memset( bloc, 0xab, sizeloc ); ldx = spm_imax( 1, original.nexp ); - if ( spmGenRHS( type, nrhs, &original, + if ( spmGenRHS( type, spmd.flttype, nrhs, &original, NULL, ldx, bloc, ldx ) != SPM_SUCCESS ) { fprintf( stderr, "Issue to generate the local rhs\n" ); continue; @@ -104,7 +104,7 @@ int main (int argc, char **argv) memset( bdst, 0xab, sizedst ); ldx = spm_imax( 1, spmd.nexp ); - if ( spmGenRHS( type, nrhs, &spmd, + if ( spmGenRHS( type, spmd.flttype, nrhs, &spmd, NULL, ldx, bdst, ldx ) != SPM_SUCCESS ) { err++; continue; diff --git a/wrappers/fortran90/examples/spmf_driver.F90 b/wrappers/fortran90/examples/spmf_driver.F90 index dcd1bdd75c981e7feaaae9468c73a4d1c11632c5..1509ac3f13752adaaf301ca8c79a3f09915afd57 100644 --- a/wrappers/fortran90/examples/spmf_driver.F90 +++ b/wrappers/fortran90/examples/spmf_driver.F90 @@ -50,7 +50,7 @@ program spmf_driver allocate(b( spm%nexp, nrhs)) ! Compute b = A * x, with x random - call spmGenRHS( SpmRhsRndX, nrhs, spm, x0, spm%nexp, b, spm%nexp, info ) + call spmGenRHS( SpmRhsRndX, spm%flttype, nrhs, spm, x0, spm%nexp, b, spm%nexp, info ) ! Copy x0 into x x = x0 diff --git a/wrappers/fortran90/examples/spmf_user.F90 b/wrappers/fortran90/examples/spmf_user.F90 index a3a58bc02d3adf663997d3af13b9bc2cd61984c2..42e7687e38e91ca527df40a79ec58899db416f8a 100644 --- a/wrappers/fortran90/examples/spmf_user.F90 +++ b/wrappers/fortran90/examples/spmf_user.F90 @@ -129,7 +129,7 @@ program spmf_user allocate(b( spm%nexp, nrhs)) ! Compute b = A * x, with x random - call spmGenRHS( SpmRhsRndX, nrhs, spm, x0, spm%nexp, b, spm%nexp, info ) + call spmGenRHS( SpmRhsRndX, spm%flttype, nrhs, spm, x0, spm%nexp, b, spm%nexp, info ) ! Copy x0 into x x = x0 diff --git a/wrappers/fortran90/src/spm_f2c.c b/wrappers/fortran90/src/spm_f2c.c index 573e4d3371aea587db4e3df8ef14b6e3fe810ff4..eef3479bc8fcfe4c31d195ee197fb3029800e2f5 100644 --- a/wrappers/fortran90/src/spm_f2c.c +++ b/wrappers/fortran90/src/spm_f2c.c @@ -9,7 +9,7 @@ * @version 1.2.0 * @author Mathieu Faverge * @author Tony Delarue - * @date 2022-02-22 + * @date 2022-10-10 * * This file has been automatically generated with gen_wrappers.py * @@ -255,6 +255,7 @@ spmGenVec_f2c( spm_rhstype_t type, int spmGenRHS_f2c( spm_rhstype_t type, + spm_coeftype_t flttype, spm_int_t nrhs, const spmatrix_t *spm, void *opt_X, @@ -262,7 +263,7 @@ spmGenRHS_f2c( spm_rhstype_t type, void *B, spm_int_t ldb ) { - return spmGenRHS( type, nrhs, spm, opt_X, opt_ldx, B, ldb ); + return spmGenRHS( type, flttype, nrhs, spm, opt_X, opt_ldx, B, ldb ); } int diff --git a/wrappers/fortran90/src/spmf_bindings.f90 b/wrappers/fortran90/src/spmf_bindings.f90 index e146ab3d5f11553f361259973c5faaea6481c0dd..afe4c1890de031ce6ef227353ae6b1720d81ade8 100644 --- a/wrappers/fortran90/src/spmf_bindings.f90 +++ b/wrappers/fortran90/src/spmf_bindings.f90 @@ -9,7 +9,7 @@ !> @version 1.2.0 !> @author Mathieu Faverge !> @author Tony Delarue -!> @date 2022-02-22 +!> @date 2022-10-10 !> !> This file has been automatically generated with gen_wrappers.py !> @@ -312,13 +312,14 @@ module spmf_bindings integer(kind=spm_int_t), value :: incx end function spmGenVec_f2c - function spmGenRHS_f2c(type, nrhs, spm, opt_X, opt_ldx, B, ldb) & + function spmGenRHS_f2c(type, flttype, nrhs, spm, opt_X, opt_ldx, B, ldb) & bind(c, name='spmGenRHS_f2c') use :: iso_c_binding, only : c_int, c_ptr use :: spmf_enums, only : spm_int_t implicit none integer(kind=c_int) :: spmGenRHS_f2c integer(c_int), value :: type + integer(c_int), value :: flttype integer(kind=spm_int_t), value :: nrhs type(c_ptr), value :: spm type(c_ptr), value :: opt_X diff --git a/wrappers/fortran90/src/spmf_enums.F90 b/wrappers/fortran90/src/spmf_enums.F90 index 4485329d6e23450bec51236c58f320c32f171889..406187c4fd4de46359731e6b1cd58b2354730b8d 100644 --- a/wrappers/fortran90/src/spmf_enums.F90 +++ b/wrappers/fortran90/src/spmf_enums.F90 @@ -9,7 +9,7 @@ !> @version 1.2.0 !> @author Mathieu Faverge !> @author Tony Delarue -!> @date 2022-02-22 +!> @date 2022-10-10 !> !> This file has been automatically generated with gen_wrappers.py !> diff --git a/wrappers/fortran90/src/spmf_functions.f90 b/wrappers/fortran90/src/spmf_functions.f90 index d6fa2f9999c995bb5803686979f920da4d5493aa..210d003e1c787bae2aa981c4cddd4b3593a6a80f 100644 --- a/wrappers/fortran90/src/spmf_functions.f90 +++ b/wrappers/fortran90/src/spmf_functions.f90 @@ -9,7 +9,7 @@ !> @version 1.2.0 !> @author Mathieu Faverge !> @author Tony Delarue -!> @date 2022-02-22 +!> @date 2022-10-10 !> !> This file has been automatically generated with gen_wrappers.py !> @@ -545,7 +545,8 @@ subroutine spmGenVec_f08(type, spm, alpha, seed, x, incx, info) end subroutine spmGenVec_f08 -subroutine spmGenRHS_f08(type, nrhs, spm, opt_X, opt_ldx, B, ldb, info) +subroutine spmGenRHS_f08(type, flttype, nrhs, spm, opt_X, opt_ldx, B, ldb, & + info) use :: spmf_interfaces, only : spmGenRHS use :: spmf_bindings, only : spmGenRHS_f2c use :: iso_c_binding, only : c_int, c_loc, c_null_ptr, c_ptr @@ -553,6 +554,7 @@ subroutine spmGenRHS_f08(type, nrhs, spm, opt_X, opt_ldx, B, ldb, info) use :: spmf_enums, only : spm_int_t, spmatrix_t implicit none integer(c_int), intent(in) :: type + integer(c_int), intent(in) :: flttype integer(kind=spm_int_t), intent(in) :: nrhs type(spmatrix_t), intent(in), target :: spm class(*), intent(inout), target, optional :: opt_X(:,:) @@ -570,7 +572,8 @@ subroutine spmGenRHS_f08(type, nrhs, spm, opt_X, opt_ldx, B, ldb, info) if ( present(opt_ldx) ) x_opt_ldx = opt_ldx x_B = spmGetCptrFrom2dArray(B) - x_info = spmGenRHS_f2c(type, nrhs, c_loc(spm), x_opt_X, x_opt_ldx, x_B, ldb) + x_info = spmGenRHS_f2c(type, flttype, nrhs, c_loc(spm), x_opt_X, x_opt_ldx, & + x_B, ldb) if ( present(info) ) info = x_info end subroutine spmGenRHS_f08 diff --git a/wrappers/fortran90/src/spmf_interfaces.f90 b/wrappers/fortran90/src/spmf_interfaces.f90 index 96261de4a76f2db1faf59ac4e4395a866ab488a2..6cfa4b4e8531b4d63b4c6e6da14a58b2b3ea285e 100644 --- a/wrappers/fortran90/src/spmf_interfaces.f90 +++ b/wrappers/fortran90/src/spmf_interfaces.f90 @@ -9,7 +9,7 @@ !> @version 1.2.0 !> @author Mathieu Faverge !> @author Tony Delarue -!> @date 2022-02-22 +!> @date 2022-10-10 !> !> This file has been automatically generated with gen_wrappers.py !> @@ -331,12 +331,14 @@ module spmf_interfaces end interface spmGenVec interface spmGenRHS - subroutine spmGenRHS_f08(type, nrhs, spm, opt_X, opt_ldx, B, ldb, info) + subroutine spmGenRHS_f08(type, flttype, nrhs, spm, opt_X, opt_ldx, B, & + ldb, info) use :: iso_c_binding, only : c_int, c_ptr use :: spmf_bindings, only : spmGetCptrFrom2dArray use :: spmf_enums, only : spm_int_t, spmatrix_t implicit none integer(c_int), intent(in) :: type + integer(c_int), intent(in) :: flttype integer(kind=spm_int_t), intent(in) :: nrhs type(spmatrix_t), intent(in), target :: spm class(*), intent(inout), target, optional :: opt_X(:,:) diff --git a/wrappers/julia/spm/src/spm.jl b/wrappers/julia/spm/src/spm.jl index 65166de92120c787c55e330f3b43ba066c8d5b57..e34f5313416f3057a63159942bf9be7c8363164e 100644 --- a/wrappers/julia/spm/src/spm.jl +++ b/wrappers/julia/spm/src/spm.jl @@ -11,7 +11,7 @@ @author Mathieu Faverge @author Selmane Lebdaoui @author Tony Delarue - @date 2022-02-22 + @date 2022-10-10 This file has been automatically generated with gen_wrappers.py @@ -139,7 +139,7 @@ end end @cbindings libspm begin - @cextern spmGenRHS( type::spm_rhstype_t, nrhs::spm_int_t, spm::Ptr{spmatrix_t}, opt_X::Ptr{Cvoid}, opt_ldx::spm_int_t, B::Ptr{Cvoid}, ldb::spm_int_t )::Cint + @cextern spmGenRHS( type::spm_rhstype_t, flttype::spm_coeftype_t, nrhs::spm_int_t, spm::Ptr{spmatrix_t}, opt_X::Ptr{Cvoid}, opt_ldx::spm_int_t, B::Ptr{Cvoid}, ldb::spm_int_t )::Cint end @cbindings libspm begin diff --git a/wrappers/julia/spm/src/spm_enums.jl.in b/wrappers/julia/spm/src/spm_enums.jl.in index 755d4b0482ad268fd77d8014adf71591dd4ee83c..95ce065736b09004d501e531266601a3f9d889f5 100644 --- a/wrappers/julia/spm/src/spm_enums.jl.in +++ b/wrappers/julia/spm/src/spm_enums.jl.in @@ -11,7 +11,7 @@ @author Mathieu Faverge @author Selmane Lebdaoui @author Tony Delarue - @date 2022-02-22 + @date 2022-10-10 This file has been automatically generated with gen_wrappers.py diff --git a/wrappers/julia/spm_driver.jl b/wrappers/julia/spm_driver.jl index 1ad73704a7774862fb061471429994bc567978e6..0cf83159f5b402b4cc8fda12ef08d381b07671f8 100755 --- a/wrappers/julia/spm_driver.jl +++ b/wrappers/julia/spm_driver.jl @@ -57,7 +57,7 @@ X0 = zeros( Cdouble, (n, nrhs) ) B = zeros( Cdouble, (n, nrhs) ) X = zeros( Cdouble, (n, nrhs) ) -spm.spmGenRHS( spm.SpmRhsRndX, nrhs, Aptr, X, n, B, n ) +spm.spmGenRHS( spm.SpmRhsRndX, A.flttype, nrhs, Aptr, X, n, B, n ) # Copy x0 into x for backup X0 = copy(X) diff --git a/wrappers/julia/spm_user.jl b/wrappers/julia/spm_user.jl index 928b68f4058b607dba69dc05ef0c3c802630b838..290b6f651f893b4f17a5af18776695adc35a7c44 100755 --- a/wrappers/julia/spm_user.jl +++ b/wrappers/julia/spm_user.jl @@ -144,7 +144,7 @@ x0 = zeros( Cdouble, ( A.nexp, nrhs ) ) b = zeros( Cdouble, ( A.nexp, nrhs ) ) x = zeros( Cdouble, ( A.nexp, nrhs ) ) -spm.spmGenRHS( spm.SpmRhsRndX, nrhs, Aptr, x0, n, b, n ) +spm.spmGenRHS( spm.SpmRhsRndX, A.flttype, nrhs, Aptr, x0, n, b, n ) # Copy x0 into x for backup x = x0 diff --git a/wrappers/python/spm/__spm__.py b/wrappers/python/spm/__spm__.py index 9bf4b51325557f8dd91f418750d31de21685c410..b6bf886ed6fd60d15ce24c0e396179600969e03b 100644 --- a/wrappers/python/spm/__spm__.py +++ b/wrappers/python/spm/__spm__.py @@ -11,7 +11,7 @@ @author Pierre Ramet @author Mathieu Faverge @author Tony Delarue - @date 2022-02-22 + @date 2022-10-10 This file has been automatically generated with gen_wrappers.py @@ -217,11 +217,12 @@ def pyspm_spmGenVec( type, spm, alpha, seed, x, incx ): libspm.spmGenVec.restype = c_int return libspm.spmGenVec( type, spm, alpha, seed, x, incx ) -def pyspm_spmGenRHS( type, nrhs, spm, opt_X, opt_ldx, B, ldb ): - libspm.spmGenRHS.argtypes = [ c_int, __spm_int__, POINTER(pyspm_spmatrix_t), - c_void_p, __spm_int__, c_void_p, __spm_int__ ] +def pyspm_spmGenRHS( type, flttype, nrhs, spm, opt_X, opt_ldx, B, ldb ): + libspm.spmGenRHS.argtypes = [ c_int, c_int, __spm_int__, + POINTER(pyspm_spmatrix_t), c_void_p, + __spm_int__, c_void_p, __spm_int__ ] libspm.spmGenRHS.restype = c_int - return libspm.spmGenRHS( type, nrhs, spm, opt_X, opt_ldx, B, ldb ) + return libspm.spmGenRHS( type, flttype, nrhs, spm, opt_X, opt_ldx, B, ldb ) def pyspm_spmCheckAxb( eps, nrhs, spm, opt_X0, opt_ldx0, B, ldb, X, ldx ): libspm.spmCheckAxb.argtypes = [ c_double, __spm_int__, diff --git a/wrappers/python/spm/enum.py.in b/wrappers/python/spm/enum.py.in index c54ac7aa492209be76c39dc1a1220cf7983bab93..1fa51e42f69361f1e6163b68e3962fe1961bd703 100644 --- a/wrappers/python/spm/enum.py.in +++ b/wrappers/python/spm/enum.py.in @@ -11,7 +11,7 @@ @author Pierre Ramet @author Mathieu Faverge @author Tony Delarue - @date 2022-02-22 + @date 2022-10-10 This file has been automatically generated with gen_wrappers.py diff --git a/wrappers/python/spm/spm.py b/wrappers/python/spm/spm.py index 8be45587202702c3ec3e9ad5f86030053bc8d229..239e4955771fd54715a2082a903b14882bb40146 100644 --- a/wrappers/python/spm/spm.py +++ b/wrappers/python/spm/spm.py @@ -262,7 +262,7 @@ class spmatrix(): ldx = 1 xptr = None - info = pyspm_spmGenRHS( rhstype, nrhs, self.id_ptr, + info = pyspm_spmGenRHS( rhstype, self.spm_c.flttype, nrhs, self.id_ptr, xptr, ldx, b.ctypes.data_as( c_void_p ), ldb ) return x, b