-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdatastruct.tex
1427 lines (1231 loc) · 44.2 KB
/
datastruct.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\section{Data Structures and Classes}
\label{sec:datastruct}
%\ifthenelse{\boolean{mtc}}{\minitoc}{}
In this chapter we illustrate the data structures used for definition of
routines interfaces. They include data structures for sparse matrices,
communication descriptors and preconditioners.%% These data structures
%% are used for calling PSBLAS routines in Fortran~90 language and will
%% be used to next chapters containing these callings.
All the data types and the basic subroutine interfaces related to
descriptors and sparse matrices are defined in
the module \fortinline|psb_base_mod|; this will have to be included by every
user subroutine that makes use of the library. The preconditioners are
defined in the module \fortinline|psb_prec_mod|
Integer, real and complex data types are parametrized with a kind type
defined in the library as follows:
\begin{description}
\item[psb\_spk\_] Kind parameter for short precision real and complex
data; corresponds to a \fortinline|REAL| declaration and is
normally 4 bytes;
\item[psb\_dpk\_] Kind parameter for long precision real and complex
data; corresponds to a \fortinline|DOUBLE PRECISION| declaration and is
normally 8 bytes;
\item[psb\_mpk\_] Kind parameter for 4-bytes integer data, as is
always used by MPI;
\item[psb\_epk\_] Kind parameter for 8-bytes integer data, as is
always used by the \fortinline|sizeof| methods;
\item[psb\_ipk\_] Kind parameter for ``local'' integer indices and data;
with default build options this is a 4 bytes integer;
\item[psb\_lpk\_] Kind parameter for ``global'' integer indices and data;
with default build options this is an 8 bytes integer;
\end{description}
The integer kinds for local and global indices can be chosen at
configure time to hold 4 or 8 bytes, with the global indices at least
as large as the local ones.
Together with the classes attributes we also discuss their
methods. Most methods detailed here only act on the local variable,
i.e. their action is purely local and asynchronous unless otherwise
stated.
The list of methods here is not completely exhaustive; many methods,
especially those that alter the contents of the various objects, are
usually not needed by the end-user, and therefore are described in the
developer's documentation.
\subsection{Descriptor data structure}
\label{sec:desc}
All the general matrix informations and elements to be
exchanged among processes are stored within a data structure of the
type \hypertarget{descdata}{{\tt psb\_desc\_type}}.
Every structure of this type is associated with a discretization
pattern and enables data communications and other operations that are
necessary for implementing the various algorithms of interest to us.
The data structure itself \fortinline|psb_desc_type| can be treated as an
opaque object handled via the tools routines of
Sec.~\ref{sec:toolsrout} or the query routines detailed below;
nevertheless we include here a description for the curious
reader.
First we describe the \fortinline|psb_indx_map| type. This is a data
structure that keeps track of a certain number of basic issues such
as:
\begin{itemize}
\item The value of the communication context;
\item The number of indices in the index space, i.e. global number of
rows and columns of a sparse matrix;
\item The local set of indices, including:
\begin{itemize}
\item The number of local indices (and local rows);
\item The number of halo indices (and therefore local columns);
\item The global indices corresponding to the local ones.
\end{itemize}
\end{itemize}
There are many different schemes for storing these data; therefore
there are a number of types extending the base one, and the descriptor
structure holds a polymorphic object whose dynamic type can be any of
the extended types.
The methods associated with this data type answer the following
queries:
\begin{itemize}
\item For a given set of local indices, find the corresponding indices
in the global numbering;
\item For a given set of global indices, find the corresponding
indices in the local numbering, if any, or return an invalid
\item Add a global index to the set of halo indices;
\item Find the process owner of each member of a set of global
indices.
\end{itemize}
All methods but the last are purely local; the last method potentially
requires communication among processes, and thus is a synchronous
method. The choice of a specific dynamic type for the index map is
made at the time the descriptor is initially allocated, according to
the mode of initialization (see also~\ref{sec:toolsrout}).
The descriptor contents are as follows:
\begin{description}
\item[{\bf indxmap}] A polymorphic variable of a type that is any
extension of the indx\_map type described above. \\
\item[{\bf halo\_index}] A list of the halo and boundary elements for
the current process to be exchanged with other processes; for each
processes with which it is necessary to communicate:
\begin{enumerate}
\item Process identifier;
\item Number of points to be received;
\item Indices of points to be received;
\item Number of points to be sent;
\item Indices of points to be sent;
\end{enumerate}
% The list may contain an arbitrary number of groups; its end is marked
% by a -1.\\
Specified as: a vector of integer type, see~\ref{sec:vecttype}.
\item[{\bf ext\_index}] A list of element indices to be exchanged to
implement the mapping between a base descriptor and a descriptor
with overlap. \\
Specified as: a vector of integer type, see~\ref{sec:vecttype}.
\item [{\bf ovrlap\_index}] A list of the overlap elements for the
current process, organized in groups like the previous vector:
\begin{enumerate}
\item Process identifier;
\item Number of points to be received;
\item Indices of points to be received;
\item Number of points to be sent;
\item Indices of points to be sent;
\end{enumerate}
% The list may contain an arbitrary number of groups; its end is marked
% by a -1.\\
Specified as: a vector of integer type, see~\ref{sec:vecttype}.
\item [{\bf ovr\_mst\_idx}] A list to retrieve the value of each
overlap element from the respective master process.\\
Specified as: a vector of integer type, see~\ref{sec:vecttype}.
\item [{\bf ovrlap\_elem}] For all overlap points belonging to th
ecurrent process:
\begin{enumerate}
\item Overlap point index;
\item Number of processes sharing that overlap points;
\item Index of a ``master'' process:
\end{enumerate}
Specified as: an allocatable integer array of rank two.
\item [{\bf bnd\_elem}] A list of all boundary points, i.e. points
that have a connection with other processes.
\end{description}
The Fortran~2003 declaration for \fortinline|psb_desc_type| structures is
as follows:
\begin{listing}[h!]
% \begin{Sbox}
\ifpdf
\begin{minted}[breaklines=true,bgcolor=bg,fontsize=\small]{fortran}
type psb_desc_type
class(psb_indx_map), allocatable :: indxmap
type(psb_i_vect_type) :: v_halo_index
type(psb_i_vect_type) :: v_ext_index
type(psb_i_vect_type) :: v_ovrlap_index
type(psb_i_vect_type) :: v_ovr_mst_idx
integer, allocatable :: ovrlap_elem(:,:)
integer, allocatable :: bnd_elem(:)
end type psb_desc_type
\end{minted}
\else
\begin{center}
\begin{minipage}[tl]{0.9\textwidth}
\begin{verbatim}
type psb_desc_type
class(psb_indx_map), allocatable :: indxmap
type(psb_i_vect_type) :: v_halo_index
type(psb_i_vect_type) :: v_ext_index
type(psb_i_vect_type) :: v_ovrlap_index
type(psb_i_vect_type) :: v_ovr_mst_idx
integer, allocatable :: ovrlap_elem(:,:)
integer, allocatable :: bnd_elem(:)
end type psb_desc_type
\end{verbatim}
\end{minipage}
\end{center}
\fi
% \end{Sbox}
% \setlength{\fboxsep}{8pt}
% \begin{center}
% \fbox{\TheSbox}
% \end{center}
\caption{\label{fig:desctype}The PSBLAS defined data type that
contains the communication descriptor.}
\end{listing}
A communication descriptor associated with a sparse matrix has a
state, which can take the following values:
\begin{description}
\item[Build:] State entered after the first allocation, and before the
first assembly; in this state it is possible to add communication
requirements among different processes.
\item[Assembled:] State entered after the assembly; computations using
the associated sparse matrix, such as matrix-vector products, are
only possible in this state.
\end{description}
\subsubsection{Descriptor Methods}
\subsubsection{get\_local\_rows --- Get number of local rows}
\begin{verbatim}
nr = desc%get_local_rows()
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[desc] the communication descriptor.\\
Scope: {\bf local}.\\
% Type: {\bf required}.\\
% Intent: {\bf in}.\\
% Specified as: a object of type \descdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] The number of local rows, i.e. the number of
rows owned by the current process; as explained in~\ref{sec:intro},
it is equal to $|{\cal I}_i| + |{\cal B}_i|$. The returned value is
specific to the calling process.
\end{description}
\subsubsection{get\_local\_cols --- Get number of local cols}
\begin{verbatim}
nc = desc%get_local_cols()
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[desc] the communication descriptor.\\
Scope: {\bf local}.\\
% Type: {\bf required}.\\
% Intent: {\bf in}.\\
% Specified as: a object of type \descdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] The number of local cols, i.e. the number of
indices used by the current process, including both local and halo
indices; as explained in~\ref{sec:intro},
it is equal to $|{\cal I}_i| + |{\cal B}_i| +|{\cal H}_i|$. The
returned value is specific to the calling process.
\end{description}
\subsubsection{get\_global\_rows --- Get number of global rows}
\begin{verbatim}
nr = desc%get_global_rows()
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[desc] the communication descriptor.\\
Scope: {\bf local}.\\
% Type: {\bf required}.\\
% Intent: {\bf in}.\\
% Specified as: a object of type \descdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] The number of global rows, i.e. the size of the
global index space.
\end{description}
\subsubsection{get\_global\_cols --- Get number of global cols}
\begin{verbatim}
nr = desc%get_global_cols()
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[desc] the communication descriptor.\\
Scope: {\bf local}.\\
% Type: {\bf required}.\\
% Intent: {\bf in}.\\
% Specified as: a object of type \descdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] The number of global cols; usually this is equal
to the number of global rows.
\end{description}
\subsubsection{get\_global\_indices --- Get vector of global indices}
\begin{verbatim}
myidx = desc%get_global_indices([owned])
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[desc] the communication descriptor.\\
Scope: {\bf local}.\\
Type: {\bf required}.\\
\item[owned] Choose if you only want owned indices
(\fortinline|owned=.true.|) or also halo indices (\fortinline|owned=.false.|).
Scope: {\bf local}.\\
Type: {\bf optional}; default: \fortinline|.true.|.\\
% Intent: {\bf in}.\\
% Specified as: a object of type \descdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] The global indices, returned as an allocatable
integer array of kind \fortinline|psb_lpk_| and rank 1.
\end{description}
\subsubsection{get\_context --- Get communication context}
\begin{verbatim}
ctxt = desc%get_context()
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[desc] the communication descriptor.\\
Scope: {\bf local}.\\
% Type: {\bf required}.\\
% Intent: {\bf in}.\\
% Specified as: a object of type \descdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] The communication context.
\end{description}
\subsubsection{Clone --- clone current object}
\begin{verbatim}
call desc%clone(descout,info)
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[desc] the communication descriptor.\\
Scope: {\bf local}.\\
% Type: {\bf required}.\\
% Intent: {\bf in}.\\
% Specified as: a object of type \descdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[descout] A copy of the input object.
\item[info] Return code.
\end{description}
\subsubsection{CNV --- convert internal storage format}
\begin{verbatim}
call desc%cnv(mold)
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[desc] the communication descriptor.\\
Scope: {\bf local}.\\
\item[mold] the desired integer storage format.\\
Scope: {\bf local}.\\
% Type: {\bf required}.\\
% Intent: {\bf in}.\\
Specified as: a object of type derived from (integer) \vbasedata.
\end{description}
The \fortinline|mold| arguments may be
employed to interface with special devices, such as GPUs and other
accelerators.
\subsubsection{psb\_cd\_get\_hash\_threshold --- Get threshold for
index mapping switch}
\begin{verbatim}
ith = psb_cd_get_hash_threshold()
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Return]
\item[Function value] The current value for the size threshold.
\end{description}
\subsubsection{psb\_cd\_set\_hash\_threshold --- Set threshold for
index mapping switch}
%\addcontentsline{toc}{paragraph}{psb\_cd\_set\_large\_threshold}
\begin{verbatim}
call psb_cd_set_hash_threshold(ith)
\end{verbatim}
\begin{description}
\item[Type:] Synchronous.
\item[\bf On Entry]
\item[ith] the new threshold for communication descriptors.\\
Scope: {\bf global}.\\
Type: {\bf required}.\\
Intent: {\bf in}.\\
Specified as: an integer value greater than zero.
\end{description}
This threshold guides the library into using a list based or a
hash-table based descriptor for global to local index conversion;
if the size of the global index space is below this threshold, a list
based structure is used, if it is above a hash-table based structure
is used.
Note: the threshold value is only queried by the library at the time a
call to \fortinline|psb_cdall| is executed, therefore changing the threshold
has no effect on communication descriptors that have already been
initialized. Moreover the threshold must have the same value on all
processes.
\subsubsection{get\_p\_adjcncy --- Get process adjacency list}
%\addcontentsline{toc}{paragraph}{get\_p\_adjcncy}
\begin{verbatim}
list = desc%get_p_adjcncy()
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Return]
\item[Function value] The current list of adjacent processes,
i.e. processes with which the current one has to exchange halo
data.
\end{description}
\subsubsection{set\_p\_adjcncy --- Set process adjacency list}
%\addcontentsline{toc}{paragraph}{set\_p\_adjcncy}
\begin{verbatim}
call desc%set_p_adjcncy(list)
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[list] the list of adjacent processes.\\
Scope: {\bf local}.\\
Type: {\bf required}.\\
Intent: {\bf in}.\\
Specified as: a one-dimensional array of integers of kind \fortinline|psb_ipk_|.
\end{description}
Note: this method can be called after a call to \fortinline|psb_cdall| and
before a call to \fortinline|psb_cdasb|. The user is specifying here some
knowledge about which processes are topological neighbours of the
current process. The availability of this information may speed up the
execution of the assembly call \fortinline|psb_cdasb|.
\subsubsection{fnd\_owner --- Find the owner process of a set of indices}
%\addcontentsline{toc}{paragraph}{fnd\_owner}
\begin{verbatim}
call desc%fnd_owner(idx,iprc,info)
\end{verbatim}
\begin{description}
\item[Type:] Synchronous.
\item[\bf On Entry]
\item[idx] the list of global indices for which we need the owning processes.\\
Scope: {\bf local}.\\
Type: {\bf required}.\\
Intent: {\bf in}.\\
Specified as: a one-dimensional array of integers of kind \fortinline|psb_lpk_|.
\item[\bf On Return]
\item[iprc] the list of processes owning the indices in \fortinline|idx|.\\
Scope: {\bf local}.\\
Type: {\bf required}.\\
Intent: {\bf in}.\\
Specified as: an allocatable one-dimensional array of integers of kind \fortinline|psb_ipk_|.
\end{description}
Note: this method may or may not actually require communications, depending on
the exact internal data storage; given that the choice of storage may
be altered by runtime parameters, it is necessary for safety that this
method is called by all processes.
\subsubsection{Named Constants}
\label{sec:cd_constants}
\begin{description}
\item[psb\_none\_] Generic no-op;
\item[psb\_root\_] Default root process for broadcast and scatter operations;
\item[psb\_nohalo\_] Do not fetch halo elements;
\item[psb\_halo\_] Fetch halo elements from neighbouring processes;
\item[psb\_sum\_] Sum overlapped elements
\item[psb\_avg\_] Average overlapped elements
\item[psb\_comm\_halo\_] Exchange data based on the \fortinline|halo_index|
list;
\item[psb\_comm\_ext\_] Exchange data based on the \fortinline|ext_index|
list;
\item[psb\_comm\_ovr\_] Exchange data based on the \fortinline|ovrlap_index|
list;
\item[psb\_comm\_mov\_] Exchange data based on the \fortinline|ovr_mst_idx|
list;
%% \item[psb\_square\_root\_] Update with the square root of the average
%% of overlapped elements;
%% \item[psb\_dec\_type\_] Entry holding decomposition type (in \fortinline|desc_a%matrix_data|)
%% \item[psb\_m\_] Entry holding total number of rows
%% \item[psb\_n\_] Entry holding total number of columns
%% \item[ psb\_n\_row\_] Entry holding the number of rows stored in the
%% current process
%% \item[psb\_n\_col\_] Entry holding the number of columns stored in the
%% current process
%% \item[psb\_ctxt\_] Entry holding a copy of the BLACS communication context
%% \item[psb\_desc\_asb\_] State of the descriptor: assembled,
%% i.e. suitable for computational tasks.
%% \item[psb\_desc\_bld\_] State of the descriptor: build, must be
%% assembled before computational use.
\end{description}
\subsection{Sparse Matrix class}
\label{sec:spmat}
The \hypertarget{spdata}{{\tt psb\_Tspmat\_type}} class
contains all information about the local portion of the sparse matrix and
its storage mode. Its design is
based on the STATE design pattern~\cite{DesignPatterns} as detailed
in~\cite{Sparse03}; the type declaration is shown in
figure~\ref{fig:spmattype} where \fortinline|T| is a placeholder for the
data type and precision variants
\begin{description}
\item[S] Single precision real;
\item[D] Double precision real;
\item[C] Single precision complex;
\item[Z] Double precision complex;
\item[LS,LD,LC,LZ] Same numeric type as above, but with
\fortinline|psb_lpk_| integer indices.
\end{description}
The actual data is contained in the polymorphic component \fortinline|a%a|
of type \hypertarget{spbasedata}{{\tt psb\_T\_base\_sparse\_mat}}; its
specific layout can be chosen dynamically among the predefined types,
or an entirely new storage layout can be implemented and passed to the
library at runtime via the \fortinline|psb_spasb| routine.
\begin{listing}[h!]
\ifpdf
\begin{minted}[breaklines=true,bgcolor=bg,fontsize=\small]{fortran}
type :: psb_Tspmat_type
class(psb_T_base_sparse_mat), allocatable :: a
end type psb_Tspmat_type
\end{minted}
\else
% \begin{Sbox}
\begin{center}
\begin{minipage}[tl]{0.85\textwidth}
\begin{verbatim}
type :: psb_Tspmat_type
class(psb_T_base_sparse_mat), allocatable :: a
end type psb_Tspmat_type
\end{verbatim}
\end{minipage}
\end{center}
% \end{Sbox}
% \setlength{\fboxsep}{8pt}
% \begin{center}
% \fbox{\TheSbox}
% \end{center}
\fi
\caption{\label{fig:spmattype}
The PSBLAS defined data type that
contains a sparse matrix.}
\end{listing}
The following very common formats are precompiled in PSBLAS and thus
are always available:
\begin{description}
\item[psb\_T\_coo\_sparse\_mat] Coordinate storage;
\item[psb\_T\_csr\_sparse\_mat] Compressed storage by rows;
\item[psb\_T\_csc\_sparse\_mat] Compressed storage by columns;
\end{description}
The inner sparse matrix has an associated state, which can take the
following values:
\begin{description}
\item[Build:] State entered after the first allocation, and before the
first assembly; in this state it is possible to add nonzero entries.
\item[Assembled:] State entered after the assembly; computations using
the sparse matrix, such as matrix-vector products, are only possible
in this state;
\item[Update:] State entered after a reinitalization; this is used to
handle applications in which the same sparsity pattern is used
multiple times with different coefficients. In this state it is only
possible to enter coefficients for already existing nonzero entries.
\end{description}
The only storage variant supporting the build state is COO; all other
variants are obtained by conversion to/from it.
\subsubsection{Sparse Matrix Methods}
\subsubsection{get\_nrows --- Get number of rows in a sparse matrix}
%\addcontentsline{toc}{paragraph}{get\_nrows}
\begin{verbatim}
nr = a%get_nrows()
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix\\
Scope: {\bf local}\\
% Type: {\bf required}\\
% Intent: {\bf in}.\\
% Specified as: a object of type \spdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] The number of rows of sparse matrix \fortinline|a|.
\end{description}
\subsubsection{get\_ncols --- Get number of columns in a sparse
matrix}
%\addcontentsline{toc}{paragraph}{get\_ncols}
\begin{verbatim}
nc = a%get_ncols()
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix\\
Scope: {\bf local}\\
% Type: {\bf required}\\
% Intent: {\bf in}.\\
% Specified as: a object of type \spdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] The number of columns of sparse matrix \fortinline|a|.
\end{description}
\subsubsection{get\_nnzeros --- Get number of nonzero elements
in a sparse matrix}
%\addcontentsline{toc}{paragraph}{get\_nnzeros}
\begin{verbatim}
nz = a%get_nnzeros()
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix\\
Scope: {\bf local}\\
% Type: {\bf required}\\
% Intent: {\bf in}.\\
% Specified as: a object of type \spdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] The number of nonzero elements stored in sparse matrix \fortinline|a|.
\end{description}
{\par\noindent\bfseries Notes}
\begin{enumerate}
\item The function value is specific to the storage format of matrix
\fortinline|a|; some storage formats employ padding, thus the returned
value for the same matrix may be different for different storage choices.
\end{enumerate}
\subsubsection{get\_size --- Get maximum number of nonzero elements
in a sparse matrix}
%\addcontentsline{toc}{paragraph}{get\_size }
\begin{verbatim}
maxnz = a%get_size()
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix\\
Scope: {\bf local}\\
% Type: {\bf required}\\
% Intent: {\bf in}.\\
% Specified as: a object of type \spdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] The maximum number of nonzero elements that can
be stored in sparse matrix \fortinline|a| using its current memory allocation.
\end{description}
\subsubsection{sizeof --- Get memory occupation in bytes
of a sparse matrix}
%\addcontentsline{toc}{paragraph}{sizeof }
\begin{verbatim}
memory_size = a%sizeof()
\end{verbatim}
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix\\
Scope: {\bf local}\\
% Type: {\bf required}\\
% Intent: {\bf in}.\\
% Specified as: a object of type \spdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] The memory occupation in bytes.
\end{description}
\subsubsection{get\_fmt --- Short description of the dynamic type}
%\addcontentsline{toc}{paragraph}{get\_fmt }
\fortinline|write(*,*) a%get_fmt()|
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix\\
Scope: {\bf local}\\
% Type: {\bf required}\\
% Intent: {\bf in}.\\
% Specified as: a object of type \spdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] A short string describing the dynamic type of
the matrix. Predefined values include \fortinline|NULL|, \fortinline|COO|,
\fortinline|CSR| and \fortinline|CSC|.
\end{description}
\subsubsection{is\_bld, is\_upd, is\_asb --- Status check}
%\addcontentsline{toc}{paragraph}{is\_bld, is\_upd, is\_asb }
\fortinline|if (a%is_bld()) then|\\
\fortinline|if (a%is_upd()) then|\\
\fortinline|if (a%is_asb()) then|
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix\\
Scope: {\bf local}\\
% Type: {\bf required}\\
% Intent: {\bf in}.\\
% Specified as: a object of type \spdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] A \fortinline|logical| value indicating whether the
matrix is in the Build, Update or Assembled state, respectively.
\end{description}
\subsubsection{is\_lower, is\_upper, is\_triangle, is\_unit ---
Format check}
%\addcontentsline{toc}{paragraph}{is\_lower, is\_upper, is\_triangle, is\_unit}
\ifpdf
\begin{minted}{fortran}
if (a%is_triangle()) then
if (a%is_upper()) then
if (a%is_lower()) then
if (a%is_unit()) then
\end{minted}
\else
\begin{verbatim}
if (a%is_triangle()) then
if (a%is_upper()) then
if (a%is_lower()) then
if (a%is_unit()) then
\end{verbatim}
\fi
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix\\
Scope: {\bf local}\\
% Type: {\bf required}\\
% Intent: {\bf in}.\\
% Specified as: a object of type \spdata.
\end{description}
\begin{description}
\item[\bf On Return]
\item[Function value] A \fortinline|logical| value indicating whether the
matrix is triangular; if \fortinline|is_triangle()| returns \fortinline|.true.|
check also if it is lower, upper and with a unit (i.e. assumed)
diagonal.
\end{description}
\subsubsection{cscnv --- Convert to a different storage format}
%\addcontentsline{toc}{paragraph}{cscnv}
\ifpdf
\begin{minted}{fortran}
call a%cscnv(b,info [, type, mold, dupl])
call a%cscnv(info [, type, mold, dupl])
\end{minted}
\else
\begin{verbatim}
call a%cscnv(b,info [, type, mold, dupl])
call a%cscnv(info [, type, mold, dupl])
\end{verbatim}
\fi
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix.\\
A variable of type \fortinline|psb_Tspmat_type|.\\
Scope: {\bf local}.\\
\item[type] a string requesting a new format.\\
Type: optional.
\item[mold] a variable of \fortinline|class(psb_T_base_sparse_mat)| requesting a new format.\\
Type: optional.
\item[dupl] an integer value specifing how to handle duplicates (see
Named Constants below)
\end{description}
\begin{description}
\item[\bf On Return]
\item[b,a] A copy of \fortinline|a| with a new storage format.\\
A variable of type \fortinline|psb_Tspmat_type|.
\item[info] Return code.
\end{description}
The \fortinline|mold| arguments may be
employed to interface with special devices, such as GPUs and other
accelerators.
\subsubsection{csclip --- Reduce to a submatrix}
%\addcontentsline{toc}{paragraph}{csclip}
\ifpdf
\begin{minted}{fortran}
call a%csclip(b,info[,&
& imin,imax,jmin,jmax,rscale,cscale])
\end{minted}
\else
\begin{verbatim}
call a%csclip(b,info[,&
& imin,imax,jmin,jmax,rscale,cscale])
\end{verbatim}
\fi
Returns the submatrix \fortinline|A(imin:imax,jmin:jmax)|, optionally
rescaling row/col indices to the range
\fortinline|1:imax-imin+1,1:jmax-jmin+1|.
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix.\\
A variable of type \fortinline|psb_Tspmat_type|.\\
Scope: {\bf local}.\\
\item[imin,imax,jmin,jmax] Minimum and maximum row and column indices.\\
Type: optional.
\item[rscale,cscale] Whether to rescale row/column indices.
Type: optional.
\end{description}
\begin{description}
\item[\bf On Return]
\item[b] A copy of a submatrix of \fortinline|a|.\\
A variable of type \fortinline|psb_Tspmat_type|.
\item[info] Return code.
\end{description}
\subsubsection{clean\_zeros --- Eliminate zero coefficients}
%\addcontentsline{toc}{paragraph}{clean\_zeros}
\fortinline|call a%clean_zeros(info)|
Eliminates zero coefficients explicitly stored in the input matrix.
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix.\\
A variable of type \fortinline|psb_Tspmat_type|.\\
Scope: {\bf local}.\\
\end{description}
\begin{description}
\item[\bf On Return]
\item[a] The matrix \fortinline|a| without zero coefficients.\\
A variable of type \fortinline|psb_Tspmat_type|.
\item[info] Return code.
\end{description}
{\par\noindent\bfseries Notes}
\begin{enumerate}
\item Depending on the internal storage format, there may still be some amount of
zero padding in the output.
\item Any explicit zeros on the main diagonal are always kept in the
data structure.
\end{enumerate}
\subsubsection{get\_diag --- Get main diagonal}
%\addcontentsline{toc}{paragraph}{get\_diag}
\fortinline|call a%get_diag(d,info)|
Returns a copy of the main diagonal.
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix.\\
A variable of type \fortinline|psb_Tspmat_type|.\\
Scope: {\bf local}.\\
\end{description}
\begin{description}
\item[\bf On Return]
\item[d] A copy of the main diagonal.\\
A one-dimensional array of the appropriate type.
\item[info] Return code.
\end{description}
\subsubsection{clip\_diag --- Cut out main diagonal}
%\addcontentsline{toc}{paragraph}{clip\_diag}
\fortinline|call a%clip_diag(b,info)|
Returns a copy of \fortinline|a| without the main diagonal.
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix.\\
A variable of type \fortinline|psb_Tspmat_type|.\\
Scope: {\bf local}.\\
\end{description}
\begin{description}
\item[\bf On Return]
\item[b] A copy of \fortinline|a| without the main diagonal.\\
A variable of type \fortinline|psb_Tspmat_type|.
\item[info] Return code.
\end{description}
\subsubsection{tril --- Return the lower triangle}
%\addcontentsline{toc}{paragraph}{tril}
\ifpdf
\begin{minted}{fortran}
call a%tril(l,info[,&
& diag,imin,imax,jmin,jmax,rscale,cscale,u])
\end{minted}
\else
\begin{verbatim}
call a%tril(l,info[,&
& diag,imin,imax,jmin,jmax,rscale,cscale,u])
\end{verbatim}
\fi
Returns the lower triangular part of submatrix
\fortinline|A(imin:imax,jmin:jmax)|, optionally rescaling row/col indices to
the range \fortinline|1:imax-imin+1,1:jmax-jmin+1| and returing the
complementary upper triangle.
\begin{description}
\item[Type:] Asynchronous.
\item[\bf On Entry]
\item[a] the sparse matrix.\\
A variable of type \fortinline|psb_Tspmat_type|.\\
Scope: {\bf local}.\\
\item[diag] Include diagonals up to this one; \fortinline|diag=1| means the
first superdiagonal, \fortinline|diag=-1| means the first subdiagonal.
Default 0.
\item[imin,imax,jmin,jmax] Minimum and maximum row and column indices.\\
Type: optional.
\item[rscale,cscale] Whether to rescale row/column indices.
Type: optional.