Test Matrix in MAGMA

19 views
Skip to first unread message

Xiniz Ronda

unread,
Jul 6, 2022, 6:08:05 PMJul 6
to magma...@icl.utk.edu

Hi,

I think my message has not been sent, so I am writing again.


As I am seeing inside of the thesting directory there are some functions to generate matrices for tests. I am able to generate rand and randn by this option: --matrix rand.


I think it is calling a LAPACK function. In description of LAPACK we have: 


         IDIST is INTEGER

          Specifies the distribution of the random numbers:

          = 1:  uniform (0,1)

          = 2:  uniform (-1,1)

          = 3:  normal (0,1)


Are we able inside of MAGMA to specify the distribution?


Can I have a rand or randn with specified Condition number?


How is it possible to generate a matrix with a specified Condition number?


Do we have any method to generate matrices with large elements or other distributions in MAGMA which generate a bad condition matrix?


How are you importing the SuiteSparse Matrix Collectioninside of MAGMA?


Cheers

Stanimire Tomov

unread,
Jul 6, 2022, 6:46:13 PMJul 6
to Xiniz Ronda, magma...@icl.utk.edu
Hi,

On Jul 6, 2022, at 5:24 PM, Xiniz Ronda <ronda...@gmail.com> wrote:

Hi,
I think my message has not been sent, so I am writing again.

As I am seeing inside of the thesting directory there are some functions to generate matrices for tests. I am able to generate rand and randn by this option: --matrix rand.

I think it is calling a LAPACK function. In description of LAPACK we have: 

         IDIST is INTEGER
          Specifies the distribution of the random numbers:
          = 1:  uniform (0,1)
          = 2:  uniform (-1,1)
          = 3:  normal (0,1)

yes, you can specify to any of the testers one of these options
--matrix rand 
--matrix rands
--matrix randn   
to generate the corresponding distributions that you list above.


Are we able inside of MAGMA to specify the distribution?

yes for random numbers, as well as eigenvalue distribution when controlling the condition number.

See file magma_generate.cpp that describes all options.


Can I have a rand or randn with specified Condition number?

yes, for certain matrices, as described in magma_generate.cpp function magma_generate_matrix.
For example
./testing_dgetrf --cond 1000 -n 1000 --matrix svd_geo
will do LU factorization of matrix with condition number 1000, size 1000, 
and will have singular values with geometric distribution.

