forked from petsc/petsc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpetscvec.h
1010 lines (808 loc) · 48.5 KB
/
petscvec.h
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
/*
Defines the vector component of PETSc. Vectors generally represent
degrees of freedom for finite element/finite difference functions
on a grid. They have more mathematical structure then simple arrays.
*/
#pragma once
#include <petscsys.h>
#include <petscsftypes.h> /* for VecScatter, VecScatterType */
#include <petscis.h>
#include <petscdevicetypes.h>
#include <petscviewer.h>
/* SUBMANSEC = Vec */
/*S
Vec - Abstract PETSc vector object. Used for holding solutions and right-hand sides for (non) linear systems and integrators
Level: beginner
Note:
Internally the actual vector representation is generally a simple array but most PETSc code can work on other representations through this abstraction
.seealso: [](doc_vector), [](ch_vectors), `VecCreate()`, `VecType`, `VecSetType()`
S*/
typedef struct _p_Vec *Vec;
/*E
ScatterMode - Determines the direction of a scatter
Values:
+ `SCATTER_FORWARD` - Scatters the values as dictated by the `VecScatterCreate()` call
. `SCATTER_REVERSE` - Moves the values in the opposite direction than the directions indicated in the `VecScatterCreate()` call
. `SCATTER_FORWARD_LOCAL` - Scatters the values as dictated by the `VecScatterCreate()` call except NO MPI communication is done
- `SCATTER_REVERSE_LOCAL` - Moves the values in the opposite direction than the directions indicated in the `VecScatterCreate()` call
except NO MPI communication is done
Level: beginner
.seealso: [](ch_vectors), `VecScatter`, `VecScatterBegin()`, `VecScatterEnd()`, `SCATTER_FORWARD`, `SCATTER_REVERSE`, `SCATTER_FORWARD_LOCAL`, `SCATTER_REVERSE_LOCAL`
E*/
typedef enum {
SCATTER_FORWARD = 0,
SCATTER_REVERSE = 1,
SCATTER_FORWARD_LOCAL = 2,
SCATTER_REVERSE_LOCAL = 3
} ScatterMode;
/*MC
SCATTER_FORWARD - Scatters the values as dictated by the `VecScatterCreate()` call
Level: beginner
.seealso: [](ch_vectors), `VecScatter`, `ScatterMode`, `VecScatterCreate()`, `VecScatterBegin()`, `VecScatterEnd()`, `SCATTER_REVERSE`, `SCATTER_FORWARD_LOCAL`,
`SCATTER_REVERSE_LOCAL`
M*/
/*MC
SCATTER_REVERSE - Moves the values in the opposite direction then the directions indicated in
in the `VecScatterCreate()`
Level: beginner
.seealso: [](ch_vectors), `VecScatter`, `ScatterMode`, `VecScatterCreate()`, `VecScatterBegin()`, `VecScatterEnd()`, `SCATTER_FORWARD`, `SCATTER_FORWARD_LOCAL`,
`SCATTER_REVERSE_LOCAL`
M*/
/*MC
SCATTER_FORWARD_LOCAL - Scatters the values as dictated by the `VecScatterCreate()` call except NO parallel communication
is done. Any variables that have be moved between processes are ignored
Level: developer
.seealso: [](ch_vectors), `VecScatter`, `ScatterMode`, `VecScatterCreate()`, `VecScatterBegin()`, `VecScatterEnd()`, `SCATTER_REVERSE`, `SCATTER_FORWARD`,
`SCATTER_REVERSE_LOCAL`
M*/
/*MC
SCATTER_REVERSE_LOCAL - Moves the values in the opposite direction then the directions indicated in
in the `VecScatterCreate()` except NO parallel communication
is done. Any variables that have be moved between processes are ignored
Level: developer
.seealso: [](ch_vectors), `VecScatter`, `ScatterMode`, `VecScatterCreate()`, `VecScatterBegin()`, `VecScatterEnd()`, `SCATTER_FORWARD`, `SCATTER_FORWARD_LOCAL`,
`SCATTER_REVERSE`
M*/
/*J
VecType - String with the name of a PETSc vector type
Level: beginner
.seealso: [](doc_vector), [](ch_vectors), `VecSetType()`, `Vec`, `VecCreate()`, `VecDestroy()`
J*/
typedef const char *VecType;
#define VECSEQ "seq"
#define VECMPI "mpi"
#define VECSTANDARD "standard" /* seq on one process and mpi on multiple */
#define VECSHARED "shared"
#define VECSEQVIENNACL "seqviennacl"
#define VECMPIVIENNACL "mpiviennacl"
#define VECVIENNACL "viennacl" /* seqviennacl on one process and mpiviennacl on multiple */
#define VECSEQCUDA "seqcuda"
#define VECMPICUDA "mpicuda"
#define VECCUDA "cuda" /* seqcuda on one process and mpicuda on multiple */
#define VECSEQHIP "seqhip"
#define VECMPIHIP "mpihip"
#define VECHIP "hip" /* seqhip on one process and mpihip on multiple */
#define VECNEST "nest"
#define VECSEQKOKKOS "seqkokkos"
#define VECMPIKOKKOS "mpikokkos"
#define VECKOKKOS "kokkos" /* seqkokkos on one process and mpikokkos on multiple */
/* Dynamic creation and loading functions */
PETSC_EXTERN PetscErrorCode VecScatterSetType(VecScatter, VecScatterType);
PETSC_EXTERN PetscErrorCode VecScatterGetType(VecScatter, VecScatterType *);
PETSC_EXTERN PetscErrorCode VecScatterSetFromOptions(VecScatter);
PETSC_EXTERN PetscErrorCode VecScatterRegister(const char[], PetscErrorCode (*)(VecScatter));
PETSC_EXTERN PetscErrorCode VecScatterCreate(Vec, IS, Vec, IS, VecScatter *);
/* Logging support */
#define REAL_FILE_CLASSID 1211213
#define VEC_FILE_CLASSID 1211214
PETSC_EXTERN PetscClassId VEC_CLASSID;
PETSC_EXTERN PetscClassId PETSCSF_CLASSID;
PETSC_EXTERN PetscErrorCode VecInitializePackage(void);
PETSC_EXTERN PetscErrorCode VecFinalizePackage(void);
PETSC_EXTERN PetscErrorCode VecCreate(MPI_Comm, Vec *);
PETSC_EXTERN PetscErrorCode VecCreateFromOptions(MPI_Comm, const char *, PetscInt, PetscInt, PetscInt, Vec *);
PETSC_EXTERN PetscErrorCode VecCreateSeq(MPI_Comm, PetscInt, Vec *);
PETSC_EXTERN PetscErrorCode VecCreateMPI(MPI_Comm, PetscInt, PetscInt, Vec *);
PETSC_EXTERN PetscErrorCode VecCreateSeqWithArray(MPI_Comm, PetscInt, PetscInt, const PetscScalar[], Vec *);
PETSC_EXTERN PetscErrorCode VecCreateMPIWithArray(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscScalar[], Vec *);
PETSC_EXTERN PetscErrorCode VecCreateShared(MPI_Comm, PetscInt, PetscInt, Vec *);
PETSC_EXTERN PetscErrorCode VecSetFromOptions(Vec);
PETSC_EXTERN PetscErrorCode VecViewFromOptions(Vec, PetscObject, const char[]);
PETSC_EXTERN PetscErrorCode VecSetUp(Vec);
PETSC_EXTERN PetscErrorCode VecDestroy(Vec *);
PETSC_EXTERN PetscErrorCode VecZeroEntries(Vec);
PETSC_EXTERN PetscErrorCode VecSetOptionsPrefix(Vec, const char[]);
PETSC_EXTERN PetscErrorCode VecAppendOptionsPrefix(Vec, const char[]);
PETSC_EXTERN PetscErrorCode VecGetOptionsPrefix(Vec, const char *[]);
PETSC_EXTERN PetscErrorCode VecSetSizes(Vec, PetscInt, PetscInt);
PETSC_EXTERN PetscErrorCode VecDotNorm2(Vec, Vec, PetscScalar *, PetscReal *);
PETSC_EXTERN PetscErrorCode VecDot(Vec, Vec, PetscScalar *);
PETSC_EXTERN PetscErrorCode VecDotRealPart(Vec, Vec, PetscReal *);
PETSC_EXTERN PetscErrorCode VecTDot(Vec, Vec, PetscScalar *);
PETSC_EXTERN PetscErrorCode VecMDot(Vec, PetscInt, const Vec[], PetscScalar[]);
PETSC_EXTERN PetscErrorCode VecMTDot(Vec, PetscInt, const Vec[], PetscScalar[]);
PETSC_EXTERN PetscErrorCode VecGetSubVector(Vec, IS, Vec *);
PETSC_EXTERN PetscErrorCode VecRestoreSubVector(Vec, IS, Vec *);
PETSC_EXTERN PetscErrorCode VecConcatenate(PetscInt, const Vec[], Vec *, IS *[]);
/*E
NormType - determines what type of norm to compute
Values:
+ `NORM_1` - the one norm, $||v|| = \sum_i | v_i |$. $||A|| = \max_j || v_*j ||$, maximum column sum
. `NORM_2` - the two norm, $||v|| = sqrt(\sum_i |v_i|^2)$ (vectors only)
. `NORM_FROBENIUS` - $||A|| = sqrt(\sum_ij |A_ij|^2)$, same as `NORM_2` for vectors
. `NORM_INFINITY` - $||v|| = \max_i |v_i|$. $||A|| = \max_i || v_i* ||$, maximum row sum
- `NORM_1_AND_2` - computes both the 1 and 2 norm of a vector. The values are stored in two adjacent `PetscReal` memory locations
Level: beginner
Note:
The `v` above represents a `Vec` while the `A` represents a `Mat`
.seealso: [](ch_vectors), `Vec`, `Mat`, `VecNorm()`, `VecNormBegin()`, `VecNormEnd()`, `MatNorm()`, `NORM_1`,
`NORM_2`, `NORM_FROBENIUS`, `NORM_INFINITY`, `NORM_1_AND_2`
E*/
typedef enum {
NORM_1 = 0,
NORM_2 = 1,
NORM_FROBENIUS = 2,
NORM_INFINITY = 3,
NORM_1_AND_2 = 4
} NormType;
PETSC_EXTERN const char *const NormTypes[];
#define NORM_MAX NORM_INFINITY
/*MC
NORM_1 - the one norm, $||v|| = \sum_i | v_i |$. $||A|| = \max_j || v_{*,j} ||$, maximum column sum
Level: beginner
.seealso: [](ch_vectors), `NormType`, `MatNorm()`, `VecNorm()`, `VecNormBegin()`, `VecNormEnd()`, `NORM_2`, `NORM_FROBENIUS`,
`NORM_INFINITY`, `NORM_1_AND_2`
M*/
/*MC
NORM_2 - the two norm, $||v|| = \sqrt{\sum_i |v_i|^2}$ (vectors only)
Level: beginner
.seealso: [](ch_vectors), `NormType`, `MatNorm()`, `VecNorm()`, `VecNormBegin()`, `VecNormEnd()`, `NORM_1`, `NORM_FROBENIUS`,
`NORM_INFINITY`, `NORM_1_AND_2`
M*/
/*MC
NORM_FROBENIUS - $||A|| = \sqrt{\sum_{i,j} |A_{i,j}|^2}$, same as `NORM_2` for vectors
Level: beginner
.seealso: [](ch_vectors), `NormType`, `MatNorm()`, `VecNorm()`, `VecNormBegin()`, `VecNormEnd()`, `NORM_1`, `NORM_2`,
`NORM_INFINITY`, `NORM_1_AND_2`
M*/
/*MC
NORM_INFINITY - $||v|| = \max_i |v_i|$. $||A|| = \max_i || v_{i,*} ||$, maximum row sum
Level: beginner
.seealso: [](ch_vectors), `NormType`, `MatNorm()`, `VecNorm()`, `VecNormBegin()`, `VecNormEnd()`, `NORM_1`, `NORM_2`,
`NORM_FROBENIUS`, `NORM_1_AND_2`
M*/
/*MC
NORM_1_AND_2 - computes both the 1 and 2 norm of a vector. The values are stored in two adjacent `PetscReal` memory locations
Level: beginner
.seealso: [](ch_vectors), `NormType`, `MatNorm()`, `VecNorm()`, `VecNormBegin()`, `VecNormEnd()`, `NORM_1`, `NORM_2`,
`NORM_FROBENIUS`, `NORM_INFINITY`
M*/
/*MC
NORM_MAX - see `NORM_INFINITY`
Level: beginner
M*/
/*E
ReductionType - determines what type of column reduction (one that is not a type of norm defined in `NormType`) to compute
Values:
+ `REDUCTION_SUM_REALPART` - sum of real part of each matrix column
. `REDUCTION_SUM_IMAGINARYPART` - sum of imaginary part of each matrix column
. `REDUCTION_MEAN_REALPART` - arithmetic mean of real part of each matrix column
- `REDUCTION_MEAN_IMAGINARYPART` - arithmetic mean of imaginary part of each matrix column
Level: beginner
Developer Note:
The constants defined in `ReductionType` MUST BE DISTINCT from those defined in `NormType`.
This is because `MatGetColumnReductions()` is used to compute both norms and other types of reductions,
and the constants defined in both `NormType` and `ReductionType` are used to designate the desired operation.
.seealso: [](ch_vectors), `MatGetColumnReductions()`, `MatGetColumnNorms()`, `NormType`, `REDUCTION_SUM_REALPART`,
`REDUCTION_SUM_IMAGINARYPART`, `REDUCTION_MEAN_REALPART`, `REDUCTION_NORM_1`, `REDUCTION_NORM_2`, `REDUCTION_NORM_FROBENIUS`, `REDUCTION_NORM_INFINITY`
E*/
typedef enum {
REDUCTION_SUM_REALPART = 10,
REDUCTION_MEAN_REALPART = 11,
REDUCTION_SUM_IMAGINARYPART = 12,
REDUCTION_MEAN_IMAGINARYPART = 13
} ReductionType;
/*MC
REDUCTION_SUM_REALPART - sum of real part of matrix column
Level: beginner
.seealso: [](ch_vectors), `ReductionType`, `MatGetColumnReductions()`, `REDUCTION_SUM_IMAGINARYPART`, `REDUCTION_MEAN_REALPART`, `REDUCTION_NORM_1`,
`REDUCTION_NORM_2`, `REDUCTION_NORM_FROBENIUS`, `REDUCTION_NORM_INFINITY`
M*/
/*MC
REDUCTION_SUM_IMAGINARYPART - sum of imaginary part of matrix column
Level: beginner
.seealso: [](ch_vectors), `ReductionType`, `MatGetColumnReductions()`, `REDUCTION_SUM_REALPART`, `REDUCTION_MEAN_IMAGINARYPART`, `REDUCTION_NORM_1`,
`REDUCTION_NORM_2`, `REDUCTION_NORM_FROBENIUS`, `REDUCTION_NORM_INFINITY`
M*/
/*MC
REDUCTION_MEAN_REALPART - arithmetic mean of real part of matrix column
Level: beginner
.seealso: [](ch_vectors), `ReductionType`, `MatGetColumnReductions()`, `REDUCTION_MEAN_IMAGINARYPART`, `REDUCTION_SUM_REALPART`, `REDUCTION_NORM_1`,
`REDUCTION_NORM_2`, `REDUCTION_NORM_FROBENIUS`, `REDUCTION_NORM_INFINITY`
M*/
/*MC
REDUCTION_MEAN_IMAGINARYPART - arithmetic mean of imaginary part of matrix column
Level: beginner
.seealso: [](ch_vectors), `ReductionType`, `MatGetColumnReductions()`, `REDUCTION_MEAN_REALPART`, `REDUCTION_SUM_IMAGINARYPART`, `REDUCTION_NORM_1`,
`REDUCTION_NORM_2`, `REDUCTION_NORM_FROBENIUS`, `REDUCTION_NORM_INFINITY`
M*/
PETSC_EXTERN PetscErrorCode VecNorm(Vec, NormType, PetscReal *);
PETSC_EXTERN PetscErrorCode VecNormAvailable(Vec, NormType, PetscBool *, PetscReal *);
PETSC_EXTERN PetscErrorCode VecNormalize(Vec, PetscReal *);
PETSC_EXTERN PetscErrorCode VecSum(Vec, PetscScalar *);
PETSC_EXTERN PetscErrorCode VecMean(Vec, PetscScalar *);
PETSC_EXTERN PetscErrorCode VecMax(Vec, PetscInt *, PetscReal *);
PETSC_EXTERN PetscErrorCode VecMin(Vec, PetscInt *, PetscReal *);
PETSC_EXTERN PetscErrorCode VecScale(Vec, PetscScalar);
PETSC_EXTERN PetscErrorCode VecCopy(Vec, Vec);
PETSC_EXTERN PetscErrorCode VecSetRandom(Vec, PetscRandom);
PETSC_EXTERN PetscErrorCode VecSet(Vec, PetscScalar);
PETSC_EXTERN PetscErrorCode VecSetInf(Vec);
PETSC_EXTERN PetscErrorCode VecSwap(Vec, Vec);
PETSC_EXTERN PetscErrorCode VecAXPY(Vec, PetscScalar, Vec);
PETSC_EXTERN PetscErrorCode VecAXPBY(Vec, PetscScalar, PetscScalar, Vec);
PETSC_EXTERN PetscErrorCode VecMAXPY(Vec, PetscInt, const PetscScalar[], Vec[]);
PETSC_EXTERN PetscErrorCode VecMAXPBY(Vec, PetscInt, const PetscScalar[], PetscScalar, Vec[]);
PETSC_EXTERN PetscErrorCode VecAYPX(Vec, PetscScalar, Vec);
PETSC_EXTERN PetscErrorCode VecWAXPY(Vec, PetscScalar, Vec, Vec);
PETSC_EXTERN PetscErrorCode VecAXPBYPCZ(Vec, PetscScalar, PetscScalar, PetscScalar, Vec, Vec);
PETSC_EXTERN PetscErrorCode VecPointwiseMax(Vec, Vec, Vec);
PETSC_EXTERN PetscErrorCode VecPointwiseMaxAbs(Vec, Vec, Vec);
PETSC_EXTERN PetscErrorCode VecPointwiseMin(Vec, Vec, Vec);
PETSC_EXTERN PetscErrorCode VecPointwiseMult(Vec, Vec, Vec);
PETSC_EXTERN PetscErrorCode VecPointwiseDivide(Vec, Vec, Vec);
PETSC_EXTERN PetscErrorCode VecMaxPointwiseDivide(Vec, Vec, PetscReal *);
PETSC_EXTERN PetscErrorCode VecShift(Vec, PetscScalar);
PETSC_EXTERN PetscErrorCode VecReciprocal(Vec);
PETSC_EXTERN PetscErrorCode VecPermute(Vec, IS, PetscBool);
PETSC_EXTERN PetscErrorCode VecSqrtAbs(Vec);
PETSC_EXTERN PetscErrorCode VecLog(Vec);
PETSC_EXTERN PetscErrorCode VecExp(Vec);
PETSC_EXTERN PetscErrorCode VecAbs(Vec);
PETSC_EXTERN PetscErrorCode VecDuplicate(Vec, Vec *);
PETSC_EXTERN PetscErrorCode VecDuplicateVecs(Vec, PetscInt, Vec *[]);
PETSC_EXTERN PetscErrorCode VecDestroyVecs(PetscInt, Vec *[]);
PETSC_EXTERN PetscErrorCode VecStrideNormAll(Vec, NormType, PetscReal[]);
PETSC_EXTERN PetscErrorCode VecStrideMaxAll(Vec, PetscInt[], PetscReal[]);
PETSC_EXTERN PetscErrorCode VecStrideMinAll(Vec, PetscInt[], PetscReal[]);
PETSC_EXTERN PetscErrorCode VecStrideScaleAll(Vec, const PetscScalar[]);
PETSC_EXTERN PetscErrorCode VecStrideSumAll(Vec, PetscScalar *);
PETSC_EXTERN PetscErrorCode VecUniqueEntries(Vec, PetscInt *, PetscScalar **);
PETSC_EXTERN PetscErrorCode VecStrideNorm(Vec, PetscInt, NormType, PetscReal *);
PETSC_EXTERN PetscErrorCode VecStrideMax(Vec, PetscInt, PetscInt *, PetscReal *);
PETSC_EXTERN PetscErrorCode VecStrideMin(Vec, PetscInt, PetscInt *, PetscReal *);
PETSC_EXTERN PetscErrorCode VecStrideScale(Vec, PetscInt, PetscScalar);
PETSC_EXTERN PetscErrorCode VecStrideSum(Vec, PetscInt, PetscScalar *);
PETSC_EXTERN PetscErrorCode VecStrideSet(Vec, PetscInt, PetscScalar);
PETSC_EXTERN PetscErrorCode VecStrideGather(Vec, PetscInt, Vec, InsertMode);
PETSC_EXTERN PetscErrorCode VecStrideScatter(Vec, PetscInt, Vec, InsertMode);
PETSC_EXTERN PetscErrorCode VecStrideGatherAll(Vec, Vec[], InsertMode);
PETSC_EXTERN PetscErrorCode VecStrideScatterAll(Vec[], Vec, InsertMode);
PETSC_EXTERN PetscErrorCode VecStrideSubSetScatter(Vec, PetscInt, const PetscInt[], const PetscInt[], Vec, InsertMode);
PETSC_EXTERN PetscErrorCode VecStrideSubSetGather(Vec, PetscInt, const PetscInt[], const PetscInt[], Vec, InsertMode);
PETSC_EXTERN PetscErrorCode VecSetValues(Vec, PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
PETSC_EXTERN PetscErrorCode VecGetValues(Vec, PetscInt, const PetscInt[], PetscScalar[]);
PETSC_EXTERN PetscErrorCode VecAssemblyBegin(Vec);
PETSC_EXTERN PetscErrorCode VecAssemblyEnd(Vec);
PETSC_EXTERN PetscErrorCode VecStashSetInitialSize(Vec, PetscInt, PetscInt);
PETSC_EXTERN PetscErrorCode VecStashView(Vec, PetscViewer);
PETSC_EXTERN PetscErrorCode VecStashViewFromOptions(Vec, PetscObject, const char[]);
PETSC_EXTERN PetscErrorCode VecStashGetInfo(Vec, PetscInt *, PetscInt *, PetscInt *, PetscInt *);
PETSC_EXTERN PetscErrorCode VecSetPreallocationCOO(Vec, PetscCount, const PetscInt[]);
PETSC_EXTERN PetscErrorCode VecSetPreallocationCOOLocal(Vec, PetscCount, PetscInt[]);
PETSC_EXTERN PetscErrorCode VecSetValuesCOO(Vec, const PetscScalar[], InsertMode);
/*MC
VecSetValue - Set a single entry into a vector.
Synopsis:
#include <petscvec.h>
PetscErrorCode VecSetValue(Vec v,PetscInt row,PetscScalar value, InsertMode mode);
Not Collective
Input Parameters:
+ v - the vector
. row - the row location of the entry
. value - the value to insert
- mode - either `INSERT_VALUES` or `ADD_VALUES`
Level: beginner
Notes:
For efficiency one should use `VecSetValues()` and set several or
many values simultaneously if possible.
These values may be cached, so `VecAssemblyBegin()` and `VecAssemblyEnd()`
MUST be called after all calls to `VecSetValue()` have been completed.
`VecSetValue()` uses 0-based indices in Fortran as well as in C.
.seealso: [](ch_vectors), `VecSetValues()`, `VecAssemblyBegin()`, `VecAssemblyEnd()`, `VecSetValuesBlockedLocal()`, `VecSetValueLocal()`
M*/
static inline PetscErrorCode VecSetValue(Vec v, PetscInt i, PetscScalar va, InsertMode mode)
{
return VecSetValues(v, 1, &i, &va, mode);
}
PETSC_EXTERN PetscErrorCode VecSetBlockSize(Vec, PetscInt);
PETSC_EXTERN PetscErrorCode VecGetBlockSize(Vec, PetscInt *);
PETSC_EXTERN PetscErrorCode VecSetValuesBlocked(Vec, PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
/* Dynamic creation and loading functions */
PETSC_EXTERN PetscFunctionList VecList;
PETSC_EXTERN PetscErrorCode VecSetType(Vec, VecType);
PETSC_EXTERN PetscErrorCode VecGetType(Vec, VecType *);
PETSC_EXTERN PetscErrorCode VecRegister(const char[], PetscErrorCode (*)(Vec));
PETSC_EXTERN PetscErrorCode VecRegisterAll(void);
PETSC_EXTERN PetscErrorCode VecScatterBegin(VecScatter, Vec, Vec, InsertMode, ScatterMode);
PETSC_EXTERN PetscErrorCode VecScatterEnd(VecScatter, Vec, Vec, InsertMode, ScatterMode);
PETSC_EXTERN PetscErrorCode VecScatterDestroy(VecScatter *);
PETSC_EXTERN PetscErrorCode VecScatterSetUp(VecScatter);
PETSC_EXTERN PetscErrorCode VecScatterCopy(VecScatter, VecScatter *);
PETSC_EXTERN PetscErrorCode VecScatterView(VecScatter, PetscViewer);
PETSC_EXTERN PetscErrorCode VecScatterViewFromOptions(VecScatter, PetscObject, const char[]);
PETSC_EXTERN PetscErrorCode VecScatterRemap(VecScatter, PetscInt[], PetscInt[]);
PETSC_EXTERN PetscErrorCode VecScatterGetMerged(VecScatter, PetscBool *);
PETSC_EXTERN PetscErrorCode VecGetArray4d(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]);
PETSC_EXTERN PetscErrorCode VecRestoreArray4d(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]);
PETSC_EXTERN PetscErrorCode VecGetArray3d(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ***[]);
PETSC_EXTERN PetscErrorCode VecRestoreArray3d(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ***[]);
PETSC_EXTERN PetscErrorCode VecGetArray2d(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar **[]);
PETSC_EXTERN PetscErrorCode VecRestoreArray2d(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar **[]);
PETSC_EXTERN PetscErrorCode VecGetArray1d(Vec, PetscInt, PetscInt, PetscScalar *[]);
PETSC_EXTERN PetscErrorCode VecRestoreArray1d(Vec, PetscInt, PetscInt, PetscScalar *[]);
PETSC_EXTERN PetscErrorCode VecGetArray4dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]);
PETSC_EXTERN PetscErrorCode VecGetArray4dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]);
PETSC_EXTERN PetscErrorCode VecRestoreArray4dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]);
PETSC_EXTERN PetscErrorCode VecGetArray3dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ***[]);
PETSC_EXTERN PetscErrorCode VecRestoreArray3dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ***[]);
PETSC_EXTERN PetscErrorCode VecGetArray2dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar **[]);
PETSC_EXTERN PetscErrorCode VecRestoreArray2dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar **[]);
PETSC_EXTERN PetscErrorCode VecGetArray1dWrite(Vec, PetscInt, PetscInt, PetscScalar *[]);
PETSC_EXTERN PetscErrorCode VecRestoreArray1dWrite(Vec, PetscInt, PetscInt, PetscScalar *[]);
PETSC_EXTERN PetscErrorCode VecGetArray4dRead(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]);
PETSC_EXTERN PetscErrorCode VecRestoreArray4dRead(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]);
PETSC_EXTERN PetscErrorCode VecGetArray3dRead(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ***[]);
PETSC_EXTERN PetscErrorCode VecRestoreArray3dRead(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ***[]);
PETSC_EXTERN PetscErrorCode VecGetArray2dRead(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar **[]);
PETSC_EXTERN PetscErrorCode VecRestoreArray2dRead(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar **[]);
PETSC_EXTERN PetscErrorCode VecGetArray1dRead(Vec, PetscInt, PetscInt, PetscScalar *[]);
PETSC_EXTERN PetscErrorCode VecRestoreArray1dRead(Vec, PetscInt, PetscInt, PetscScalar *[]);
PETSC_EXTERN PetscErrorCode VecPlaceArray(Vec, const PetscScalar[]);
PETSC_EXTERN PetscErrorCode VecResetArray(Vec);
PETSC_EXTERN PetscErrorCode VecReplaceArray(Vec, const PetscScalar[]);
PETSC_EXTERN PetscErrorCode VecGetArrays(const Vec[], PetscInt, PetscScalar **[]);
PETSC_EXTERN PetscErrorCode VecRestoreArrays(const Vec[], PetscInt, PetscScalar **[]);
PETSC_EXTERN PetscErrorCode VecView(Vec, PetscViewer);
PETSC_EXTERN PetscErrorCode VecViewNative(Vec, PetscViewer);
PETSC_EXTERN PetscErrorCode VecEqual(Vec, Vec, PetscBool *);
PETSC_EXTERN PetscErrorCode VecLoad(Vec, PetscViewer);
PETSC_EXTERN PetscErrorCode VecGetSize(Vec, PetscInt *);
PETSC_EXTERN PetscErrorCode VecGetLocalSize(Vec, PetscInt *);
PETSC_EXTERN PetscErrorCode VecGetOwnershipRange(Vec, PetscInt *, PetscInt *);
PETSC_EXTERN PetscErrorCode VecGetOwnershipRanges(Vec, const PetscInt *[]);
PETSC_EXTERN PetscErrorCode VecSetLocalToGlobalMapping(Vec, ISLocalToGlobalMapping);
PETSC_EXTERN PetscErrorCode VecSetValuesLocal(Vec, PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
PETSC_EXTERN PetscErrorCode VecViennaCLGetCLContext(Vec, PETSC_UINTPTR_T *);
PETSC_EXTERN PetscErrorCode VecViennaCLGetCLQueue(Vec, PETSC_UINTPTR_T *);
PETSC_EXTERN PetscErrorCode VecViennaCLGetCLMemRead(Vec, PETSC_UINTPTR_T *);
PETSC_EXTERN PetscErrorCode VecViennaCLGetCLMemWrite(Vec, PETSC_UINTPTR_T *);
PETSC_EXTERN PetscErrorCode VecViennaCLRestoreCLMemWrite(Vec);
PETSC_EXTERN PetscErrorCode VecViennaCLGetCLMem(Vec, PETSC_UINTPTR_T *);
PETSC_EXTERN PetscErrorCode VecViennaCLRestoreCLMem(Vec);
/*MC
VecSetValueLocal - Set a single entry into a vector using the local numbering, see `VecSetValuesLocal()`
Synopsis:
#include <petscvec.h>
PetscErrorCode VecSetValueLocal(Vec v,PetscInt row,PetscScalar value, InsertMode mode);
Not Collective
Input Parameters:
+ v - the vector
. row - the row location of the entry
. value - the value to insert
- mode - either `INSERT_VALUES` or `ADD_VALUES`
Level: beginner
Notes:
For efficiency one should use `VecSetValuesLocal()` and set several or
many values simultaneously if possible.
These values may be cached, so `VecAssemblyBegin()` and `VecAssemblyEnd()`
MUST be called after all calls to `VecSetValueLocal()` have been completed.
`VecSetValues()` uses 0-based indices in Fortran as well as in C.
.seealso: [](ch_vectors), `VecSetValuesLocal()`, `VecSetValues()`, `VecAssemblyBegin()`, `VecAssemblyEnd()`, `VecSetValuesBlockedLocal()`, `VecSetValue()`
M*/
static inline PetscErrorCode VecSetValueLocal(Vec v, PetscInt i, PetscScalar va, InsertMode mode)
{
return VecSetValuesLocal(v, 1, &i, &va, mode);
}
/*MC
VecCheckAssembled - checks if values have been changed in the vector, by `VecSetValues()` or related routines, but it has not been assembled
Synopsis:
#include <petscvec.h>
VecCheckAssembled(Vec v);
Not Collective
Input Parameter:
. v - the vector to check
Level: developer
Note:
After calls to `VecSetValues()` and related routines on must call ``VecAssemblyBegin()` and `VecAssemblyEnd()` before using the vector
.seealso: [](ch_vectors), `Vec`, `VecSetValues()`, `VecAssemblyBegin()`, `VecAssemblyEnd()`, `MatAssemblyBegin()`, `MatAssemblyEnd()`
M*/
#define VecCheckAssembled(v) PetscCheck(v->stash.insertmode == NOT_SET_VALUES, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Not for unassembled vector, did you call VecAssemblyBegin()/VecAssemblyEnd()?")
PETSC_EXTERN PetscErrorCode VecSetValuesBlockedLocal(Vec, PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
PETSC_EXTERN PetscErrorCode VecGetLocalToGlobalMapping(Vec, ISLocalToGlobalMapping *);
PETSC_EXTERN PetscErrorCode VecDotBegin(Vec, Vec, PetscScalar *);
PETSC_EXTERN PetscErrorCode VecDotEnd(Vec, Vec, PetscScalar *);
PETSC_EXTERN PetscErrorCode VecTDotBegin(Vec, Vec, PetscScalar *);
PETSC_EXTERN PetscErrorCode VecTDotEnd(Vec, Vec, PetscScalar *);
PETSC_EXTERN PetscErrorCode VecNormBegin(Vec, NormType, PetscReal *);
PETSC_EXTERN PetscErrorCode VecNormEnd(Vec, NormType, PetscReal *);
PETSC_EXTERN PetscErrorCode VecErrorWeightedNorms(Vec, Vec, Vec, NormType, PetscReal, Vec, PetscReal, Vec, PetscReal, PetscReal *, PetscInt *, PetscReal *, PetscInt *, PetscReal *, PetscInt *);
PETSC_EXTERN PetscErrorCode VecMDotBegin(Vec, PetscInt, const Vec[], PetscScalar[]);
PETSC_EXTERN PetscErrorCode VecMDotEnd(Vec, PetscInt, const Vec[], PetscScalar[]);
PETSC_EXTERN PetscErrorCode VecMTDotBegin(Vec, PetscInt, const Vec[], PetscScalar[]);
PETSC_EXTERN PetscErrorCode VecMTDotEnd(Vec, PetscInt, const Vec[], PetscScalar[]);
PETSC_EXTERN PetscErrorCode PetscCommSplitReductionBegin(MPI_Comm);
PETSC_EXTERN PetscErrorCode VecBindToCPU(Vec, PetscBool);
PETSC_DEPRECATED_FUNCTION(3, 13, 0, "VecBindToCPU()", ) static inline PetscErrorCode VecPinToCPU(Vec v, PetscBool flg)
{
return VecBindToCPU(v, flg);
}
PETSC_EXTERN PetscErrorCode VecBoundToCPU(Vec, PetscBool *);
PETSC_EXTERN PetscErrorCode VecSetBindingPropagates(Vec, PetscBool);
PETSC_EXTERN PetscErrorCode VecGetBindingPropagates(Vec, PetscBool *);
PETSC_EXTERN PetscErrorCode VecSetPinnedMemoryMin(Vec, size_t);
PETSC_EXTERN PetscErrorCode VecGetPinnedMemoryMin(Vec, size_t *);
PETSC_EXTERN PetscErrorCode VecGetOffloadMask(Vec, PetscOffloadMask *);
typedef enum {
VEC_IGNORE_OFF_PROC_ENTRIES,
VEC_IGNORE_NEGATIVE_INDICES,
VEC_SUBSET_OFF_PROC_ENTRIES
} VecOption;
PETSC_EXTERN PetscErrorCode VecSetOption(Vec, VecOption, PetscBool);
PETSC_EXTERN PetscErrorCode VecGetArray(Vec, PetscScalar **);
PETSC_EXTERN PetscErrorCode VecGetArrayWrite(Vec, PetscScalar **);
PETSC_EXTERN PetscErrorCode VecGetArrayRead(Vec, const PetscScalar **);
PETSC_EXTERN PetscErrorCode VecRestoreArray(Vec, PetscScalar **);
PETSC_EXTERN PetscErrorCode VecRestoreArrayWrite(Vec, PetscScalar **);
PETSC_EXTERN PetscErrorCode VecRestoreArrayRead(Vec, const PetscScalar **);
PETSC_EXTERN PetscErrorCode VecCreateLocalVector(Vec, Vec *);
PETSC_EXTERN PetscErrorCode VecGetLocalVector(Vec, Vec);
PETSC_EXTERN PetscErrorCode VecRestoreLocalVector(Vec, Vec);
PETSC_EXTERN PetscErrorCode VecGetLocalVectorRead(Vec, Vec);
PETSC_EXTERN PetscErrorCode VecRestoreLocalVectorRead(Vec, Vec);
PETSC_EXTERN PetscErrorCode VecGetArrayAndMemType(Vec, PetscScalar **, PetscMemType *);
PETSC_EXTERN PetscErrorCode VecRestoreArrayAndMemType(Vec, PetscScalar **);
PETSC_EXTERN PetscErrorCode VecGetArrayReadAndMemType(Vec, const PetscScalar **, PetscMemType *);
PETSC_EXTERN PetscErrorCode VecRestoreArrayReadAndMemType(Vec, const PetscScalar **);
PETSC_EXTERN PetscErrorCode VecGetArrayWriteAndMemType(Vec, PetscScalar **, PetscMemType *);
PETSC_EXTERN PetscErrorCode VecRestoreArrayWriteAndMemType(Vec, PetscScalar **);
/*@C
VecGetArrayPair - Accesses a pair of pointers for two vectors that may be common. When the vectors are not the same the first pointer is read only
Logically Collective; No Fortran Support
Input Parameters:
+ x - the vector
- y - the second vector
Output Parameters:
+ xv - location to put pointer to the first array
- yv - location to put pointer to the second array
Level: developer
.seealso: [](ch_vectors), `VecGetArray()`, `VecGetArrayRead()`, `VecRestoreArrayPair()`
@*/
static inline PetscErrorCode VecGetArrayPair(Vec x, Vec y, PetscScalar **xv, PetscScalar **yv)
{
PetscFunctionBegin;
PetscCall(VecGetArray(y, yv));
if (x == y) *xv = *yv;
else PetscCall(VecGetArrayRead(x, (const PetscScalar **)xv));
PetscFunctionReturn(PETSC_SUCCESS);
}
/*@C
VecRestoreArrayPair - Returns a pair of pointers for two vectors that may be common obtained with `VecGetArrayPair()`
Logically Collective; No Fortran Support
Input Parameters:
+ x - the vector
. y - the second vector
. xv - location to put pointer to the first array
- yv - location to put pointer to the second array
Level: developer
.seealso: [](ch_vectors), `VecGetArray()`, `VecGetArrayRead()`, `VecGetArrayPair()`
@*/
static inline PetscErrorCode VecRestoreArrayPair(Vec x, Vec y, PetscScalar **xv, PetscScalar **yv)
{
PetscFunctionBegin;
PetscCall(VecRestoreArray(y, yv));
if (x != y) PetscCall(VecRestoreArrayRead(x, (const PetscScalar **)xv));
PetscFunctionReturn(PETSC_SUCCESS);
}
#if PetscDefined(USE_DEBUG)
PETSC_EXTERN PetscErrorCode VecLockReadPush(Vec);
PETSC_EXTERN PetscErrorCode VecLockReadPop(Vec);
PETSC_EXTERN PetscErrorCode VecLockWriteSet(Vec, PetscBool);
PETSC_EXTERN PetscErrorCode VecLockGet(Vec, PetscInt *);
PETSC_EXTERN PetscErrorCode VecLockGetLocation(Vec, const char *[], const char *[], int *);
static inline PetscErrorCode VecSetErrorIfLocked(Vec x, PetscInt arg)
{
PetscInt state;
PetscFunctionBegin;
PetscCall(VecLockGet(x, &state));
if (PetscUnlikely(state != 0)) {
const char *file, *func, *name;
int line;
PetscCall(VecLockGetLocation(x, &file, &func, &line));
PetscCall(PetscObjectGetName((PetscObject)x, &name));
SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Vector '%s' (argument #%" PetscInt_FMT ") was locked for %s access in %s() at %s:%d (line numbers only accurate to function begin)", name, arg, state > 0 ? "read-only" : "write-only", func ? func : "unknown_function", file ? file : "unknown file", line);
}
PetscFunctionReturn(PETSC_SUCCESS);
}
/* The three are deprecated */
PETSC_EXTERN PETSC_DEPRECATED_FUNCTION(3, 11, 0, "VecLockReadPush()", ) PetscErrorCode VecLockPush(Vec);
PETSC_EXTERN PETSC_DEPRECATED_FUNCTION(3, 11, 0, "VecLockReadPop()", ) PetscErrorCode VecLockPop(Vec);
#define VecLocked(x, arg) VecSetErrorIfLocked(x, arg) PETSC_DEPRECATED_MACRO(3, 11, 0, "VecSetErrorIfLocked()", )
#else
#define VecLockReadPush(x) PETSC_SUCCESS
#define VecLockReadPop(x) PETSC_SUCCESS
#define VecLockGet(x, s) (*(s) = 0, PETSC_SUCCESS)
#define VecSetErrorIfLocked(x, arg) PETSC_SUCCESS
#define VecLockWriteSet(x, flg) PETSC_SUCCESS
/* The three are deprecated */
#define VecLockPush(x) PETSC_SUCCESS
#define VecLockPop(x) PETSC_SUCCESS
#define VecLocked(x, arg) PETSC_SUCCESS
#endif
/*E
VecOperation - Enumeration of overide-able methods in the `Vec` implementation function-table.
Values:
+ `VECOP_DUPLICATE` - `VecDuplicate()`
. `VECOP_SET` - `VecSet()`
. `VECOP_VIEW` - `VecView()`
. `VECOP_LOAD` - `VecLoad()`
. `VECOP_VIEWNATIVE` - `VecViewNative()`
- `VECOP_LOADNATIVE` - `VecLoadNative()`
Level: advanced
Notes:
Some operations may serve as the implementation for other routines not listed above. For
example `VECOP_SET` can be used to simultaneously overriding the implementation used in
`VecSet()`, `VecSetInf()`, and `VecZeroEntries()`.
Entries to `VecOperation` are added as needed so if you do not see the operation listed which
you'd like to replace, please send mail to `petsc-maint@mcs.anl.gov`!
.seealso: [](ch_vectors), `Vec`, `VecSetOperation()`
E*/
typedef enum {
VECOP_DUPLICATE = 0,
VECOP_SET = 10,
VECOP_VIEW = 33,
VECOP_LOAD = 41,
VECOP_VIEWNATIVE = 69,
VECOP_LOADNATIVE = 70
} VecOperation;
PETSC_EXTERN PetscErrorCode VecSetOperation(Vec, VecOperation, void (*)(void));
/*
Routines for dealing with ghosted vectors:
vectors with ghost elements at the end of the array.
*/
PETSC_EXTERN PetscErrorCode VecMPISetGhost(Vec, PetscInt, const PetscInt[]);
PETSC_EXTERN PetscErrorCode VecCreateGhost(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Vec *);
PETSC_EXTERN PetscErrorCode VecCreateGhostWithArray(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscScalar[], Vec *);
PETSC_EXTERN PetscErrorCode VecCreateGhostBlock(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], Vec *);
PETSC_EXTERN PetscErrorCode VecCreateGhostBlockWithArray(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscScalar[], Vec *);
PETSC_EXTERN PetscErrorCode VecGhostGetGhostIS(Vec, IS *);
PETSC_EXTERN PetscErrorCode VecGhostGetLocalForm(Vec, Vec *);
PETSC_EXTERN PetscErrorCode VecGhostRestoreLocalForm(Vec, Vec *);
PETSC_EXTERN PetscErrorCode VecGhostIsLocalForm(Vec, Vec, PetscBool *);
PETSC_EXTERN PetscErrorCode VecGhostUpdateBegin(Vec, InsertMode, ScatterMode);
PETSC_EXTERN PetscErrorCode VecGhostUpdateEnd(Vec, InsertMode, ScatterMode);
PETSC_EXTERN PetscErrorCode VecConjugate(Vec);
PETSC_EXTERN PetscErrorCode VecImaginaryPart(Vec);
PETSC_EXTERN PetscErrorCode VecRealPart(Vec);
PETSC_EXTERN PetscErrorCode VecScatterCreateToAll(Vec, VecScatter *, Vec *);
PETSC_EXTERN PetscErrorCode VecScatterCreateToZero(Vec, VecScatter *, Vec *);
/* These vector calls were included from TAO. They miss vtable entries and GPU implementation */
PETSC_EXTERN PetscErrorCode ISComplementVec(IS, Vec, IS *);
PETSC_EXTERN PetscErrorCode VecPow(Vec, PetscScalar);
PETSC_EXTERN PetscErrorCode VecMedian(Vec, Vec, Vec, Vec);
PETSC_EXTERN PetscErrorCode VecWhichInactive(Vec, Vec, Vec, Vec, PetscBool, IS *);
PETSC_EXTERN PetscErrorCode VecWhichBetween(Vec, Vec, Vec, IS *);
PETSC_EXTERN PetscErrorCode VecWhichBetweenOrEqual(Vec, Vec, Vec, IS *);
PETSC_EXTERN PetscErrorCode VecWhichGreaterThan(Vec, Vec, IS *);
PETSC_EXTERN PetscErrorCode VecWhichLessThan(Vec, Vec, IS *);
PETSC_EXTERN PetscErrorCode VecWhichEqual(Vec, Vec, IS *);
PETSC_EXTERN PetscErrorCode VecISAXPY(Vec, IS, PetscScalar, Vec);
PETSC_EXTERN PetscErrorCode VecISCopy(Vec, IS, ScatterMode, Vec);
PETSC_EXTERN PetscErrorCode VecISSet(Vec, IS, PetscScalar);
PETSC_EXTERN PetscErrorCode VecISShift(Vec, IS, PetscScalar);
PETSC_EXTERN PetscErrorCode VecBoundGradientProjection(Vec, Vec, Vec, Vec, Vec);
PETSC_EXTERN PetscErrorCode VecStepBoundInfo(Vec, Vec, Vec, Vec, PetscReal *, PetscReal *, PetscReal *);
PETSC_EXTERN PetscErrorCode VecStepMax(Vec, Vec, PetscReal *);
PETSC_EXTERN PetscErrorCode VecStepMaxBounded(Vec, Vec, Vec, Vec, PetscReal *);
PETSC_EXTERN PetscErrorCode PetscViewerMathematicaGetVector(PetscViewer, Vec);
PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutVector(PetscViewer, Vec);
/*S
Vecs - Collection of vectors where the data for the vectors is stored in
one contiguous memory
Level: advanced
Notes:
Temporary construct for handling multiply right hand side solves
This is faked by storing a single vector that has enough array space for
n vectors
S*/
struct _n_Vecs {
PetscInt n;
Vec v;
};
typedef struct _n_Vecs *Vecs;
PETSC_EXTERN PetscErrorCode VecsDestroy(Vecs);
PETSC_EXTERN PetscErrorCode VecsCreateSeq(MPI_Comm, PetscInt, PetscInt, Vecs *);
PETSC_EXTERN PetscErrorCode VecsCreateSeqWithArray(MPI_Comm, PetscInt, PetscInt, PetscScalar *, Vecs *);
PETSC_EXTERN PetscErrorCode VecsDuplicate(Vecs, Vecs *);
#if PetscDefined(HAVE_VIENNACL)
typedef struct _p_PetscViennaCLIndices *PetscViennaCLIndices;
PETSC_EXTERN PetscErrorCode VecViennaCLCopyToGPUSome_Public(Vec, PetscViennaCLIndices);
PETSC_EXTERN PetscErrorCode VecViennaCLCopyFromGPUSome_Public(Vec, PetscViennaCLIndices);
PETSC_EXTERN PetscErrorCode VecCreateSeqViennaCL(MPI_Comm, PetscInt, Vec *);
PETSC_EXTERN PetscErrorCode VecCreateMPIViennaCL(MPI_Comm, PetscInt, PetscInt, Vec *);
#endif
#if PetscDefined(HAVE_CUDA) || PetscDefined(HAVE_HIP)
PETSC_EXTERN PetscErrorCode VecScatterInitializeForGPU(VecScatter, Vec);
PETSC_EXTERN PetscErrorCode VecScatterFinalizeForGPU(VecScatter);
#endif
#if PetscDefined(HAVE_KOKKOS_KERNELS)
PETSC_EXTERN PetscErrorCode VecCreateSeqKokkos(MPI_Comm, PetscInt, Vec *);
PETSC_EXTERN PetscErrorCode VecCreateSeqKokkosWithArray(MPI_Comm, PetscInt, PetscInt, const PetscScalar *, Vec *);
PETSC_EXTERN PetscErrorCode VecCreateMPIKokkos(MPI_Comm, PetscInt, PetscInt, Vec *);
PETSC_EXTERN PetscErrorCode VecCreateMPIKokkosWithArray(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscScalar *, Vec *);
#endif
PETSC_EXTERN PetscErrorCode VecNestGetSubVecs(Vec, PetscInt *, Vec **);
PETSC_EXTERN PetscErrorCode VecNestGetSubVec(Vec, PetscInt, Vec *);
PETSC_EXTERN PetscErrorCode VecNestSetSubVecs(Vec, PetscInt, PetscInt *, Vec *);
PETSC_EXTERN PetscErrorCode VecNestSetSubVec(Vec, PetscInt, Vec);
PETSC_EXTERN PetscErrorCode VecCreateNest(MPI_Comm, PetscInt, IS *, Vec *, Vec *);
PETSC_EXTERN PetscErrorCode VecNestGetSize(Vec, PetscInt *);
PETSC_EXTERN PetscErrorCode PetscOptionsGetVec(PetscOptions, const char[], const char[], Vec, PetscBool *);
PETSC_EXTERN PetscErrorCode VecFilter(Vec, PetscReal);
PETSC_DEPRECATED_FUNCTION(3, 20, 0, "VecFilter()", ) static inline PetscErrorCode VecChop(Vec v, PetscReal tol)
{
return VecFilter(v, tol);
}
PETSC_EXTERN PetscErrorCode VecGetLayout(Vec, PetscLayout *);
PETSC_EXTERN PetscErrorCode VecSetLayout(Vec, PetscLayout);
PETSC_EXTERN PetscErrorCode PetscSectionVecView(PetscSection, Vec, PetscViewer);
PETSC_EXTERN PetscErrorCode VecGetValuesSection(Vec, PetscSection, PetscInt, PetscScalar **);
PETSC_EXTERN PetscErrorCode VecSetValuesSection(Vec, PetscSection, PetscInt, const PetscScalar[], InsertMode);
PETSC_EXTERN PetscErrorCode PetscSectionVecNorm(PetscSection, PetscSection, Vec, NormType, PetscReal[]);
/*S
VecTagger - Object used to manage the tagging of a subset of indices based on the values of a vector. The
motivating application is the selection of cells for refinement or coarsening based on vector containing
the values in an error indicator metric.
Values:
+ `VECTAGGERABSOLUTE` - "absolute" values are in a interval (box for complex values) of explicitly defined values
. `VECTAGGERRELATIVE` - "relative" values are in a interval (box for complex values) of values relative to the set of all values in the vector
. `VECTAGGERCDF` - "cdf" values are in a relative range of the *cumulative distribution* of values in the vector
. `VECTAGGEROR` - "or" values are in the union of other tags
- `VECTAGGERAND` - "and" values are in the intersection of other tags
Level: advanced
Developer Note:
Why not use a `DMLabel` or similar object
.seealso: [](ch_vectors), `Vec`, `VecTaggerType`, `VecTaggerCreate()`
S*/
typedef struct _p_VecTagger *VecTagger;
/*J
VecTaggerType - String with the name of a `VecTagger` type
Level: advanced
.seealso: [](ch_vectors), `Vec`, `VecTagger`, `VecTaggerCreate()`
J*/
typedef const char *VecTaggerType;
#define VECTAGGERABSOLUTE "absolute"
#define VECTAGGERRELATIVE "relative"
#define VECTAGGERCDF "cdf"
#define VECTAGGEROR "or"
#define VECTAGGERAND "and"
PETSC_EXTERN PetscClassId VEC_TAGGER_CLASSID;
PETSC_EXTERN PetscFunctionList VecTaggerList;
PETSC_EXTERN PetscErrorCode VecTaggerRegister(const char[], PetscErrorCode (*)(VecTagger));
PETSC_EXTERN PetscErrorCode VecTaggerRegisterAll(void);
PETSC_EXTERN PetscErrorCode VecTaggerCreate(MPI_Comm, VecTagger *);
PETSC_EXTERN PetscErrorCode VecTaggerSetBlockSize(VecTagger, PetscInt);
PETSC_EXTERN PetscErrorCode VecTaggerGetBlockSize(VecTagger, PetscInt *);
PETSC_EXTERN PetscErrorCode VecTaggerSetType(VecTagger, VecTaggerType);
PETSC_EXTERN PetscErrorCode VecTaggerGetType(VecTagger, VecTaggerType *);
PETSC_EXTERN PetscErrorCode VecTaggerSetInvert(VecTagger, PetscBool);
PETSC_EXTERN PetscErrorCode VecTaggerGetInvert(VecTagger, PetscBool *);
PETSC_EXTERN PetscErrorCode VecTaggerSetFromOptions(VecTagger);
PETSC_EXTERN PetscErrorCode VecTaggerSetUp(VecTagger);
PETSC_EXTERN PetscErrorCode VecTaggerView(VecTagger, PetscViewer);
PETSC_EXTERN PetscErrorCode VecTaggerComputeIS(VecTagger, Vec, IS *, PetscBool *);
PETSC_EXTERN PetscErrorCode VecTaggerDestroy(VecTagger *);
/*S
VecTaggerBox - A interval (box for complex numbers) range used to tag values. For real scalars, this is just a closed interval; for complex scalars,
the box is the closed region in the complex plane such that real(min) <= real(z) <= real(max) and imag(min) <= imag(z) <= imag(max). `INF` is an acceptable endpoint.
Level: beginner
.seealso: [](ch_vectors), `Vec`, `VecTagger`, `VecTaggerType`, `VecTaggerCreate()`, `VecTaggerComputeIntervals()`
S*/
typedef struct {
PetscScalar min;
PetscScalar max;
} VecTaggerBox;
PETSC_EXTERN PetscErrorCode VecTaggerComputeBoxes(VecTagger, Vec, PetscInt *, VecTaggerBox **, PetscBool *);
PETSC_EXTERN PetscErrorCode VecTaggerAbsoluteSetBox(VecTagger, VecTaggerBox *);
PETSC_EXTERN PetscErrorCode VecTaggerAbsoluteGetBox(VecTagger, const VecTaggerBox **);
PETSC_EXTERN PetscErrorCode VecTaggerRelativeSetBox(VecTagger, VecTaggerBox *);
PETSC_EXTERN PetscErrorCode VecTaggerRelativeGetBox(VecTagger, const VecTaggerBox **);
PETSC_EXTERN PetscErrorCode VecTaggerCDFSetBox(VecTagger, VecTaggerBox *);
PETSC_EXTERN PetscErrorCode VecTaggerCDFGetBox(VecTagger, const VecTaggerBox **);
/*E
VecTaggerCDFMethod - Determines what method is used to compute absolute values from cumulative distribution values (e.g., what value is the preimage of .95 in the cdf).
Values:
+ `VECTAGGER_CDF_GATHER` - gather results to MPI rank 0, perform the computation and broadcast the result
- `VECTAGGER_CDF_ITERATIVE` - compute the results on all ranks iteratively using `MPI_Allreduce()`
Level: advanced
Note:
Relevant only in parallel: in serial it is directly computed.
.seealso: [](ch_vectors), `Vec`, `VecTagger`, `VecTaggerType`, `VecTaggerCreate()`, `VecTaggerCDFSetMethod()`, `VecTaggerCDFMethods`
E*/
typedef enum {
VECTAGGER_CDF_GATHER,
VECTAGGER_CDF_ITERATIVE,
VECTAGGER_CDF_NUM_METHODS
} VecTaggerCDFMethod;
PETSC_EXTERN const char *const VecTaggerCDFMethods[];
PETSC_EXTERN PetscErrorCode VecTaggerCDFSetMethod(VecTagger, VecTaggerCDFMethod);
PETSC_EXTERN PetscErrorCode VecTaggerCDFGetMethod(VecTagger, VecTaggerCDFMethod *);
PETSC_EXTERN PetscErrorCode VecTaggerCDFIterativeSetTolerances(VecTagger, PetscInt, PetscReal, PetscReal);
PETSC_EXTERN PetscErrorCode VecTaggerCDFIterativeGetTolerances(VecTagger, PetscInt *, PetscReal *, PetscReal *);
PETSC_EXTERN PetscErrorCode VecTaggerOrSetSubs(VecTagger, PetscInt, VecTagger *, PetscCopyMode);
PETSC_EXTERN PetscErrorCode VecTaggerOrGetSubs(VecTagger, PetscInt *, VecTagger **);
PETSC_EXTERN PetscErrorCode VecTaggerAndSetSubs(VecTagger, PetscInt, VecTagger *, PetscCopyMode);
PETSC_EXTERN PetscErrorCode VecTaggerAndGetSubs(VecTagger, PetscInt *, VecTagger **);
PETSC_EXTERN PetscErrorCode VecTaggerInitializePackage(void);
PETSC_EXTERN PetscErrorCode VecTaggerFinalizePackage(void);
#if PetscDefined(USE_DEBUG)
/* This is an internal debug-only routine that should not be used by users */
PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode VecValidValues_Internal(Vec, PetscInt, PetscBool);
#else
#define VecValidValues_Internal(...) PETSC_SUCCESS
#endif /* PETSC_USE_DEBUG */
#define VEC_CUPM_NOT_CONFIGURED(impl) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP_SYS, "Must configure PETSc with " PetscStringize(impl) " support to use %s", PETSC_FUNCTION_NAME)
#if PetscDefined(HAVE_CUDA)
#define VEC_CUDA_DECL_OR_STUB(__decl__, ...) PETSC_EXTERN __decl__;
#else
#define VEC_CUDA_DECL_OR_STUB(__decl__, ...) \
static inline __decl__ \
{ \
__VA_ARGS__; \
VEC_CUPM_NOT_CONFIGURED(cuda); \
}
#endif /* PETSC_HAVE_CUDA */
/* extra underscore here to make it line up with the cuda versions */
#if PetscDefined(HAVE_HIP)
#define VEC_HIP__DECL_OR_STUB(__decl__, ...) PETSC_EXTERN __decl__;
#else
#define VEC_HIP__DECL_OR_STUB(__decl__, ...) \
static inline __decl__ \
{ \
__VA_ARGS__; \
VEC_CUPM_NOT_CONFIGURED(hip); \
}
#endif /* PETSC_HAVE_HIP */
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCreateSeqCUDA(MPI_Comm a, PetscInt b, Vec *c), (void)a, (void)b, (void)c)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecCreateSeqHIP(MPI_Comm a, PetscInt b, Vec *c), (void)a, (void)b, (void)c)
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCreateSeqCUDAWithArray(MPI_Comm a, PetscInt b, PetscInt c, const PetscScalar *d, Vec *e), (void)a, (void)b, (void)c, (void)d, (void)e)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecCreateSeqHIPWithArray(MPI_Comm a, PetscInt b, PetscInt c, const PetscScalar *d, Vec *e), (void)a, (void)b, (void)c, (void)d, (void)e)
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCreateSeqCUDAWithArrays(MPI_Comm a, PetscInt b, PetscInt c, const PetscScalar *d, const PetscScalar *e, Vec *f), (void)a, (void)b, (void)c, (void)d, (void)e, (void)f)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecCreateSeqHIPWithArrays(MPI_Comm a, PetscInt b, PetscInt c, const PetscScalar *d, const PetscScalar *e, Vec *f), (void)a, (void)b, (void)c, (void)d, (void)e, (void)f)
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCreateMPICUDA(MPI_Comm a, PetscInt b, PetscInt c, Vec *d), (void)a, (void)b, (void)c, (void)d)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecCreateMPIHIP(MPI_Comm a, PetscInt b, PetscInt c, Vec *d), (void)a, (void)b, (void)c, (void)d)
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCreateMPICUDAWithArray(MPI_Comm a, PetscInt b, PetscInt c, PetscInt d, const PetscScalar *e, Vec *f), (void)a, (void)b, (void)c, (void)d, (void)e, (void)f)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecCreateMPIHIPWithArray(MPI_Comm a, PetscInt b, PetscInt c, PetscInt d, const PetscScalar *e, Vec *f), (void)a, (void)b, (void)c, (void)d, (void)e, (void)f)
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCreateMPICUDAWithArrays(MPI_Comm a, PetscInt b, PetscInt c, PetscInt d, const PetscScalar *e, const PetscScalar *f, Vec *g), (void)a, (void)b, (void)c, (void)d, (void)e, (void)f, (void)g)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecCreateMPIHIPWithArrays(MPI_Comm a, PetscInt b, PetscInt c, PetscInt d, const PetscScalar *e, const PetscScalar *f, Vec *g), (void)a, (void)b, (void)c, (void)d, (void)e, (void)f, (void)g)
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDAGetArray(Vec a, PetscScalar **b), (void)a, (void)b)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPGetArray(Vec a, PetscScalar **b), (void)a, (void)b)
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDARestoreArray(Vec a, PetscScalar **b), (void)a, (void)b)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPRestoreArray(Vec a, PetscScalar **b), (void)a, (void)b)
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDAGetArrayRead(Vec a, const PetscScalar **b), (void)a, (void)b)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPGetArrayRead(Vec a, const PetscScalar **b), (void)a, (void)b)
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDARestoreArrayRead(Vec a, const PetscScalar **b), (void)a, (void)b)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPRestoreArrayRead(Vec a, const PetscScalar **b), (void)a, (void)b)
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDAGetArrayWrite(Vec a, PetscScalar **b), (void)a, (void)b)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPGetArrayWrite(Vec a, PetscScalar **b), (void)a, (void)b)
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDARestoreArrayWrite(Vec a, PetscScalar **b), (void)a, (void)b)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPRestoreArrayWrite(Vec a, PetscScalar **b), (void)a, (void)b)
VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDAPlaceArray(Vec a, const PetscScalar b[]), (void)a, (void)b)
VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPPlaceArray(Vec a, const PetscScalar b[]), (void)a, (void)b)