-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsolver.h
More file actions
1920 lines (1811 loc) · 74.7 KB
/
solver.h
File metadata and controls
1920 lines (1811 loc) · 74.7 KB
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
/*
* Copyright 2023 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
*
* \ingroup TRANS
*
* Defines the solver transition path API.
*
* @see blas_sparse.h for the SparseBLAS transition path API
* @see spblas_impl.h for the SpBLAS transition path API
*
* @author A. N. Yzelman
* @date 5th of October, 2023
*/
/**
* \defgroup TRANS_SOLVERS Solvers
* \ingroup TRANS
* @{
*
* This exposes a transition path API to the linear system solvers implemented
* in ALP. The primary benefit compared to simply using a SpBLAS or SparseBLAS
* interface, is that solvers herein defined can be compiled using the
* nonblocking backend, thus automatically optimising across (Sparse)BLAS
* primitives. This is an experimental feature designed to evaluate exactly
* this advantage.
*
* The C-style interface here defined expects the industry-standard Compressed
* Row Storage (CRS) for matrices, also known as CSR. It employs a systematic
* postfix to the functions it defines. For example, the basic functions of the
* Conjugate Gradient solver are:
* - <tt>sparse_cg_init_xyy</tt>,
* - <tt>sparse_cg_solve_xyy</tt>, and
* - <tt>sparse_cg_destroy_xyy</tt>.
*
* \parblock
* \par The postfix system and the sparse matrix storage format
*
* First explaining the postfix system, each of the above <tt>x</tt> characters
* may be <tt>d</tt> or <tt>s</tt>, indicating the precision used during the
* solve: double- or single-precision, respectively.
*
* Each of the <tt>y</tt> characters may be <tt>z</tt> or <tt>i</tt>, indicating
* the integer type used during the solve: a <tt>size_t</tt> or a regular
* <tt>int</tt>, respectively.
*
* The first <tt>y</tt> character indicates the integer type of the CRS column
* index array, which maintains for each nonzero entry on which column it
* resides. For really large dimension matrices, a <tt>size_t</tt> integer
* type, which usually defaults to 64-bit unsigned integers, may be required.
*
* The second <tt>y</tt> character indicates the integer type of the row offset
* array of the CRS. The \f$ i \f$-th contiguous pair \f$ (a, b] \f$ of this
* array indicates where in the value and column arrays the \f$ i \f$-th row of
* the matrix is encoded-- the start position \f$ a \f$ is inclusive whereas the
* end position \f$ b \f$ is exclusive. The row offset array is of size
* \f$ m + 1 \f$, where \f$ m \f$ is the number of rows in the matrix. Hence the
* last entry of the offset array is the total number of nonzeroes the matrix
* contains. The data type of the offset array must be <tt>size_t</tt> when
* matrices contain many nonzeroes.
*
* \note Usually, if the offset array must be of type <tt>size_t</tt>, then the
* column index array must also be of type <tt>size_t</tt>. Certainly for
* matrices used with (linear) solvers, after all, the number of
* nonzeroes is a multiple of the number of matrix rows.
* \endparblock
*
* \parblock
* \par Implemented solvers
*
* Currently, the following ALP solvers are exposed:
* -# the sparse Conjugate Gradient (CG) solver, implemented at
* #grb::algorithms::conjugate_gradient.
* -# its preconditioned variant (PCG), implemented at
* #grb::algorithms::preconditioned_conjugate_gradient. The preconditioner
* may be supplied as an arbitrary user-defined function; while this is
* maximally flexible, it also requires the user to employ parallelisation
* and other optimisations for the preconditioner, manually.
*
* If you require any other solver, please feel free to submit a feature request
* or to contact the maintainer(s).
* \endparblock
*
* \warning The solvers here defined, and the transition path functionalities as
* a whole, are currently in a prototype stage. While the underlying
* ALP algorithms are automatically smoke tested and robust, the
* transition path libraries are presently tested externally and often
* manually.
*/
#ifndef _H_ALP_SPARSE_LINSOLVERS
#define _H_ALP_SPARSE_LINSOLVERS
#include <stddef.h> // for size_t
#ifdef __cplusplus
extern "C" {
#endif
/**
* The various error codes sparse solver library functions may return.
*/
typedef enum {
/** The call has completed successfully. */
NO_ERROR,
/**
* Illegal NULL pointer provided as argument.
*/
NULL_ARGUMENT,
/**
* Illegal argument provided.
*/
ILLEGAL_ARGUMENT,
/**
* Out of memory error detected during call.
*/
OUT_OF_MEMORY,
/**
* The algorithm has failed achieving its intended result. For example, an
* iterative solver did not converge.
*/
FAILED,
/**
* An unknown error has been encountered. The state of the underlying solver
* library has become undefined. When encoutering this error code, the caller
* is encouraged to exit gracefully or (at least) to make no further calls into
* this library.
*/
UNKNOWN
} sparse_err_t;
/**
* A solver handle for the Conjugate Gradient algorithm.
*/
typedef void * sparse_cg_handle_t;
/**
* A user-defined preconditioner function type for CG solver that employ
* single-precision floating-point nonzero values.
*
* I.e. and more precisely, a preconditioner function type for CG solver handles
* of types <tt>sii</tt>, <tt>siz</tt>, and <tt>szz</tt>.
*
* A preconditioner is assumed to be a plain C function pointer, where
* -# the function returns an <tt>int</tt> error code (where zero will be
* interpreted as success);
* -# the first argument is where the result of applying the preconditioner
* will be stored. It is a raw vector pointer, i.e., <tt>float *</tt>;
* -# the second argument contains the data on which the preconditioner
* action should be computed. It is a raw const vector pointer, i.e.,
* <tt>const float*</tt>;
* -# the third argument contains a pointer to any preconditioner data it
* may require. It is a raw void pointer, meaning, although usually not
* necessary nor recommended, the preconditioner data may be stateful.
*
* The function signature must match exactly this specification.
*/
typedef int (*sparse_cg_preconditioner_sxx_t) (
float * const,
const float * const,
void * const
);
/**
* A user-defined preconditioner function type for CG solver that employ
* double-precision floating-point nonzero values.
*
* I.e. and more precisely, a preconditioner function type for CG solver handles
* of types <tt>dii</tt>, <tt>diz</tt>, and <tt>dzz</tt>.
*
* A preconditioner is assumed to be a plain C function pointer, where
* -# the function returns an <tt>int</tt> error code (where zero will be
* interpreted as success);
* -# the first argument is where the result of applying the preconditioner
* will be stored. It is a raw vector pointer, i.e., <tt>double *</tt>;
* -# the second argument contains the data on which the preconditioner
* action should be computed. It is a raw const vector pointer, i.e.,
* <tt>const double *</tt>;
* -# the third argument contains a pointer to any preconditioner data it
* may require. It is a raw void pointer, meaning, although usually not
* necessary nor recommended, the preconditioner data may be stateful.
*
* The function signature must match exactly this specification.
*/
typedef int (*sparse_cg_preconditioner_dxx_t) (
double * const,
const double * const,
void * const
);
/**
* Initialises a #sparse_cg_handle_t object.
*
* @param[out] handle An uninitialised handler to a CG solver.
*
* Initialisation proceeds according to a given system matrix given in
* Compressed Row Storage (CRS), also commonly known as the Compressed Sparse
* Rows (CSR) format.
*
* @param[in] n The size of the system matrix.
* @param[in] a The nonzero values of the system matrix.
* @param[in] ja The column indices of the nonzeroes of the system matrix.
* @param[in] ia The row offset array of the system matrix.
* @param[in] precon Whether the CG handle is expected to execute solves with
* preconditioning.
* @param[in] numa Whether the CG handle is expected to execute solves that
* employ more than one NUMA domain, in which case any memory
* allocated during construction of this handle may attempt
* to employ NUMA-aware allocation.
*
* The Boolean flags \a precon and \a numa indicated above are \em hints to the
* underlying ALP implementation.
*
* \note This means that even if \a precon was set to <tt>false</tt> during
* handle creation, a user may still request preconditioning and expect
* no error. Similarly, even if \a numa was set <tt>true</tt> during
* handle creation, the underlying ALP implementation may still opt to
* \em not employ NUMA-aware allocation, for example, if it was configured
* without libnuma support.
*
* This variant is for single-precision floating point nonzeroes and integer
* \a ja and \a ia arrays, as also indicated by the <tt>sii</tt> postfix.
*
* @returns #ILLEGAL_ARGUMENT If \a n equals zero.
* @returns #NULL_ARGUMENT If \a handle is <tt>NULL</tt>.
* @returns #NULL_ARGUMENT If any of \a a, \a ja, or \a ia are <tt>NULL</tt>.
* @returns #OUT_OF_MEMORY In case of encountering out-of-memory conditions.
*
* On returning any of the above errors, the call to this function shall not have
* any other effects (than having returned the error code).
*
* \note This implies in particular that any initially given invalid and
* non-<tt>NULL</tt> \a handle may be reused for future, potentially
* successful, calls to this (or any other) initialisation function.
*
* @returns #NO_ERROR If initialisation of the handle proceeded
* successfully. Only in this case shall \a handle
* henceforth be a \em valid handle.
*
* On returning #NO_ERROR, \a handle shall correspond to an initialised (P)CG
* solver instance. Note that this handle contains workspace memory that are
* necessary for auxiliary vectors required by the CG algorithm. When
* preconditioning is employed, four such workspace vectors of size \a n are
* required; otherwise, only three such vectors are required. This memory will
* be freed on a call to #sparse_cg_destroy_sii.
*/
sparse_err_t sparse_cg_init_opt_sii(
sparse_cg_handle_t * const handle, const size_t n,
const float * const a, const int * const ja, const int * const ia,
const bool precon, const bool numa
);
/**
* Variant of #sparse_cg_init_opt_sii that results in a #sparse_cg_handle_t with
* default hints (with preconditioning and with NUMA).
*
* @see sparse_cg_init_opt_sii for full details.
*/
sparse_err_t sparse_cg_init_sii(
sparse_cg_handle_t * const handle, const size_t n,
const float * const a, const int * const ja, const int * const ia
);
/**
* Variant of #sparse_cg_init_opt_sii that does not allocate workspace, but
* instead employs given user memory as its workspace memory.
*
* This variant of initialisation guarantees no additional dynamic memory
* allocation will be performed. A call to #sparse_cg_destroy_sii will likewise
* \em not free up the given \a workspace memory.
*
* @param[in,out] workspace The user-supplied memory that will be used as the
* work space for the returned PCG solver \a handle.
*
* Previous contents of the given \a workspace will be ignored, and, when given
* to this function, should be considered lost. On a successful call, the given
* memory should be considered to be under the sole custody of the PCG solver
* \a handle until the time the handle is destroyed; at that point, the
* ownership of the given memory will be returned to the callee. If the call to
* this function is not successful, the ownership of the memory region returns
* to the callee immediately. For as long as ownership of the memory region is
* not with the callee, the contents of the memory region are undefined while
* code not controlled by ALP is not allowed to write into the memory region.
*
* @param[in] workspace_size The size of the memory pointed to by \a workspace.
*
* The given workspace must have byte size greater than or equal to the value
* returned by a call to #sparse_cg_workspace_size_s.
*
* \note For variants that use double-precision values, the workspace must have
* byte size greater than or equal to the value returned by a call to
* #sparse_cg_workspace_size_d.
*
* \note Note that the hints that can be supplied to #sparse_cg_init_opt_sii
* affect its internal workspace allocation mechanisms. Therefore, those
* hints do not apply to this manual PCG solver initialisation variant.
*
* In addition to the possible return codes defined by #sparse_cg_init_opt_sii,
* a call to this variant may furthermore return:
*
* @returns #NULL_ARGUMENT If \a workspace equals <tt>NULL</tt>.
* @returns #ILLEGAL_ARGUMENT If \a workspace_size is smaller than required.
*
* Different from the specification of #sparse_cg_init_opt_sii, this variant
* may never return #OUT_OF_MEMORY.
*
* For further details, see #sparse_cg_init_opt_sii.
*/
sparse_err_t sparse_cg_manual_init_sii(
sparse_cg_handle_t * const handle, const size_t n,
const float * const a, const int * const ja, const int * const ia,
void * workspace, const size_t workspace_size
);
/**
* Initialises a #sparse_cg_handle_t object.
*
* This variant is for double-precision floating point nonzeroes and integer
* \a ja and \a ia arrays, as also indicated by the <tt>dii</tt> postfix.
*
* @see #sparse_cg_init_opt_sii for full documentation.
*/
sparse_err_t sparse_cg_init_opt_dii(
sparse_cg_handle_t * const handle, const size_t n,
const double * const a, const int * const ja, const int * const ia,
const bool precon, const bool numa
);
/**
* Variant of #sparse_cg_init_opt_dii that results in a #sparse_cg_handle_t with
* default hints (with preconditioning and with NUMA).
*
* @see sparse_cg_init_opt_dii for full details.
*/
sparse_err_t sparse_cg_init_dii(
sparse_cg_handle_t * const handle, const size_t n,
const double * const a, const int * const ja, const int * const ia
);
/**
* Variant of #sparse_cg_init_opt_dii that does not allocate workspace, but
* instead employs given user memory as its workspace memory.
*
* @see #sparse_cg_manual_init_sii for full details.
*/
sparse_err_t sparse_cg_manual_init_dii(
sparse_cg_handle_t * const handle, const size_t n,
const double * const a, const int * const ja, const int * const ia,
void * workspace, const size_t workspace_size
);
/**
* Initialises a #sparse_cg_handle_t object.
*
* This variant is for single-precision floating point nonzeroes,
* <tt>size_t</tt>-valued \a ja, and integer-valued \a ia, as also indicated by
* the <tt>siz</tt> postfix.
*
* @see #sparse_cg_init_opt_sii for full documentation.
*/
sparse_err_t sparse_cg_init_opt_siz(
sparse_cg_handle_t * const handle, const size_t n,
const float * const a, const int * const ja, const size_t * const ia,
const bool precon, const bool numa
);
/**
* Variant of #sparse_cg_init_opt_siz that results in a #sparse_cg_handle_t with
* default hints (with preconditioning and with NUMA).
*
* @see sparse_cg_init_opt_siz for full details.
*/
sparse_err_t sparse_cg_init_siz(
sparse_cg_handle_t * const handle, const size_t n,
const float * const a, const int * const ja, const size_t * const ia
);
/**
* Variant of #sparse_cg_init_opt_siz that does not allocate workspace, but
* instead employs given user memory as its workspace memory.
*
* @see #sparse_cg_manual_init_sii for full details.
*/
sparse_err_t sparse_cg_manual_init_siz(
sparse_cg_handle_t * const handle, const size_t n,
const float * const a, const int * const ja, const size_t * const ia,
void * workspace, const size_t workspace_size
);
/**
* Initialises a #sparse_cg_handle_t object.
*
* This variant is for double-precision floating point nonzeroes,
* <tt>size_t</tt>-valued \a ja, and integer-valued \a ia, as also indicated by
* the <tt>diz</tt> postfix.
*
* @see #sparse_cg_init_opt_sii for full documentation.
*/
sparse_err_t sparse_cg_init_opt_diz(
sparse_cg_handle_t * const handle, const size_t n,
const double * const a, const int * const ja, const size_t * const ia,
const bool precon, const bool numa
);
/**
* Variant of #sparse_cg_init_opt_diz that results in a #sparse_cg_handle_t with
* default hints (with preconditioning and with NUMA).
*
* @see sparse_cg_init_opt_diz for full details.
*/
sparse_err_t sparse_cg_init_diz(
sparse_cg_handle_t * const handle, const size_t n,
const double * const a, const int * const ja, const size_t * const ia
);
/**
* Variant of #sparse_cg_init_opt_siz that does not allocate workspace, but
* instead employs given user memory as its workspace memory.
*
* @see #sparse_cg_manual_init_sii for full details.
*/
sparse_err_t sparse_cg_manual_init_diz(
sparse_cg_handle_t * const handle, const size_t n,
const double * const a, const int * const ja, const size_t * const ia,
void * workspace, const size_t workspace_size
);
/**
* Initialises a #sparse_cg_handle_t object.
*
* This variant is for single-precision floating point nonzeroes and
* <tt>size_t</tt>-valued \a ja and \a ia, as also indicated by the <tt>szz</tt>
* postfix.
*
* @see #sparse_cg_init_opt_sii for full documentation.
*/
sparse_err_t sparse_cg_init_opt_szz(
sparse_cg_handle_t * const handle, const size_t n,
const float * const a, const size_t * const ja, const size_t * const ia,
const bool precon, const bool numa
);
/**
* Variant of #sparse_cg_init_opt_szz that results in a #sparse_cg_handle_t with
* default hints (with preconditioning and with NUMA).
*
* @see sparse_cg_init_opt_szz for full details.
*/
sparse_err_t sparse_cg_init_szz(
sparse_cg_handle_t * const handle, const size_t n,
const float * const a, const size_t * const ja, const size_t * const ia
);
/**
* Variant of #sparse_cg_init_opt_siz that does not allocate workspace, but
* instead employs given user memory as its workspace memory.
*
* @see #sparse_cg_manual_init_sii for full details.
*/
sparse_err_t sparse_cg_manual_init_szz(
sparse_cg_handle_t * const handle, const size_t n,
const float * const a, const size_t * const ja, const size_t * const ia,
void * workspace, const size_t workspace_size
);
/**
* Initialises a #sparse_cg_handle_t object.
*
* This variant is for double-precision floating point nonzeroes and
* <tt>size_t</tt>-valued \a ja and \a ia, as also indicated by the <tt>dzz</tt>
* postfix.
*
* @see #sparse_cg_init_opt_sii for full documentation.
*/
sparse_err_t sparse_cg_init_opt_dzz(
sparse_cg_handle_t * const handle, const size_t n,
const double * const a, const size_t * const ja, const size_t * const ia,
const bool precon, const bool numa
);
/**
* Variant of #sparse_cg_init_opt_dzz that results in a #sparse_cg_handle_t with
* default hints (with preconditioning and with NUMA).
*
* @see sparse_cg_init_opt_dzz for full details.
*/
sparse_err_t sparse_cg_init_dzz(
sparse_cg_handle_t * const handle, const size_t n,
const double * const a, const size_t * const ja, const size_t * const ia
);
/**
* Variant of #sparse_cg_init_opt_siz that does not allocate workspace, but
* instead employs given user memory as its workspace memory.
*
* @see #sparse_cg_manual_init_sii for full details.
*/
sparse_err_t sparse_cg_manual_init_dzz(
sparse_cg_handle_t * const handle, const size_t n,
const double * const a, const size_t * const ja, const size_t * const ia,
void * workspace, const size_t workspace_size
);
/**
* Returns the minimum workspace size required when manually supplying a
* workspace for PCG solvers to initialise with.
*
* Those so-called manual initialisation functions are the following:
* - #sparse_cg_manual_init_sii,
* - #sparse_cg_manual_init_siz, and
* - #sparse_cg_manual_init_szz.
* This is the variant for PCG solvers that operate on single-precision values.
*
* @param[in] n The maximum system size the solver will be initialised
* with.
* @param[in] precon Whether the solver is expected to use a preconditioner.
*
* \note If preconditioning is required, the solver requires a larger work
* space. Note, however, that even if initially not enough workspace is
* supplied for a preconditioned solve, nonetheless requesting a
* preconditioned solve will still execute -- it will then dynamically
* allocate memory on the fly.
*
* A call to this function never fails.
*
* @returns The required workspace size in bytes.
*/
size_t sparse_cg_workspace_size_s( const size_t n, const bool precon );
/**
* Returns the minimum workspace size required when manually supplying a
* workspace for PCG solvers to initialise with.
*
* Those so-called manual initialisation functions are the following:
* - #sparse_cg_manual_init_dii,
* - #sparse_cg_manual_init_diz, and
* - #sparse_cg_manual_init_dzz.
* This is the variant for PCG solvers that operate on double-precision values.
*
* @param[in] n The maximum system size the solver will be initialised
* with.
* @param[in] precon Whether the solver is expected to use a preconditioner.
*
* \note If preconditioning is required, the solver requires a larger work
* space. Note, however, that even if initially not enough workspace is
* supplied for a preconditioned solve, nonetheless requesting a
* preconditioned solve will still execute -- it will then dynamically
* allocate memory on the fly.
*
* A call to this function never fails.
*
* @returns The required workspace size in bytes.
*/
size_t sparse_cg_workspace_size_d( const size_t n, const bool precon );
// Note that szi and dzi are skipped on purpose. Such variants would not seem
// sensible, though could easily be provided if they do turn out to be needed
/**
* Retrieves the system size for a given CG solver handle.
*
* @param[in] handle A handle to a valid CG solver object.
* @param[out] size Where to store the system size.
*
* @returns #NULL_ARGUMENT If \a handle is <tt>NULL</tt>. If this error is
* returned, the call to this function shall not have
* any other effects.
* @returns #NULL_ARGUMENT If \a size is <tt>NULL</tt>. If this error code is
* returned, the call to this function shall have no
* other effects.
* @returns #NO_ERROR Otherwise.
*
* This variant is for CG solve instances of type <tt>sii</tt>.
*
* \warning If \a handle did not refer to a valid CG solver instance, the effect
* of calling this function is undefined(!).
*
* @see #sparse_cg_init_sii On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_get_size_sii(
sparse_cg_handle_t const handle, size_t * const size
);
/**
* Retrieves the system size for a given CG solver handle.
*
* @param[in] handle A handle to a valid CG solver object.
* @param[out] size Where to store the system size.
*
* @returns #NULL_ARGUMENT If \a handle is <tt>NULL</tt>. If this error is
* returned, the call to this function shall not have
* any other effects.
* @returns #NULL_ARGUMENT If \a size is <tt>NULL</tt>. If this error code is
* returned, the call to this function shall have no
* other effects.
* @returns #NO_ERROR Otherwise.
*
* This variant is for CG solve instances of type <tt>siz</tt>.
*
* \warning If \a handle did not refer to a valid CG solver instance, the effect
* of calling this function is undefined(!).
*
* @see #sparse_cg_init_siz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_get_size_siz(
sparse_cg_handle_t const handle, size_t * const size
);
/**
* Retrieves the system size for a given CG solver handle.
*
* @param[in] handle A handle to a valid CG solver object.
* @param[out] size Where to store the system size.
*
* @returns #NULL_ARGUMENT If \a handle is <tt>NULL</tt>. If this error is
* returned, the call to this function shall not have
* any other effects.
* @returns #NULL_ARGUMENT If \a size is <tt>NULL</tt>. If this error code is
* returned, the call to this function shall have no
* other effects.
* @returns #NO_ERROR Otherwise.
*
* This variant is for CG solve instances of type <tt>szz</tt>.
*
* \warning If \a handle did not refer to a valid CG solver instance, the effect
* of calling this function is undefined(!).
*
* @see #sparse_cg_init_szz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_get_size_szz(
sparse_cg_handle_t const handle, size_t * const size
);
/**
* Retrieves the system size for a given CG solver handle.
*
* @param[in] handle A handle to a valid CG solver object.
* @param[out] size Where to store the system size.
*
* @returns #NULL_ARGUMENT If \a handle is <tt>NULL</tt>. If this error is
* returned, the call to this function shall not have
* any other effects.
* @returns #NULL_ARGUMENT If \a size is <tt>NULL</tt>. If this error code is
* returned, the call to this function shall have no
* other effects.
* @returns #NO_ERROR Otherwise.
*
* This variant is for CG solve instances of type <tt>dii</tt>.
*
* \warning If \a handle did not refer to a valid CG solver instance, the effect
* of calling this function is undefined(!).
*
* @see #sparse_cg_init_dii On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_get_size_dii(
sparse_cg_handle_t const handle, size_t * const size
);
/**
* Retrieves the system size for a given CG solver handle.
*
* @param[in] handle A handle to a valid CG solver object.
* @param[out] size Where to store the system size.
*
* @returns #NULL_ARGUMENT If \a handle is <tt>NULL</tt>. If this error is
* returned, the call to this function shall not have
* any other effects.
* @returns #NULL_ARGUMENT If \a size is <tt>NULL</tt>. If this error code is
* returned, the call to this function shall have no
* other effects.
* @returns #NO_ERROR Otherwise.
*
* This variant is for CG solve instances of type <tt>diz</tt>.
*
* \warning If \a handle did not refer to a valid CG solver instance, the effect
* of calling this function is undefined(!).
*
* @see #sparse_cg_init_diz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_get_size_diz(
sparse_cg_handle_t const handle, size_t * const size
);
/**
* Retrieves the system size for a given CG solver handle.
*
* @param[in] handle A handle to a valid CG solver object.
* @param[out] size Where to store the system size.
*
* @returns #NULL_ARGUMENT If \a handle is <tt>NULL</tt>. If this error is
* returned, the call to this function shall not have
* any other effects.
* @returns #NULL_ARGUMENT If \a size is <tt>NULL</tt>. If this error code is
* returned, the call to this function shall have no
* other effects.
* @returns #NO_ERROR Otherwise.
*
* This variant is for CG solve instances of type <tt>dzz</tt>.
*
* \warning If \a handle did not refer to a valid CG solver instance, the effect
* of calling this function is undefined(!).
*
* @see #sparse_cg_init_dzz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_get_size_dzz(
sparse_cg_handle_t const handle, size_t * const size
);
/**
* Gets the current accepted relative tolerance for the given CG solver.
*
* @param[in] handle A handle to a valid CG solver object.
* @param[out] tol Where to store the currently effective tolerance.
*
* @returns #NULL_ARGUMENT If \a handle is <tt>NULL</tt>. If this error is
* returned, the call to this function shall not have
* any other effects.
* @returns #NULL_ARGUMENT If \a tol is <tt>NULL</tt>. If this error code is
* returned, the call to this function shall have no
* other effects.
* @returns #NO_ERROR Otherwise.
*
* This variant is for CG solver instances of type <tt>sii</tt>.
*
* \warning If \a handle did not refer to a valid CG solver instance, the effect
* of calling this function is undefined(!).
*
* @see #sparse_cg_init_sii On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_get_tolerance_sii(
const sparse_cg_handle_t handle, float * const tol );
/**
* Gets the current accepted relative tolerance for the given CG solver.
*
* This variant is for CG solver instances of type <tt>siz</tt>.
*
* @see #sparse_cg_get_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_siz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_get_tolerance_siz(
const sparse_cg_handle_t handle, float * const tol );
/**
* Gets the current accepted relative tolerance for the given CG solver.
*
* This variant is for CG solver instances of type <tt>szz</tt>.
*
* @see #sparse_cg_get_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_szz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_get_tolerance_szz(
const sparse_cg_handle_t handle, float * const tol );
/**
* Gets the current accepted relative tolerance for the given CG solver.
*
* This variant is for CG solver instances of type <tt>dii</tt>.
*
* @see #sparse_cg_get_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_dii On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_get_tolerance_dii(
const sparse_cg_handle_t handle, double * const tol );
/**
* Gets the current accepted relative tolerance for the given CG solver.
*
* This variant is for CG solver instances of type <tt>diz</tt>.
*
* @see #sparse_cg_get_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_diz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_get_tolerance_diz(
const sparse_cg_handle_t handle, double * const tol );
/**
* Gets the current accepted relative tolerance for the given CG solver.
*
* This variant is for CG solver instances of type <tt>dzz</tt>.
*
* @see #sparse_cg_get_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_dzz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_get_tolerance_dzz(
const sparse_cg_handle_t handle, double * const tol );
/**
* Sets the current accepted relative tolerance for the given CG solver.
*
* @param[in,out] handle A handle to a valid CG solver object.
* @param[in] tol The given tolerance.
*
* @returns #NULL_ARGUMENT If \a handle is <tt>NULL</tt>. If this error is
* returned, the call to this function shall not have
* any other effects.
* @returns #NO_ERROR Otherwise.
*
* This variant is for CG solver instances of type <tt>sii</tt>.
*
* \warning If \a handle did not refer to a valid CG solver instance, the effect
* of calling this function is undefined(!).
*
* @see #sparse_cg_init_sii On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_set_tolerance_sii(
sparse_cg_handle_t handle, const float tol );
/**
* Sets the current accepted relative tolerance for the given CG solver.
*
* This variant is for CG solver instances of type <tt>siz</tt>.
*
* @see #sparse_cg_set_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_siz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_set_tolerance_siz(
sparse_cg_handle_t handle, const float tol );
/**
* Sets the current accepted relative tolerance for the given CG solver.
*
* This variant is for CG solver instances of type <tt>szz</tt>.
*
* @see #sparse_cg_set_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_szz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_set_tolerance_szz(
sparse_cg_handle_t handle, const float tol );
/**
* Sets the current accepted relative tolerance for the given CG solver.
*
* This variant is for CG solver instances of type <tt>dii</tt>.
*
* @see #sparse_cg_set_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_dii On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_set_tolerance_dii(
sparse_cg_handle_t handle, const double tol );
/**
* Sets the current accepted relative tolerance for the given CG solver.
*
* This variant is for CG solver instances of type <tt>diz</tt>.
*
* @see #sparse_cg_set_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_diz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_set_tolerance_diz(
sparse_cg_handle_t handle, const double tol );
/**
* Sets the current accepted relative tolerance for the given CG solver.
*
* This variant is for CG solver instances of type <tt>dzz</tt>.
*
* @see #sparse_cg_set_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_dzz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_set_tolerance_dzz(
sparse_cg_handle_t handle, const double tol );
/**
* Sets the current maximum number of iterations for the given CG solver.
*
* @param[in,out] handle A handle to a valid CG solver object.
* @param[in] max_iters The given maximum number of iterations.
*
* @returns #NULL_ARGUMENT If \a handle is <tt>NULL</tt>. If this error is
* returned, the call to this function shall not have
* any other effects.
* @returns #NO_ERROR Otherwise.
*
* This variant is for CG solver instances of type <tt>sii</tt>.
*
* \warning If \a handle did not refer to a valid CG solver instance, the effect
* of calling this function is undefined(!).
*
* @see #sparse_cg_init_sii On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_set_max_iter_count_sii(
sparse_cg_handle_t handle, const size_t max_iters );
/**
* Sets the current maximum number of iterations for the given CG solver.
*
* This variant is for CG solver instances of type <tt>siz</tt>.
*
* @see #sparse_cg_set_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_siz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_set_max_iter_count_siz(
sparse_cg_handle_t handle, const size_t max_iters );
/**
* Sets the current maximum number of iterations for the given CG solver.
*
* This variant is for CG solver instances of type <tt>szz</tt>.
*
* @see #sparse_cg_set_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_szz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_set_max_iter_count_szz(
sparse_cg_handle_t handle, const size_t max_iters );
/**
* Sets the current maximum number of iterations for the given CG solver.
*
* This variant is for CG solver instances of type <tt>dii</tt>.
*
* @see #sparse_cg_set_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_dii On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_set_max_iter_count_dii(
sparse_cg_handle_t handle, const size_t max_iters );
/**
* Sets the current maximum number of iterations for the given CG solver.
*
* This variant is for CG solver instances of type <tt>diz</tt>.
*
* @see #sparse_cg_set_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_diz On how to obtain a valid CG solver instance for use
* with this function.
*/
sparse_err_t sparse_cg_set_max_iter_count_diz(
sparse_cg_handle_t handle, const size_t max_iters );
/**
* Sets the current maximum number of iterations for the given CG solver.
*
* This variant is for CG solver instances of type <tt>dzz</tt>.
*
* @see #sparse_cg_set_tolerance_sii for full documentation.
*
* @see #sparse_cg_init_dzz On how to obtain a valid CG solver instance for use
* with this function.
*/