Import
Import()
can be used for importing sparse matrix data from a file.
Currently, SPARSE_FMT_COO
is supported.
The routine will open the file, read data, and then close the file.
SPARSE_FMT_COO
format is actually MatrixMarket
format, which is described here in detail.
The brief description of this file format is given below.
Matrix market format
This is the native exchange format for the Matrix Market.
The Matrix Market (MM) exchange formats provide a simple mechanism to facilitate the exchange of matrix data. In particular, the objective has been to define a minimal base ASCII file format which can be very easily explained and parsed, but can easily adapted to applications with a more rigid structure, or extended to related data objects. The MM exchange format for matrices is really a collection of affiliated formats which share design elements. In our initial specification, two matrix formats are defined.
A file format suitable for representing general sparse matrices. Only nonzero entries are provided, and the coordinates of each nonzero entry is given explicitly. This is illustrated in the example below.
%
Consider the following 5x5
matrix:
1 0 0 6 0
0 10.5 0 0 0
0 0 .015 0 0
0 250.5 0 -280 33.32
0 0 0 0 12
In MM coordinate format this could be represented as follows.
%%MatrixMarket matrix coordinate real general
%=================================================================================
%
% This ASCII file represents a sparse MxN matrix with L
% nonzeros in the following Matrix Market format:
%
% Indices are 1-based, i.e. A(1,1) is the first element.
%
%=================================================================================
5 5 8
1 1 1.000e+00
2 2 1.050e+01
3 3 1.500e-02
1 4 6.000e+00
4 2 2.505e+02
4 4 -2.800e+02
4 5 3.332e+01
5 5 1.200e+01
Header
%%MatrixMarket ${1} ${2} ${3} ${4} ${5}
-
${1}=%%MatrixMarket
-
${2}=matrix
-
${3}=coorindate|array
-
${4}=real|integer|complex|pattern|
-
${5}=general|symmetric|skew-symmetric|Hermitian
-
The first line contains the type code. In this example, it indicates that the object being represented is a
matrix
incoordinate
format and that the numeric data following isreal
and represented ingeneral
form. (By general we mean that the matrix format is not taking advantage of any symmetry properties.) -
Variants of the coordinate format are defined for matrices with complex and integer entries, as well as for those in which only the position of the nonzero entries is prescribed (pattern matrices). (These would be indicated by changing real to complex, integer, or pattern, respectively, on the header line).
-
Additional variants are defined for cases in which symmetries can be used to significantly reduce the size of the data: symmetric, skew-symmetric and Hermitian. In these cases, only entries in the lower triangular portion need be supplied. In the skew-symmetric case the diagonal entries are zero, and hence they too are omitted. (These would be indicated by changing general to symmetric, skew-symmetric, or hermitian, respectively, on the header line).
Interface
- ܀ See Interface
- ܀ Example
- ↢
INTERFACE
MODULE SUBROUTINE Import(obj, fileName, matFormat)
TYPE(CSRMatrix_), INTENT(INOUT) :: obj
CHARACTER(LEN=*), INTENT(IN) :: fileName
INTEGER(I4B), INTENT(IN) :: matFormat
END SUBROUTINE Import
END INTERFACE
PROGRAM FIDAPM33
USE easifemBase
TYPE(csrmatrix_) :: obj, obj2, pmat, pmat2
TYPE(sparseMatrixReOrdering_) :: reorder
Import matrix
CALL IMPORT(obj, "./matrixMarket/fidapm33.mtx", SPARSE_FMT_COO)
Let's see its content
CALL SPY(obj=obj, filename="FIDAPM33_BEFORE", ext="png")
CALL getILUD(obj=obj, Pmat=pmat, alpha=1.0_DFP, droptol=0.001_DFP)
CALL spy(obj=pmat, filename="FIDAPM33_ILUD_BEFORE", ext="png")
NestedDissect from Metis.
! CALL NestedDissect(reorder=reorder, csrMat=obj)
! obj2 = Permute(obj, reorder, reorder)
! CALL SPY(obj2, "FIDAPM33_AFTER")
!
! CALL getILUD(obj=obj2, Pmat=pmat2, alpha=1.0_DFP, droptol=0.001_DFP)
! CALL spy(pmat2, "FIDAPM33_ILUD_AFTER")
CALL DEALLOCATE (obj)
CALL DEALLOCATE (obj2)
CALL DEALLOCATE (pmat)
CALL DEALLOCATE (pmat2)
END PROGRAM FIDAPM33