Actual source code: vecimpl.h
2: /*
3: This private file should not be included in users' code.
4: Defines the fields shared by all vector implementations.
6: */
8: #ifndef __VECIMPL_H
11: #include <petscvec.h>
12: #include <petsc/private/petscimpl.h>
14: PETSC_EXTERN PetscBool VecRegisterAllCalled;
15: PETSC_EXTERN PetscErrorCode VecRegisterAll(void);
16: PETSC_EXTERN MPI_Op MPIU_MAXLOC;
17: PETSC_EXTERN MPI_Op MPIU_MINLOC;
19: /* ----------------------------------------------------------------------------*/
21: typedef struct _VecOps *VecOps;
22: struct _VecOps {
23: PetscErrorCode (*duplicate)(Vec, Vec *); /* get single vector */
24: PetscErrorCode (*duplicatevecs)(Vec, PetscInt, Vec **); /* get array of vectors */
25: PetscErrorCode (*destroyvecs)(PetscInt, Vec[]); /* free array of vectors */
26: PetscErrorCode (*dot)(Vec, Vec, PetscScalar *); /* z = x^H * y */
27: PetscErrorCode (*mdot)(Vec, PetscInt, const Vec[], PetscScalar *); /* z[j] = x dot y[j] */
28: PetscErrorCode (*norm)(Vec, NormType, PetscReal *); /* z = sqrt(x^H * x) */
29: PetscErrorCode (*tdot)(Vec, Vec, PetscScalar *); /* x'*y */
30: PetscErrorCode (*mtdot)(Vec, PetscInt, const Vec[], PetscScalar *); /* z[j] = x dot y[j] */
31: PetscErrorCode (*scale)(Vec, PetscScalar); /* x = alpha * x */
32: PetscErrorCode (*copy)(Vec, Vec); /* y = x */
33: PetscErrorCode (*set)(Vec, PetscScalar); /* y = alpha */
34: PetscErrorCode (*swap)(Vec, Vec); /* exchange x and y */
35: PetscErrorCode (*axpy)(Vec, PetscScalar, Vec); /* y = y + alpha * x */
36: PetscErrorCode (*axpby)(Vec, PetscScalar, PetscScalar, Vec); /* y = alpha * x + beta * y*/
37: PetscErrorCode (*maxpy)(Vec, PetscInt, const PetscScalar *, Vec *); /* y = y + alpha[j] x[j] */
38: PetscErrorCode (*aypx)(Vec, PetscScalar, Vec); /* y = x + alpha * y */
39: PetscErrorCode (*waxpy)(Vec, PetscScalar, Vec, Vec); /* w = y + alpha * x */
40: PetscErrorCode (*axpbypcz)(Vec, PetscScalar, PetscScalar, PetscScalar, Vec, Vec); /* z = alpha * x + beta *y + gamma *z*/
41: PetscErrorCode (*pointwisemult)(Vec, Vec, Vec); /* w = x .* y */
42: PetscErrorCode (*pointwisedivide)(Vec, Vec, Vec); /* w = x ./ y */
43: PetscErrorCode (*setvalues)(Vec, PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
44: PetscErrorCode (*assemblybegin)(Vec); /* start global assembly */
45: PetscErrorCode (*assemblyend)(Vec); /* end global assembly */
46: PetscErrorCode (*getarray)(Vec, PetscScalar **); /* get data array */
47: PetscErrorCode (*getsize)(Vec, PetscInt *);
48: PetscErrorCode (*getlocalsize)(Vec, PetscInt *);
49: PetscErrorCode (*restorearray)(Vec, PetscScalar **); /* restore data array */
50: PetscErrorCode (*max)(Vec, PetscInt *, PetscReal *); /* z = max(x); idx=index of max(x) */
51: PetscErrorCode (*min)(Vec, PetscInt *, PetscReal *); /* z = min(x); idx=index of min(x) */
52: PetscErrorCode (*setrandom)(Vec, PetscRandom); /* set y[j] = random numbers */
53: PetscErrorCode (*setoption)(Vec, VecOption, PetscBool);
54: PetscErrorCode (*setvaluesblocked)(Vec, PetscInt, const PetscInt[], const PetscScalar[], InsertMode);
55: PetscErrorCode (*destroy)(Vec);
56: PetscErrorCode (*view)(Vec, PetscViewer);
57: PetscErrorCode (*placearray)(Vec, const PetscScalar *); /* place data array */
58: PetscErrorCode (*replacearray)(Vec, const PetscScalar *); /* replace data array */
59: PetscErrorCode (*dot_local)(Vec, Vec, PetscScalar *);
60: PetscErrorCode (*tdot_local)(Vec, Vec, PetscScalar *);
61: PetscErrorCode (*norm_local)(Vec, NormType, PetscReal *);
62: PetscErrorCode (*mdot_local)(Vec, PetscInt, const Vec[], PetscScalar *);
63: PetscErrorCode (*mtdot_local)(Vec, PetscInt, const Vec[], PetscScalar *);
64: PetscErrorCode (*load)(Vec, PetscViewer);
65: PetscErrorCode (*reciprocal)(Vec);
66: PetscErrorCode (*conjugate)(Vec);
67: PetscErrorCode (*setlocaltoglobalmapping)(Vec, ISLocalToGlobalMapping);
68: PetscErrorCode (*setvalueslocal)(Vec, PetscInt, const PetscInt *, const PetscScalar *, InsertMode);
69: PetscErrorCode (*resetarray)(Vec); /* vector points to its original array, i.e. undoes any VecPlaceArray() */
70: PetscErrorCode (*setfromoptions)(Vec, PetscOptionItems *);
71: PetscErrorCode (*maxpointwisedivide)(Vec, Vec, PetscReal *); /* m = max abs(x ./ y) */
72: PetscErrorCode (*pointwisemax)(Vec, Vec, Vec);
73: PetscErrorCode (*pointwisemaxabs)(Vec, Vec, Vec);
74: PetscErrorCode (*pointwisemin)(Vec, Vec, Vec);
75: PetscErrorCode (*getvalues)(Vec, PetscInt, const PetscInt[], PetscScalar[]);
76: PetscErrorCode (*sqrt)(Vec);
77: PetscErrorCode (*abs)(Vec);
78: PetscErrorCode (*exp)(Vec);
79: PetscErrorCode (*log)(Vec);
80: PetscErrorCode (*shift)(Vec, PetscScalar);
81: PetscErrorCode (*create)(Vec);
82: PetscErrorCode (*stridegather)(Vec, PetscInt, Vec, InsertMode);
83: PetscErrorCode (*stridescatter)(Vec, PetscInt, Vec, InsertMode);
84: PetscErrorCode (*dotnorm2)(Vec, Vec, PetscScalar *, PetscScalar *);
85: PetscErrorCode (*getsubvector)(Vec, IS, Vec *);
86: PetscErrorCode (*restoresubvector)(Vec, IS, Vec *);
87: PetscErrorCode (*getarrayread)(Vec, const PetscScalar **);
88: PetscErrorCode (*restorearrayread)(Vec, const PetscScalar **);
89: PetscErrorCode (*stridesubsetgather)(Vec, PetscInt, const PetscInt[], const PetscInt[], Vec, InsertMode);
90: PetscErrorCode (*stridesubsetscatter)(Vec, PetscInt, const PetscInt[], const PetscInt[], Vec, InsertMode);
91: PetscErrorCode (*viewnative)(Vec, PetscViewer);
92: PetscErrorCode (*loadnative)(Vec, PetscViewer);
93: PetscErrorCode (*createlocalvector)(Vec, Vec *);
94: PetscErrorCode (*getlocalvector)(Vec, Vec);
95: PetscErrorCode (*restorelocalvector)(Vec, Vec);
96: PetscErrorCode (*getlocalvectorread)(Vec, Vec);
97: PetscErrorCode (*restorelocalvectorread)(Vec, Vec);
98: PetscErrorCode (*bindtocpu)(Vec, PetscBool);
99: PetscErrorCode (*getarraywrite)(Vec, PetscScalar **);
100: PetscErrorCode (*restorearraywrite)(Vec, PetscScalar **);
101: PetscErrorCode (*getarrayandmemtype)(Vec, PetscScalar **, PetscMemType *);
102: PetscErrorCode (*restorearrayandmemtype)(Vec, PetscScalar **);
103: PetscErrorCode (*getarrayreadandmemtype)(Vec, const PetscScalar **, PetscMemType *);
104: PetscErrorCode (*restorearrayreadandmemtype)(Vec, const PetscScalar **);
105: PetscErrorCode (*getarraywriteandmemtype)(Vec, PetscScalar **, PetscMemType *);
106: PetscErrorCode (*restorearraywriteandmemtype)(Vec, PetscScalar **, PetscMemType *);
107: PetscErrorCode (*concatenate)(PetscInt, const Vec[], Vec *, IS *[]);
108: PetscErrorCode (*sum)(Vec, PetscScalar *);
109: PetscErrorCode (*setpreallocationcoo)(Vec, PetscCount, const PetscInt[]);
110: PetscErrorCode (*setvaluescoo)(Vec, const PetscScalar[], InsertMode);
111: };
113: #if defined(offsetof) && (defined(__cplusplus) || (PETSC_C_VERSION >= 11))
114: #if (PETSC_C_VERSION >= 11) && (PETSC_C_VERSION < 23)
115: // static_assert() is a keyword since C23, before that defined as macro in assert.h
116: #include <assert.h>
117: #endif
119: static_assert(offsetof(struct _VecOps, duplicate) == sizeof(void (*)(void)) * VECOP_DUPLICATE, "");
120: static_assert(offsetof(struct _VecOps, set) == sizeof(void (*)(void)) * VECOP_SET, "");
121: static_assert(offsetof(struct _VecOps, view) == sizeof(void (*)(void)) * VECOP_VIEW, "");
122: static_assert(offsetof(struct _VecOps, load) == sizeof(void (*)(void)) * VECOP_LOAD, "");
123: static_assert(offsetof(struct _VecOps, viewnative) == sizeof(void (*)(void)) * VECOP_VIEWNATIVE, "");
124: static_assert(offsetof(struct _VecOps, loadnative) == sizeof(void (*)(void)) * VECOP_LOADNATIVE, "");
125: #endif
127: /*
128: The stash is used to temporarily store inserted vec values that
129: belong to another processor. During the assembly phase the stashed
130: values are moved to the correct processor and
131: */
133: typedef struct {
134: PetscInt nmax; /* maximum stash size */
135: PetscInt umax; /* max stash size user wants */
136: PetscInt oldnmax; /* the nmax value used previously */
137: PetscInt n; /* stash size */
138: PetscInt bs; /* block size of the stash */
139: PetscInt reallocs; /* preserve the no of mallocs invoked */
140: PetscInt *idx; /* global row numbers in stash */
141: PetscScalar *array; /* array to hold stashed values */
142: /* The following variables are used for communication */
143: MPI_Comm comm;
144: PetscMPIInt size, rank;
145: PetscMPIInt tag1, tag2;
146: MPI_Request *send_waits; /* array of send requests */
147: MPI_Request *recv_waits; /* array of receive requests */
148: MPI_Status *send_status; /* array of send status */
149: PetscInt nsends, nrecvs; /* numbers of sends and receives */
150: PetscScalar *svalues, *rvalues; /* sending and receiving data */
151: PetscInt *sindices, *rindices;
152: PetscInt rmax; /* maximum message length */
153: PetscInt *nprocs; /* tmp data used both during scatterbegin and end */
154: PetscInt nprocessed; /* number of messages already processed */
155: PetscBool donotstash;
156: PetscBool ignorenegidx; /* ignore negative indices passed into VecSetValues/VetGetValues */
157: InsertMode insertmode;
158: PetscInt *bowners;
159: } VecStash;
161: struct _p_Vec {
162: PETSCHEADER(struct _VecOps);
163: PetscLayout map;
164: void *data; /* implementation-specific data */
165: PetscBool array_gotten;
166: VecStash stash, bstash; /* used for storing off-proc values during assembly */
167: PetscBool petscnative; /* means the ->data starts with VECHEADER and can use VecGetArrayFast()*/
168: #if PetscDefined(USE_DEBUG)
169: PetscStack lockstack; /* the file,func,line of where locks are added */
170: PetscInt lock; /* lock state. vector can be free (=0), locked for read (>0) or locked for write(<0) */
171: #endif
172: PetscOffloadMask offloadmask; /* a mask which indicates where the valid vector data is (GPU, CPU or both) */
173: #if defined(PETSC_HAVE_DEVICE)
174: void *spptr; /* this is the special pointer to the array on the GPU */
175: PetscBool boundtocpu;
176: PetscBool bindingpropagates;
177: size_t minimum_bytes_pinned_memory; /* minimum data size in bytes for which pinned memory will be allocated */
178: PetscBool pinned_memory; /* PETSC_TRUE if the current host allocation has been made from pinned memory. */
179: #endif
180: char *defaultrandtype;
181: };
183: PETSC_EXTERN PetscLogEvent VEC_SetRandom;
184: PETSC_EXTERN PetscLogEvent VEC_View;
185: PETSC_EXTERN PetscLogEvent VEC_Max;
186: PETSC_EXTERN PetscLogEvent VEC_Min;
187: PETSC_EXTERN PetscLogEvent VEC_Dot;
188: PETSC_EXTERN PetscLogEvent VEC_MDot;
189: PETSC_EXTERN PetscLogEvent VEC_TDot;
190: PETSC_EXTERN PetscLogEvent VEC_MTDot;
191: PETSC_EXTERN PetscLogEvent VEC_Norm;
192: PETSC_EXTERN PetscLogEvent VEC_Normalize;
193: PETSC_EXTERN PetscLogEvent VEC_Scale;
194: PETSC_EXTERN PetscLogEvent VEC_Copy;
195: PETSC_EXTERN PetscLogEvent VEC_Set;
196: PETSC_EXTERN PetscLogEvent VEC_AXPY;
197: PETSC_EXTERN PetscLogEvent VEC_AYPX;
198: PETSC_EXTERN PetscLogEvent VEC_WAXPY;
199: PETSC_EXTERN PetscLogEvent VEC_MAXPY;
200: PETSC_EXTERN PetscLogEvent VEC_AssemblyEnd;
201: PETSC_EXTERN PetscLogEvent VEC_PointwiseMult;
202: PETSC_EXTERN PetscLogEvent VEC_SetValues;
203: PETSC_EXTERN PetscLogEvent VEC_SetPreallocateCOO;
204: PETSC_EXTERN PetscLogEvent VEC_SetValuesCOO;
205: PETSC_EXTERN PetscLogEvent VEC_Load;
206: PETSC_EXTERN PetscLogEvent VEC_ScatterBegin;
207: PETSC_EXTERN PetscLogEvent VEC_ScatterEnd;
208: PETSC_EXTERN PetscLogEvent VEC_ReduceArithmetic;
209: PETSC_EXTERN PetscLogEvent VEC_ReduceCommunication;
210: PETSC_EXTERN PetscLogEvent VEC_ReduceBegin;
211: PETSC_EXTERN PetscLogEvent VEC_ReduceEnd;
212: PETSC_EXTERN PetscLogEvent VEC_Swap;
213: PETSC_EXTERN PetscLogEvent VEC_AssemblyBegin;
214: PETSC_EXTERN PetscLogEvent VEC_DotNorm2;
215: PETSC_EXTERN PetscLogEvent VEC_AXPBYPCZ;
216: PETSC_EXTERN PetscLogEvent VEC_Ops;
217: PETSC_EXTERN PetscLogEvent VEC_ViennaCLCopyToGPU;
218: PETSC_EXTERN PetscLogEvent VEC_ViennaCLCopyFromGPU;
219: PETSC_EXTERN PetscLogEvent VEC_CUDACopyToGPU;
220: PETSC_EXTERN PetscLogEvent VEC_CUDACopyFromGPU;
221: PETSC_EXTERN PetscLogEvent VEC_HIPCopyToGPU;
222: PETSC_EXTERN PetscLogEvent VEC_HIPCopyFromGPU;
224: PETSC_EXTERN PetscErrorCode VecView_Seq(Vec, PetscViewer);
225: #if defined(PETSC_HAVE_VIENNACL)
226: PETSC_EXTERN PetscErrorCode VecViennaCLAllocateCheckHost(Vec v);
227: PETSC_EXTERN PetscErrorCode VecViennaCLCopyFromGPU(Vec v);
228: #endif
230: /*
231: Common header shared by array based vectors,
232: currently Vec_Seq and Vec_MPI
233: */
234: #define VECHEADER \
235: PetscScalar *array; \
236: PetscScalar *array_allocated; /* if the array was allocated by PETSc this is its pointer */ \
237: PetscScalar *unplacedarray; /* if one called VecPlaceArray(), this is where it stashed the original */
239: /* Get Root type of vector. e.g. VECSEQ -> VECSTANDARD, VECMPICUDA -> VECCUDA */
240: PETSC_EXTERN PetscErrorCode VecGetRootType_Private(Vec, VecType *);
242: /* Default obtain and release vectors; can be used by any implementation */
243: PETSC_EXTERN PetscErrorCode VecDuplicateVecs_Default(Vec, PetscInt, Vec *[]);
244: PETSC_EXTERN PetscErrorCode VecDestroyVecs_Default(PetscInt, Vec[]);
245: PETSC_EXTERN PetscErrorCode VecView_Binary(Vec, PetscViewer);
246: PETSC_EXTERN PetscErrorCode VecLoad_Binary(Vec, PetscViewer);
247: PETSC_EXTERN PetscErrorCode VecLoad_Default(Vec, PetscViewer);
249: PETSC_EXTERN PetscInt NormIds[7]; /* map from NormType to IDs used to cache/retrieve values of norms */
251: PETSC_INTERN PetscErrorCode VecStashCreate_Private(MPI_Comm, PetscInt, VecStash *);
252: PETSC_INTERN PetscErrorCode VecStashDestroy_Private(VecStash *);
253: PETSC_EXTERN PetscErrorCode VecStashExpand_Private(VecStash *, PetscInt);
254: PETSC_INTERN PetscErrorCode VecStashScatterEnd_Private(VecStash *);
255: PETSC_INTERN PetscErrorCode VecStashSetInitialSize_Private(VecStash *, PetscInt);
256: PETSC_INTERN PetscErrorCode VecStashGetInfo_Private(VecStash *, PetscInt *, PetscInt *);
257: PETSC_INTERN PetscErrorCode VecStashScatterBegin_Private(VecStash *, PetscInt *);
258: PETSC_INTERN PetscErrorCode VecStashScatterGetMesg_Private(VecStash *, PetscMPIInt *, PetscInt **, PetscScalar **, PetscInt *);
259: PETSC_INTERN PetscErrorCode VecStashSortCompress_Private(VecStash *);
260: PETSC_INTERN PetscErrorCode VecStashGetOwnerList_Private(VecStash *, PetscLayout, PetscMPIInt *, PetscMPIInt **);
262: /*
263: VecStashValue_Private - inserts a single value into the stash.
265: Input Parameters:
266: stash - the stash
267: idx - the global of the inserted value
268: values - the value inserted
269: */
270: static inline PetscErrorCode VecStashValue_Private(VecStash *stash, PetscInt row, PetscScalar value)
271: {
272: /* Check and see if we have sufficient memory */
273: PetscFunctionBegin;
274: if (((stash)->n + 1) > (stash)->nmax) PetscCall(VecStashExpand_Private(stash, 1));
275: (stash)->idx[(stash)->n] = row;
276: (stash)->array[(stash)->n] = value;
277: (stash)->n++;
278: PetscFunctionReturn(PETSC_SUCCESS);
279: }
281: /*
282: VecStashValuesBlocked_Private - inserts 1 block of values into the stash.
284: Input Parameters:
285: stash - the stash
286: idx - the global block index
287: values - the values inserted
288: */
289: static inline PetscErrorCode VecStashValuesBlocked_Private(VecStash *stash, PetscInt row, PetscScalar *values)
290: {
291: PetscInt stash_bs = (stash)->bs;
292: PetscScalar *array;
294: PetscFunctionBegin;
295: if (((stash)->n + 1) > (stash)->nmax) PetscCall(VecStashExpand_Private(stash, 1));
296: array = (stash)->array + stash_bs * (stash)->n;
297: (stash)->idx[(stash)->n] = row;
298: PetscCall(PetscArraycpy(array, values, stash_bs));
299: (stash)->n++;
300: PetscFunctionReturn(PETSC_SUCCESS);
301: }
303: PETSC_INTERN PetscErrorCode VecStrideGather_Default(Vec, PetscInt, Vec, InsertMode);
304: PETSC_INTERN PetscErrorCode VecStrideScatter_Default(Vec, PetscInt, Vec, InsertMode);
305: PETSC_INTERN PetscErrorCode VecReciprocal_Default(Vec);
306: PETSC_INTERN PetscErrorCode VecStrideSubSetGather_Default(Vec, PetscInt, const PetscInt[], const PetscInt[], Vec, InsertMode);
307: PETSC_INTERN PetscErrorCode VecStrideSubSetScatter_Default(Vec, PetscInt, const PetscInt[], const PetscInt[], Vec, InsertMode);
309: #if defined(PETSC_HAVE_MATLAB)
310: PETSC_EXTERN PetscErrorCode VecMatlabEnginePut_Default(PetscObject, void *);
311: PETSC_EXTERN PetscErrorCode VecMatlabEngineGet_Default(PetscObject, void *);
312: #endif
314: PETSC_EXTERN PetscErrorCode PetscSectionGetField_Internal(PetscSection, PetscSection, Vec, PetscInt, PetscInt, PetscInt, IS *, Vec *);
315: PETSC_EXTERN PetscErrorCode PetscSectionRestoreField_Internal(PetscSection, PetscSection, Vec, PetscInt, PetscInt, PetscInt, IS *, Vec *);
317: #define VecCheckSameLocalSize(x, ar1, y, ar2) \
318: do { \
319: PetscCheck((x)->map->n == (y)->map->n, PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Incompatible vector local lengths parameter # %d local size %" PetscInt_FMT " != parameter # %d local size %" PetscInt_FMT, ar1, (x)->map->n, ar2, (y)->map->n); \
320: } while (0)
322: #define VecCheckSameSize(x, ar1, y, ar2) \
323: do { \
324: PetscCheck((x)->map->N == (y)->map->N, PetscObjectComm((PetscObject)x), PETSC_ERR_ARG_INCOMP, "Incompatible vector global lengths parameter # %d global size %" PetscInt_FMT " != parameter # %d global size %" PetscInt_FMT, ar1, (x)->map->N, ar2, \
325: (y)->map->N); \
326: VecCheckSameLocalSize(x, ar1, y, ar2); \
327: } while (0)
329: #define VecCheckLocalSize(x, ar1, n) \
330: do { \
331: PetscCheck((x)->map->n == (n), PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Incorrect vector local size: parameter # %d local size %" PetscInt_FMT " != %" PetscInt_FMT, ar1, (x)->map->n, n); \
332: } while (0)
334: #define VecCheckSize(x, ar1, n, N) \
335: do { \
336: PetscCheck((x)->map->N == (N), PetscObjectComm((PetscObject)x), PETSC_ERR_ARG_INCOMP, "Incorrect vector global size: parameter # %d global size %" PetscInt_FMT " != %" PetscInt_FMT, ar1, (x)->map->N, N); \
337: VecCheckLocalSize(x, ar1, n); \
338: } while (0)
340: typedef struct _VecTaggerOps *VecTaggerOps;
341: struct _VecTaggerOps {
342: PetscErrorCode (*create)(VecTagger);
343: PetscErrorCode (*destroy)(VecTagger);
344: PetscErrorCode (*setfromoptions)(VecTagger, PetscOptionItems *);
345: PetscErrorCode (*setup)(VecTagger);
346: PetscErrorCode (*view)(VecTagger, PetscViewer);
347: PetscErrorCode (*computeboxes)(VecTagger, Vec, PetscInt *, VecTaggerBox **, PetscBool *);
348: PetscErrorCode (*computeis)(VecTagger, Vec, IS *, PetscBool *);
349: };
350: struct _p_VecTagger {
351: PETSCHEADER(struct _VecTaggerOps);
352: void *data;
353: PetscInt blocksize;
354: PetscBool invert;
355: PetscBool setupcalled;
356: };
358: PETSC_EXTERN PetscBool VecTaggerRegisterAllCalled;
359: PETSC_EXTERN PetscErrorCode VecTaggerRegisterAll(void);
360: PETSC_EXTERN PetscErrorCode VecTaggerComputeIS_FromBoxes(VecTagger, Vec, IS *, PetscBool *);
361: PETSC_EXTERN PetscMPIInt Petsc_Reduction_keyval;
363: PETSC_INTERN PetscInt VecGetSubVectorSavedStateId;
364: PETSC_INTERN PetscErrorCode VecGetSubVectorContiguityAndBS_Private(Vec, IS, PetscBool *, PetscInt *, PetscInt *);
365: PETSC_INTERN PetscErrorCode VecGetSubVectorThroughVecScatter_Private(Vec, IS, PetscInt, Vec *);
367: #if PetscDefined(HAVE_CUDA)
368: PETSC_INTERN PetscErrorCode VecCreate_CUDA(Vec);
369: PETSC_INTERN PetscErrorCode VecCreate_SeqCUDA(Vec);
370: PETSC_INTERN PetscErrorCode VecCreate_MPICUDA(Vec);
371: PETSC_INTERN PetscErrorCode VecCUDAGetArrays_Private(Vec, const PetscScalar **, const PetscScalar **, PetscOffloadMask *);
372: #endif
374: #if PetscDefined(HAVE_HIP)
375: PETSC_INTERN PetscErrorCode VecCreate_HIP(Vec);
376: PETSC_INTERN PetscErrorCode VecCreate_SeqHIP(Vec);
377: PETSC_INTERN PetscErrorCode VecCreate_MPIHIP(Vec);
378: PETSC_INTERN PetscErrorCode VecHIPGetArrays_Private(Vec, const PetscScalar **, const PetscScalar **, PetscOffloadMask *);
379: #endif
381: #if defined(PETSC_HAVE_KOKKOS)
382: PETSC_INTERN PetscErrorCode VecCreateSeqKokkosWithArrays_Private(MPI_Comm, PetscInt, PetscInt, const PetscScalar *, const PetscScalar *, Vec *);
383: PETSC_INTERN PetscErrorCode VecCreateMPIKokkosWithArrays_Private(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscScalar *, const PetscScalar *, Vec *);
384: #endif
386: /* std::upper_bound(): Given a sorted array, return index of the first element in range [first,last) whose value
387: is greater than value, or last if there is no such element.
388: */
389: static inline PetscErrorCode PetscSortedIntUpperBound(PetscInt *array, PetscCount first, PetscCount last, PetscInt value, PetscCount *upper)
390: {
391: PetscCount it, step, count = last - first;
393: PetscFunctionBegin;
394: while (count > 0) {
395: it = first;
396: step = count / 2;
397: it += step;
398: if (!(value < array[it])) {
399: first = ++it;
400: count -= step + 1;
401: } else count = step;
402: }
403: *upper = first;
404: PetscFunctionReturn(PETSC_SUCCESS);
405: }
407: #endif /* __VECIMPL_H */