For every matrix that you see cond and sigma in the description, you can specify the 
condition number and the distribution:
    Matrix      Description                                                                                                
    zero        all entries are 0                                                                                          
    ones        all entries are 1                                                                                          
    identity    diagonal entries are 1                                                                                     
    jordan      diagonal and first subdiagonal entries are 1                                                               
    kronecker   A(i,j) = 1 + (m/cond) * kronecker_delta(i,j)                                                               

                                                                                                                           

    rand*       matrix entries random uniform on (0, 1)                                                                    
    rands*      matrix entries random uniform on (-1, 1)                                                                   
    randn*      matrix entries random normal with mean 0, sigma 1                                                          

                                                                                                                           

    diag#*      A = Sigma                                                                                                  
    svd#*       A = U Sigma V^H                                                                                            
    poev#*      A = V Sigma V^H  (eigenvalues positive [1], i.e., matrix SPD)                                              
    spd#*       alias for poev                                                                                             
    heev#*      A = V Lambda V^H (eigenvalues mixed signs)                                                                 
    syev#*      alias for heev                                                                                             
    geev#*      A = V T V^H, Schur-form T                       [not yet implemented]                                      
    geevx#*     A = X T X^{-1}, Schur-form T, X ill-conditioned [not yet implemented] 

    # optional distribution suffix                                                                                         
    _rand       sigma_i random uniform on (0, 1) [default]                                                                 
    _rands      sigma_i random uniform on (-1, 1)                                                                          
    _randn      sigma_i random normal with mean 0, std 1                                                                   
                [1] Note for _rands and _randn, Sigma contains negative values.                                            
                _rand* do not use cond, so the condition number is arbitrary.                                              
                For randn, Expected( log( cond ) ) = log( 4.65 n ) [Edelman, 1988].                                        

                                                                                                                           

    _logrand    log(sigma_i) uniform on (log(1/cond), log(1))                                                              
    _arith      sigma_i = 1 - (i - 1)/(n - 1)*(1 - 1/cond); sigma_{i+1} - sigma_i is constant                              
    _geo        sigma_i = (cond)^{ -(i-1)/(n-1) };          sigma_{i+1} / sigma_i is constant                              
    _cluster0   sigma = [ 1, 1/cond, ..., 1/cond ]; 1 unit value, n-1 small values                                         
    _cluster1   sigma = [ 1, ..., 1, 1/cond ];      n-1 unit values, 1 small value                                         
    _rarith     _arith,    reversed order                                                                                  
    _rgeo       _geo,      reversed order                                                                                  
    _rcluster0  _cluster0, reversed order                                                                                  
    _rcluster1  _cluster1, reversed order                                                                                  
    _specified  user specified sigma on input                                                                              

                                                                                                                           

    * optional scaling & modifier suffix                                                                                   
    _ufl        scale near underflow         = 1e-308 for double                                                           
    _ofl        scale near overflow          = 2e+308 for double                                                           
    _small      scale near sqrt( underflow ) = 1e-154 for double                                                           
    _large      scale near sqrt( overflow  ) = 6e+153 for double                                                           
    _dominant   diagonally dominant: set |A_ii| = max( sum_j |A_ij|, sum_j |A_ji| )                                        
                Note _dominant changes the singular or eigenvalues.                                                        

                                                                          



How is it possible to generate a matrix with a specified Condition number?

as given above


Do we have any method to generate matrices with large elements or other distributions in MAGMA which generate a bad condition matrix?

yes, as described above. You can also scale near underflow and overflow, etc.


How are you importing the SuiteSparse Matrix Collectioninside of MAGMA?

We have these in the sparse part of magma. Syntax is
./testing_dsolver --solver CG  test_matrices/Trefethen_2000.mtx 
so you give the matrix in mtx format as last argument.


Cheers

--
You received this message because you are subscribed to the Google Groups "MAGMA User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to magma-user+...@icl.utk.edu.
To view this discussion on the web visit https://groups.google.com/a/icl.utk.edu/d/msgid/magma-user/CA%2Bzr%3DE11uaKQ74q0ZsBoQ2HCQr-wUYw_TugiAbM87uNbMcoMJg%40mail.gmail.com.

Xiniz Ronda

unread,
Jul 7, 2022, 12:59:50 PMJul 7
to Stanimire Tomov, magma...@icl.utk.edu
Thanks Stanimire,

It seems that I have some problems in matrix allocation also. Fro float matrix with large dimention like 47000 I have an error:
error -112: cannot allocate memory on CPU host

I changed the second parameter of magma_smalloc to a size_t data type.
Original code: 
magma_int_t M, N, lda, n2;
...
n2=lda*N;

magma_smalloc (&d_A, N*ldda)
magma_smalloc_cpu(&h_A, n2)

modified code:

size_t nh=N*M
size_t nd=N*ldda
 
magma_smalloc (&d_A, nh)
 
magma_smalloc_cpu(&h_A, nd)

Now the error is:

terminate called after throwing an instance of 'std::exception'
  what():  std::exception
Aborted (core dumped)

And if the size is small (400x400) I have this:
free(): invalid size

It is strange for me . How do you create large matrices?

Cheers

Stanimire Tomov

unread,
Jul 7, 2022, 1:52:14 PMJul 7
to Xiniz Ronda, magma...@icl.utk.edu
Hello,

47K^2 exceeds the range of 32-bit integer, so for large matrices like that you will have to use
64-bit integers. You can do that through the make.inc file, e.g., see an example like this:
make.inc-examples/make.inc.mkl-gcc-ilp64



On Jul 7, 2022, at 12:51 PM, Xiniz Ronda <ronda...@gmail.com> wrote:

Thanks Stanimire,

It seems that I have some problems in matrix allocation also. Fro float matrix with large dimention like 47000 I have an error:
error -112: cannot allocate memory on CPU host

I changed the second parameter of magma_smalloc to a size_t data type.
Original code: 
magma_int_t M, N, lda, n2;
...
n2=lda*N;

magma_smalloc (&d_A, N*ldda)
magma_smalloc_cpu(&h_A, n2)

modified code:

size_t nh=N*M
size_t nd=N*ldda
 
magma_smalloc (&d_A, nh)
 
magma_smalloc_cpu(&h_A, nd)

Now the error is:

terminate called after throwing an instance of 'std::exception'
  what():  std::exception
Aborted (core dumped)

Yes, these are the type of changes we will do through the make.inc file. 
If you do it by hand, you may have to change magma_smalloc function as well, as the function
expects 32-bit integer. This will allow you to allocate larger arrays but there are other places in
magma where the ints will have to be changed so is better to do it through the make.inc. 


And if the size is small (400x400) I have this:
free(): invalid size

It is strange for me . How do you create large matrices?

400x400 is small enough. That’s strange you get an error here.
Maybe conversion from std::size_t to int did something strange to the pointer and free gives error?

Stanimire Tomov

unread,
Jul 7, 2022, 3:22:20 PMJul 7
to Xiniz Ronda, magma...@icl.utk.edu

On Jul 7, 2022, at 2:16 PM, Xiniz Ronda <ronda...@gmail.com> wrote:

Thanks. So as I understand I have to add this two line to my current make.inc file, and after that make + make install again.

FFLAGS    += -fdefault-integer-8
F90FLAGS  += -fdefault-integer-8

Is it correct?

yes, that’s correct - for the fortran file - but there must be also addition/specification for the c++ and cuda files, e.g.,

# Defining MAGMA_ILP64 or MKL_ILP64 changes magma_int_t to int64_t in include/magma_types.h
CFLAGS    += -DMKL_ILP64
FFLAGS    += -fdefault-integer-8
F90FLAGS  += -fdefault-integer-8
NVCCFLAGS += -DMKL_ILP64

and if you link to MKL they have a separate version of MKL where the integers are 
64-bit (libmkl_gf_ilp64.so), so linking libraries have to be specified, e.g.,

# gcc/gfortran with MKL 10.3, GNU OpenMP threads, 64-bit int (use -fopenmp in CFLAGS, LDFLAGS)
# note -DMAGMA_ILP64 or -DMKL_ILP64, and -fdefault-integer-8 in FLAGS above
LIB       = -lmkl_gf_ilp64 -lmkl_gnu_thread -lmkl_core -lpthread -lstdc++ -lm -lgfortran

Xiniz Ronda

unread,
Jul 7, 2022, 4:44:16 PMJul 7
to Stanimire Tomov, magma...@icl.utk.edu
Thanks. So as I understand I have to add this two line to my current make.inc file, and after that make + make install again.

FFLAGS    += -fdefault-integer-8
F90FLAGS  += -fdefault-integer-8

Is it correct?

On Thu, Jul 7, 2022 at 7:52 PM Stanimire Tomov <to...@icl.utk.edu> wrote:

Xiniz Ronda

unread,
Jul 7, 2022, 4:44:28 PMJul 7
to Stanimire Tomov, magma...@icl.utk.edu
Thank you. I think I have to do make clean and after that start the make, but actualy I have modified bellow files for some new functions.

../Makefile.gen
../include/magma_d.h

So make clean will reset them to initial stage. Without make clean I am seeing this error:

undefined reference to symbol 'cublasSetAtomicsMode@@libcublas.so.11'
 error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Reply all
Reply to author
Forward
0 new messages