Actual source code: vector.c
1: #define PETSCVEC_DLL
3: /*
4: Provides the interface functions for vector operations that do NOT have PetscScalar/PetscReal in the signature
5: These are the vector functions the user calls.
6: */
7: #include private/vecimpl.h
9: /* Logging support */
10: PetscCookie VEC_COOKIE = 0;
11: PetscEvent VEC_View = 0, VEC_Max = 0, VEC_Min = 0, VEC_DotBarrier = 0, VEC_Dot = 0, VEC_MDotBarrier = 0, VEC_MDot = 0, VEC_TDot = 0;
12: PetscEvent VEC_Norm = 0, VEC_Normalize = 0, VEC_Scale = 0, VEC_Copy = 0, VEC_Set = 0, VEC_AXPY = 0, VEC_AYPX = 0, VEC_WAXPY = 0;
13: PetscEvent VEC_MTDot = 0, VEC_NormBarrier = 0, VEC_MAXPY = 0, VEC_Swap = 0, VEC_AssemblyBegin = 0, VEC_ScatterBegin = 0, VEC_ScatterEnd = 0;
14: PetscEvent VEC_AssemblyEnd = 0, VEC_PointwiseMult = 0, VEC_SetValues = 0, VEC_Load = 0, VEC_ScatterBarrier = 0;
15: PetscEvent VEC_SetRandom = 0, VEC_ReduceArithmetic = 0, VEC_ReduceBarrier = 0, VEC_ReduceCommunication = 0;
16: PetscEvent VEC_DotNormBarrier = 0, VEC_DotNorm = 0;
18: EXTERN PetscErrorCode VecStashGetInfo_Private(VecStash*,PetscInt*,PetscInt*);
21: /*@
22: VecStashGetInfo - Gets how many values are currently in the vector stash, i.e. need
23: to be communicated to other processors during the VecAssemblyBegin/End() process
25: Not collective
27: Input Parameter:
28: . vec - the vector
30: Output Parameters:
31: + nstash - the size of the stash
32: . reallocs - the number of additional mallocs incurred.
33: . bnstash - the size of the block stash
34: - breallocs - the number of additional mallocs incurred.in the block stash
35:
36: Level: advanced
38: .seealso: VecAssemblyBegin(), VecAssemblyEnd(), Vec, VecStashSetInitialSize(), VecStashView()
39:
40: @*/
41: PetscErrorCode VecStashGetInfo(Vec vec,PetscInt *nstash,PetscInt *reallocs,PetscInt *bnstash,PetscInt *breallocs)
42: {
45: VecStashGetInfo_Private(&vec->stash,nstash,reallocs);
46: VecStashGetInfo_Private(&vec->bstash,bnstash,breallocs);
47: return(0);
48: }
52: /*@
53: VecSetLocalToGlobalMapping - Sets a local numbering to global numbering used
54: by the routine VecSetValuesLocal() to allow users to insert vector entries
55: using a local (per-processor) numbering.
57: Collective on Vec
59: Input Parameters:
60: + x - vector
61: - mapping - mapping created with ISLocalToGlobalMappingCreate() or ISLocalToGlobalMappingCreateIS()
63: Notes:
64: All vectors obtained with VecDuplicate() from this vector inherit the same mapping.
66: Level: intermediate
68: Concepts: vector^setting values with local numbering
70: seealso: VecAssemblyBegin(), VecAssemblyEnd(), VecSetValues(), VecSetValuesLocal(),
71: VecSetLocalToGlobalMappingBlock(), VecSetValuesBlockedLocal()
72: @*/
73: PetscErrorCode VecSetLocalToGlobalMapping(Vec x,ISLocalToGlobalMapping mapping)
74: {
81: if (x->mapping) {
82: SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Mapping already set for vector");
83: }
85: if (x->ops->setlocaltoglobalmapping) {
86: (*x->ops->setlocaltoglobalmapping)(x,mapping);
87: } else {
88: PetscObjectReference((PetscObject)mapping);
89: if (x->mapping) { ISLocalToGlobalMappingDestroy(x->mapping); }
90: x->mapping = mapping;
91: }
92: return(0);
93: }
97: /*@
98: VecSetLocalToGlobalMappingBlock - Sets a local numbering to global numbering used
99: by the routine VecSetValuesBlockedLocal() to allow users to insert vector entries
100: using a local (per-processor) numbering.
102: Collective on Vec
104: Input Parameters:
105: + x - vector
106: - mapping - mapping created with ISLocalToGlobalMappingCreate() or ISLocalToGlobalMappingCreateIS()
108: Notes:
109: All vectors obtained with VecDuplicate() from this vector inherit the same mapping.
111: Level: intermediate
113: Concepts: vector^setting values blocked with local numbering
115: .seealso: VecAssemblyBegin(), VecAssemblyEnd(), VecSetValues(), VecSetValuesLocal(),
116: VecSetLocalToGlobalMapping(), VecSetValuesBlockedLocal()
117: @*/
118: PetscErrorCode VecSetLocalToGlobalMappingBlock(Vec x,ISLocalToGlobalMapping mapping)
119: {
126: if (x->bmapping) {
127: SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Mapping already set for vector");
128: }
129: PetscObjectReference((PetscObject)mapping);
130: if (x->bmapping) { ISLocalToGlobalMappingDestroy(x->bmapping); }
131: x->bmapping = mapping;
132: return(0);
133: }
137: /*@
138: VecAssemblyBegin - Begins assembling the vector. This routine should
139: be called after completing all calls to VecSetValues().
141: Collective on Vec
143: Input Parameter:
144: . vec - the vector
146: Level: beginner
148: Concepts: assembly^vectors
150: .seealso: VecAssemblyEnd(), VecSetValues()
151: @*/
152: PetscErrorCode VecAssemblyBegin(Vec vec)
153: {
155: PetscTruth flg;
161: PetscOptionsHasName(((PetscObject)vec)->prefix,"-vec_view_stash",&flg);
162: if (flg) {
163: PetscViewer viewer;
164: PetscViewerASCIIGetStdout(((PetscObject)vec)->comm,&viewer);
165: VecStashView(vec,viewer);
166: }
169: if (vec->ops->assemblybegin) {
170: (*vec->ops->assemblybegin)(vec);
171: }
173: PetscObjectStateIncrease((PetscObject)vec);
174: return(0);
175: }
179: /*
180: Processes command line options to determine if/how a matrix
181: is to be viewed. Called by VecAssemblyEnd().
183: .seealso: MatView_Private()
185: */
186: PetscErrorCode VecView_Private(Vec vec)
187: {
189: PetscTruth flg;
192: PetscOptionsBegin(((PetscObject)vec)->comm,((PetscObject)vec)->prefix,"Vector Options","Vec");
193: PetscOptionsName("-vec_view","Print vector to stdout","VecView",&flg);
194: if (flg) {
195: PetscViewer viewer;
196: PetscViewerASCIIGetStdout(((PetscObject)vec)->comm,&viewer);
197: VecView(vec,viewer);
198: }
199: PetscOptionsName("-vec_view_matlab","Print vector to stdout in a format Matlab can read","VecView",&flg);
200: if (flg) {
201: PetscViewer viewer;
202: PetscViewerASCIIGetStdout(((PetscObject)vec)->comm,&viewer);
203: PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_MATLAB);
204: VecView(vec,viewer);
205: PetscViewerPopFormat(viewer);
206: }
207: #if defined(PETSC_HAVE_MATLAB_ENGINE)
208: PetscOptionsName("-vec_view_matlab_file","Print vector to matlaboutput.mat format Matlab can read","VecView",&flg);
209: if (flg) {
210: VecView(vec,PETSC_VIEWER_MATLAB_(((PetscObject)vec)->comm));
211: }
212: #endif
213: #if defined(PETSC_USE_SOCKET_VIEWER)
214: PetscOptionsName("-vec_view_socket","Send vector to socket (can be read from matlab)","VecView",&flg);
215: if (flg) {
216: VecView(vec,PETSC_VIEWER_SOCKET_(((PetscObject)vec)->comm));
217: PetscViewerFlush(PETSC_VIEWER_SOCKET_(((PetscObject)vec)->comm));
218: }
219: #endif
220: PetscOptionsName("-vec_view_binary","Save vector to file in binary format","VecView",&flg);
221: if (flg) {
222: VecView(vec,PETSC_VIEWER_BINARY_(((PetscObject)vec)->comm));
223: PetscViewerFlush(PETSC_VIEWER_BINARY_(((PetscObject)vec)->comm));
224: }
225: PetscOptionsEnd();
226: /* These invoke PetscDrawGetDraw which invokes PetscOptionsBegin/End, */
227: /* hence they should not be inside the above PetscOptionsBegin/End block. */
228: PetscOptionsHasName(((PetscObject)vec)->prefix,"-vec_view_draw",&flg);
229: if (flg) {
230: VecView(vec,PETSC_VIEWER_DRAW_(((PetscObject)vec)->comm));
231: PetscViewerFlush(PETSC_VIEWER_DRAW_(((PetscObject)vec)->comm));
232: }
233: PetscOptionsHasName(((PetscObject)vec)->prefix,"-vec_view_draw_lg",&flg);
234: if (flg) {
235: PetscViewerSetFormat(PETSC_VIEWER_DRAW_(((PetscObject)vec)->comm),PETSC_VIEWER_DRAW_LG);
236: VecView(vec,PETSC_VIEWER_DRAW_(((PetscObject)vec)->comm));
237: PetscViewerFlush(PETSC_VIEWER_DRAW_(((PetscObject)vec)->comm));
238: }
239: return(0);
240: }
244: /*@
245: VecAssemblyEnd - Completes assembling the vector. This routine should
246: be called after VecAssemblyBegin().
248: Collective on Vec
250: Input Parameter:
251: . vec - the vector
253: Options Database Keys:
254: + -vec_view - Prints vector in ASCII format
255: . -vec_view_matlab - Prints vector in ASCII Matlab format to stdout
256: . -vec_view_matlab_file - Prints vector in Matlab format to matlaboutput.mat
257: . -vec_view_draw - Activates vector viewing using drawing tools
258: . -display <name> - Sets display name (default is host)
259: . -draw_pause <sec> - Sets number of seconds to pause after display
260: - -vec_view_socket - Activates vector viewing using a socket
261:
262: Level: beginner
264: .seealso: VecAssemblyBegin(), VecSetValues()
265: @*/
266: PetscErrorCode VecAssemblyEnd(Vec vec)
267: {
274: if (vec->ops->assemblyend) {
275: (*vec->ops->assemblyend)(vec);
276: }
278: VecView_Private(vec);
279: return(0);
280: }
284: /*@
285: VecPointwiseMax - Computes the componentwise maximum w_i = max(x_i, y_i).
287: Collective on Vec
289: Input Parameters:
290: . x, y - the vectors
292: Output Parameter:
293: . w - the result
295: Level: advanced
297: Notes: any subset of the x, y, and w may be the same vector.
298: For complex numbers compares only the real part
300: Concepts: vector^pointwise multiply
302: .seealso: VecPointwiseDivide(), VecPointwiseMult(), VecPointwiseMin(), VecPointwiseMaxAbs(), VecMaxPointwiseDivide()
303: @*/
304: PetscErrorCode VecPointwiseMax(Vec w,Vec x,Vec y)
305: {
317: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
318: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
320: (*w->ops->pointwisemax)(w,x,y);
321: PetscObjectStateIncrease((PetscObject)w);
322: return(0);
323: }
328: /*@
329: VecPointwiseMin - Computes the componentwise minimum w_i = min(x_i, y_i).
331: Collective on Vec
333: Input Parameters:
334: . x, y - the vectors
336: Output Parameter:
337: . w - the result
339: Level: advanced
341: Notes: any subset of the x, y, and w may be the same vector.
342: For complex numbers compares only the real part
344: Concepts: vector^pointwise multiply
346: .seealso: VecPointwiseDivide(), VecPointwiseMult(), VecPointwiseMin(), VecPointwiseMaxAbs(), VecMaxPointwiseDivide()
347: @*/
348: PetscErrorCode VecPointwiseMin(Vec w,Vec x,Vec y)
349: {
361: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
362: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
364: (*w->ops->pointwisemin)(w,x,y);
365: PetscObjectStateIncrease((PetscObject)w);
366: return(0);
367: }
371: /*@
372: VecPointwiseMaxAbs - Computes the componentwise maximum of the absolute values w_i = max(abs(x_i), abs(y_i)).
374: Collective on Vec
376: Input Parameters:
377: . x, y - the vectors
379: Output Parameter:
380: . w - the result
382: Level: advanced
384: Notes: any subset of the x, y, and w may be the same vector.
386: Concepts: vector^pointwise multiply
388: .seealso: VecPointwiseDivide(), VecPointwiseMult(), VecPointwiseMin(), VecPointwiseMax(), VecMaxPointwiseDivide()
389: @*/
390: PetscErrorCode VecPointwiseMaxAbs(Vec w,Vec x,Vec y)
391: {
403: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
404: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
406: (*w->ops->pointwisemaxabs)(w,x,y);
407: PetscObjectStateIncrease((PetscObject)w);
408: return(0);
409: }
413: /*@
414: VecPointwiseDivide - Computes the componentwise division w = x/y.
416: Collective on Vec
418: Input Parameters:
419: . x, y - the vectors
421: Output Parameter:
422: . w - the result
424: Level: advanced
426: Notes: any subset of the x, y, and w may be the same vector.
428: Concepts: vector^pointwise divide
430: .seealso: VecPointwiseMult(), VecPointwiseMax(), VecPointwiseMin(), VecPointwiseMaxAbs(), VecMaxPointwiseDivide()
431: @*/
432: PetscErrorCode VecPointwiseDivide(Vec w,Vec x,Vec y)
433: {
445: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
446: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
448: (*w->ops->pointwisedivide)(w,x,y);
449: PetscObjectStateIncrease((PetscObject)w);
450: return(0);
451: }
456: /*@
457: VecDuplicate - Creates a new vector of the same type as an existing vector.
459: Collective on Vec
461: Input Parameters:
462: . v - a vector to mimic
464: Output Parameter:
465: . newv - location to put new vector
467: Notes:
468: VecDuplicate() does not copy the vector, but rather allocates storage
469: for the new vector. Use VecCopy() to copy a vector.
471: Use VecDestroy() to free the space. Use VecDuplicateVecs() to get several
472: vectors.
474: Level: beginner
476: .seealso: VecDestroy(), VecDuplicateVecs(), VecCreate(), VecCopy()
477: @*/
478: PetscErrorCode VecDuplicate(Vec v,Vec *newv)
479: {
486: (*v->ops->duplicate)(v,newv);
487: PetscObjectStateIncrease((PetscObject)*newv);
488: return(0);
489: }
493: /*@
494: VecDestroy - Destroys a vector.
496: Collective on Vec
498: Input Parameters:
499: . v - the vector
501: Level: beginner
503: .seealso: VecDuplicate(), VecDestroyVecs()
504: @*/
505: PetscErrorCode VecDestroy(Vec v)
506: {
511: if (--((PetscObject)v)->refct > 0) return(0);
512: /* destroy the internal part */
513: if (v->ops->destroy) {
514: (*v->ops->destroy)(v);
515: }
516: /* destroy the external/common part */
517: if (v->mapping) {
518: ISLocalToGlobalMappingDestroy(v->mapping);
519: }
520: if (v->bmapping) {
521: ISLocalToGlobalMappingDestroy(v->bmapping);
522: }
523: PetscFree(v->map.range);
524: PetscHeaderDestroy(v);
525: return(0);
526: }
530: /*@C
531: VecDuplicateVecs - Creates several vectors of the same type as an existing vector.
533: Collective on Vec
535: Input Parameters:
536: + m - the number of vectors to obtain
537: - v - a vector to mimic
539: Output Parameter:
540: . V - location to put pointer to array of vectors
542: Notes:
543: Use VecDestroyVecs() to free the space. Use VecDuplicate() to form a single
544: vector.
546: Fortran Note:
547: The Fortran interface is slightly different from that given below, it
548: requires one to pass in V a Vec (integer) array of size at least m.
549: See the Fortran chapter of the users manual and petsc/src/vec/examples for details.
551: Level: intermediate
553: .seealso: VecDestroyVecs(), VecDuplicate(), VecCreate(), VecDuplicateVecsF90()
554: @*/
555: PetscErrorCode VecDuplicateVecs(Vec v,PetscInt m,Vec *V[])
556: {
563: (*v->ops->duplicatevecs)(v, m,V);
564: return(0);
565: }
569: /*@C
570: VecDestroyVecs - Frees a block of vectors obtained with VecDuplicateVecs().
572: Collective on Vec
574: Input Parameters:
575: + vv - pointer to array of vector pointers
576: - m - the number of vectors previously obtained
578: Fortran Note:
579: The Fortran interface is slightly different from that given below.
580: See the Fortran chapter of the users manual and
581: petsc/src/vec/examples for details.
583: Level: intermediate
585: .seealso: VecDuplicateVecs(), VecDestroyVecsf90()
586: @*/
587: PetscErrorCode VecDestroyVecs(Vec vv[],PetscInt m)
588: {
595: (*(*vv)->ops->destroyvecs)(vv,m);
596: return(0);
597: }
599: #undef __FUNCT__
601: /*@
602: VecViewFromOptions - This function visualizes the vector based upon user options.
604: Collective on Vec
606: Input Parameters:
607: . vec - The vector
608: . title - The title (currently ignored)
610: Level: intermediate
612: .keywords: Vec, view, options, database
613: .seealso: VecSetFromOptions(), VecView()
614: @*/
615: PetscErrorCode VecViewFromOptions(Vec vec, const char *title)
616: {
620: VecView_Private(vec);
621: return(0);
622: }
626: /*@C
627: VecView - Views a vector object.
629: Collective on Vec
631: Input Parameters:
632: + vec - the vector
633: - viewer - an optional visualization context
635: Notes:
636: The available visualization contexts include
637: + PETSC_VIEWER_STDOUT_SELF - standard output (default)
638: - PETSC_VIEWER_STDOUT_WORLD - synchronized standard
639: output where only the first processor opens
640: the file. All other processors send their
641: data to the first processor to print.
643: You can change the format the vector is printed using the
644: option PetscViewerSetFormat().
646: The user can open alternative visualization contexts with
647: + PetscViewerASCIIOpen() - Outputs vector to a specified file
648: . PetscViewerBinaryOpen() - Outputs vector in binary to a
649: specified file; corresponding input uses VecLoad()
650: . PetscViewerDrawOpen() - Outputs vector to an X window display
651: - PetscViewerSocketOpen() - Outputs vector to Socket viewer
653: The user can call PetscViewerSetFormat() to specify the output
654: format of ASCII printed objects (when using PETSC_VIEWER_STDOUT_SELF,
655: PETSC_VIEWER_STDOUT_WORLD and PetscViewerASCIIOpen). Available formats include
656: + PETSC_VIEWER_ASCII_DEFAULT - default, prints vector contents
657: . PETSC_VIEWER_ASCII_MATLAB - prints vector contents in Matlab format
658: . PETSC_VIEWER_ASCII_INDEX - prints vector contents, including indices of vector elements
659: - PETSC_VIEWER_ASCII_COMMON - prints vector contents, using a
660: format common among all vector types
662: Level: beginner
664: Concepts: vector^printing
665: Concepts: vector^saving to disk
667: .seealso: PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscDrawLGCreate(),
668: PetscViewerSocketOpen(), PetscViewerBinaryOpen(), VecLoad(), PetscViewerCreate(),
669: PetscRealView(), PetscScalarView(), PetscIntView()
670: @*/
671: PetscErrorCode VecView(Vec vec,PetscViewer viewer)
672: {
673: PetscErrorCode ierr;
674: PetscViewerFormat format;
679: if (!viewer) {
680: PetscViewerASCIIGetStdout(((PetscObject)vec)->comm,&viewer);
681: }
684: if (vec->stash.n || vec->bstash.n) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call VecAssemblyBegin/End() before viewing this vector");
686: /*
687: Check if default viewer has been overridden, but user request it anyways
688: */
689: PetscViewerGetFormat(viewer,&format);
690: if (vec->ops->viewnative && format == PETSC_VIEWER_NATIVE) {
691: PetscViewerPopFormat(viewer);
692: (*vec->ops->viewnative)(vec,viewer);
693: PetscViewerPushFormat(viewer,PETSC_VIEWER_NATIVE);
694: } else {
695: (*vec->ops->view)(vec,viewer);
696: }
697: return(0);
698: }
702: /*@
703: VecGetSize - Returns the global number of elements of the vector.
705: Not Collective
707: Input Parameter:
708: . x - the vector
710: Output Parameters:
711: . size - the global length of the vector
713: Level: beginner
715: Concepts: vector^local size
717: .seealso: VecGetLocalSize()
718: @*/
719: PetscErrorCode VecGetSize(Vec x,PetscInt *size)
720: {
727: (*x->ops->getsize)(x,size);
728: return(0);
729: }
733: /*@
734: VecGetLocalSize - Returns the number of elements of the vector stored
735: in local memory. This routine may be implementation dependent, so use
736: with care.
738: Not Collective
740: Input Parameter:
741: . x - the vector
743: Output Parameter:
744: . size - the length of the local piece of the vector
746: Level: beginner
748: Concepts: vector^size
750: .seealso: VecGetSize()
751: @*/
752: PetscErrorCode VecGetLocalSize(Vec x,PetscInt *size)
753: {
760: (*x->ops->getlocalsize)(x,size);
761: return(0);
762: }
766: /*@C
767: VecGetOwnershipRange - Returns the range of indices owned by
768: this processor, assuming that the vectors are laid out with the
769: first n1 elements on the first processor, next n2 elements on the
770: second, etc. For certain parallel layouts this range may not be
771: well defined.
773: Not Collective
775: Input Parameter:
776: . x - the vector
778: Output Parameters:
779: + low - the first local element, pass in PETSC_NULL if not interested
780: - high - one more than the last local element, pass in PETSC_NULL if not interested
782: Note:
783: The high argument is one more than the last element stored locally.
785: Fortran: PETSC_NULL_INTEGER should be used instead of PETSC_NULL
787: Level: beginner
789: Concepts: ownership^of vectors
790: Concepts: vector^ownership of elements
792: @*/
793: PetscErrorCode VecGetOwnershipRange(Vec x,PetscInt *low,PetscInt *high)
794: {
800: if (low) *low = x->map.rstart;
801: if (high) *high = x->map.rend;
802: return(0);
803: }
807: /*@
808: VecSetOption - Sets an option for controling a vector's behavior.
810: Collective on Vec
812: Input Parameter:
813: + x - the vector
814: . op - the option
815: - flag - turn the option on or off
817: Supported Options:
818: + VEC_IGNORE_OFF_PROC_ENTRIES, which causes VecSetValues() to ignore
819: entries destined to be stored on a separate processor. This can be used
820: to eliminate the global reduction in the VecAssemblyXXXX() if you know
821: that you have only used VecSetValues() to set local elements
822: . VEC_IGNORE_NEGATIVE_INDICES, which means you can pass negative indices
823: in ix in calls to VecSetValues or VecGetValues. These rows are simply
824: ignored.
826: Level: intermediate
828: @*/
829: PetscErrorCode VecSetOption(Vec x,VecOption op,PetscTruth flag)
830: {
836: if (x->ops->setoption) {
837: (*x->ops->setoption)(x,op,flag);
838: }
839: return(0);
840: }
844: /* Default routines for obtaining and releasing; */
845: /* may be used by any implementation */
846: PetscErrorCode VecDuplicateVecs_Default(Vec w,PetscInt m,Vec *V[])
847: {
849: PetscInt i;
854: if (m <= 0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"m must be > 0: m = %D",m);
855: PetscMalloc(m*sizeof(Vec*),V);
856: for (i=0; i<m; i++) {VecDuplicate(w,*V+i);}
857: return(0);
858: }
862: PetscErrorCode VecDestroyVecs_Default(Vec v[], PetscInt m)
863: {
865: PetscInt i;
869: if (m <= 0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"m must be > 0: m = %D",m);
870: for (i=0; i<m; i++) {VecDestroy(v[i]);}
871: PetscFree(v);
872: return(0);
873: }
877: /*@
878: VecResetArray - Resets a vector to use its default memory. Call this
879: after the use of VecPlaceArray().
881: Not Collective
883: Input Parameters:
884: . vec - the vector
886: Level: developer
888: .seealso: VecGetArray(), VecRestoreArray(), VecReplaceArray(), VecPlaceArray()
890: @*/
891: PetscErrorCode VecResetArray(Vec vec)
892: {
898: if (vec->ops->resetarray) {
899: (*vec->ops->resetarray)(vec);
900: } else {
901: SETERRQ(PETSC_ERR_SUP,"Cannot reset array in this type of vector");
902: }
903: PetscObjectStateIncrease((PetscObject)vec);
904: return(0);
905: }
909: /*@C
910: VecLoadIntoVector - Loads a vector that has been stored in binary format
911: with VecView().
913: Collective on PetscViewer
915: Input Parameters:
916: + viewer - binary file viewer, obtained from PetscViewerBinaryOpen()
917: - vec - vector to contain files values (must be of correct length)
919: Level: intermediate
921: Notes:
922: The input file must contain the full global vector, as
923: written by the routine VecView().
925: Use VecLoad() to create the vector as the values are read in
927: Notes for advanced users:
928: Most users should not need to know the details of the binary storage
929: format, since VecLoad() and VecView() completely hide these details.
930: But for anyone who's interested, the standard binary matrix storage
931: format is
932: .vb
933: int VEC_FILE_COOKIE
934: int number of rows
935: PetscScalar *values of all nonzeros
936: .ve
938: Note for Cray users, the int's stored in the binary file are 32 bit
939: integers; not 64 as they are represented in the memory, so if you
940: write your own routines to read/write these binary files from the Cray
941: you need to adjust the integer sizes that you read in, see
942: PetscBinaryRead() and PetscBinaryWrite() to see how this may be
943: done.
945: In addition, PETSc automatically does the byte swapping for
946: machines that store the bytes reversed, e.g. DEC alpha, freebsd,
947: linux, Windows and the paragon; thus if you write your own binary
948: read/write routines you have to swap the bytes; see PetscBinaryRead()
949: and PetscBinaryWrite() to see how this may be done.
951: Concepts: vector^loading from file
953: .seealso: PetscViewerBinaryOpen(), VecView(), MatLoad(), VecLoad()
954: @*/
955: PetscErrorCode VecLoadIntoVector(PetscViewer viewer,Vec vec)
956: {
963: if (!vec->ops->loadintovector) {
964: SETERRQ(PETSC_ERR_SUP,"Vector does not support load");
965: }
966: (*vec->ops->loadintovector)(viewer,vec);
967: PetscObjectStateIncrease((PetscObject)vec);
968: return(0);
969: }
973: /*@
974: VecReciprocal - Replaces each component of a vector by its reciprocal.
976: Collective on Vec
978: Input Parameter:
979: . vec - the vector
981: Output Parameter:
982: . vec - the vector reciprocal
984: Level: intermediate
986: Concepts: vector^reciprocal
988: @*/
989: PetscErrorCode VecReciprocal(Vec vec)
990: {
996: if (vec->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
997: if (!vec->ops->reciprocal) {
998: SETERRQ(PETSC_ERR_SUP,"Vector does not support reciprocal operation");
999: }
1000: (*vec->ops->reciprocal)(vec);
1001: PetscObjectStateIncrease((PetscObject)vec);
1002: return(0);
1003: }
1007: PetscErrorCode VecSetOperation(Vec vec,VecOperation op, void (*f)(void))
1008: {
1011: /* save the native version of the viewer */
1012: if (op == VECOP_VIEW && !vec->ops->viewnative) {
1013: vec->ops->viewnative = vec->ops->view;
1014: }
1015: (((void(**)(void))vec->ops)[(int)op]) = f;
1016: return(0);
1017: }
1022: /*@
1023: VecStashSetInitialSize - sets the sizes of the vec-stash, that is
1024: used during the assembly process to store values that belong to
1025: other processors.
1027: Collective on Vec
1029: Input Parameters:
1030: + vec - the vector
1031: . size - the initial size of the stash.
1032: - bsize - the initial size of the block-stash(if used).
1034: Options Database Keys:
1035: + -vecstash_initial_size <size> or <size0,size1,...sizep-1>
1036: - -vecstash_block_initial_size <bsize> or <bsize0,bsize1,...bsizep-1>
1038: Level: intermediate
1040: Notes:
1041: The block-stash is used for values set with VecSetValuesBlocked() while
1042: the stash is used for values set with VecSetValues()
1044: Run with the option -info and look for output of the form
1045: VecAssemblyBegin_MPIXXX:Stash has MM entries, uses nn mallocs.
1046: to determine the appropriate value, MM, to use for size and
1047: VecAssemblyBegin_MPIXXX:Block-Stash has BMM entries, uses nn mallocs.
1048: to determine the value, BMM to use for bsize
1050: Concepts: vector^stash
1051: Concepts: stash^vector
1053: .seealso: VecSetBlockSize(), VecSetValues(), VecSetValuesBlocked(), VecStashView()
1055: @*/
1056: PetscErrorCode VecStashSetInitialSize(Vec vec,PetscInt size,PetscInt bsize)
1057: {
1062: VecStashSetInitialSize_Private(&vec->stash,size);
1063: VecStashSetInitialSize_Private(&vec->bstash,bsize);
1064: return(0);
1065: }
1069: /*@
1070: VecConjugate - Conjugates a vector.
1072: Collective on Vec
1074: Input Parameters:
1075: . x - the vector
1077: Level: intermediate
1079: Concepts: vector^conjugate
1081: @*/
1082: PetscErrorCode VecConjugate(Vec x)
1083: {
1084: #ifdef PETSC_USE_COMPLEX
1090: if (x->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1091: (*x->ops->conjugate)(x);
1092: /* we need to copy norms here */
1093: PetscObjectStateIncrease((PetscObject)x);
1094: return(0);
1095: #else
1096: return(0);
1097: #endif
1098: }
1102: /*@
1103: VecPointwiseMult - Computes the componentwise multiplication w = x*y.
1105: Collective on Vec
1107: Input Parameters:
1108: . x, y - the vectors
1110: Output Parameter:
1111: . w - the result
1113: Level: advanced
1115: Notes: any subset of the x, y, and w may be the same vector.
1117: Concepts: vector^pointwise multiply
1119: .seealso: VecPointwiseDivide(), VecPointwiseMax(), VecPointwiseMin(), VecPointwiseMaxAbs(), VecMaxPointwiseDivide()
1120: @*/
1121: PetscErrorCode VecPointwiseMult(Vec w, Vec x,Vec y)
1122: {
1134: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
1135: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
1138: (*w->ops->pointwisemult)(w,x,y);
1140: PetscObjectStateIncrease((PetscObject)w);
1141: return(0);
1142: }
1146: /*@
1147: VecSetRandom - Sets all components of a vector to random numbers.
1149: Collective on Vec
1151: Input Parameters:
1152: + x - the vector
1153: - rctx - the random number context, formed by PetscRandomCreate(), or PETSC_NULL and
1154: it will create one internally.
1156: Output Parameter:
1157: . x - the vector
1159: Example of Usage:
1160: .vb
1161: PetscRandomCreate(PETSC_COMM_WORLD,&rctx);
1162: VecSetRandom(x,rctx);
1163: PetscRandomDestroy(rctx);
1164: .ve
1166: Level: intermediate
1168: Concepts: vector^setting to random
1169: Concepts: random^vector
1171: .seealso: VecSet(), VecSetValues(), PetscRandomCreate(), PetscRandomDestroy()
1172: @*/
1173: PetscErrorCode VecSetRandom(Vec x,PetscRandom rctx)
1174: {
1176: PetscRandom randObj = PETSC_NULL;
1182: if (x->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1184: if (!rctx) {
1185: MPI_Comm comm;
1186: PetscObjectGetComm((PetscObject)x,&comm);
1187: PetscRandomCreate(comm,&randObj);
1188: PetscRandomSetFromOptions(randObj);
1189: rctx = randObj;
1190: }
1193: (*x->ops->setrandom)(x,rctx);
1195:
1196: if (randObj) {
1197: PetscRandomDestroy(randObj);
1198: }
1199: PetscObjectStateIncrease((PetscObject)x);
1200: return(0);
1201: }
1203: /*@
1204: VecZeroEntries - puts a 0.0 in each element of a vector
1206: Collective on Vec
1208: Input Parameter:
1209: . vec - The vector
1211: Level: beginner
1213: .keywords: Vec, set, options, database
1214: .seealso: VecCreate(), VecSetOptionsPrefix(), VecSet(), VecSetValues()
1215: @*/
1216: PetscErrorCode VecZeroEntries (Vec vec)
1217: {
1220: VecSet(vec,0);
1221: return(0);
1222: }
1226: /*
1227: VecSetTypeFromOptions_Private - Sets the type of vector from user options. Defaults to a PETSc sequential vector on one
1228: processor and a PETSc MPI vector on more than one processor.
1230: Collective on Vec
1232: Input Parameter:
1233: . vec - The vector
1235: Level: intermediate
1237: .keywords: Vec, set, options, database, type
1238: .seealso: VecSetFromOptions(), VecSetType()
1239: */
1240: static PetscErrorCode VecSetTypeFromOptions_Private(Vec vec)
1241: {
1242: PetscTruth opt;
1243: const char *defaultType;
1244: char typeName[256];
1245: PetscMPIInt size;
1249: if (((PetscObject)vec)->type_name) {
1250: defaultType = ((PetscObject)vec)->type_name;
1251: } else {
1252: MPI_Comm_size(((PetscObject)vec)->comm, &size);
1253: if (size > 1) {
1254: defaultType = VECMPI;
1255: } else {
1256: defaultType = VECSEQ;
1257: }
1258: }
1260: if (!VecRegisterAllCalled) {
1261: VecRegisterAll(PETSC_NULL);
1262: }
1263: PetscOptionsList("-vec_type","Vector type","VecSetType",VecList,defaultType,typeName,256,&opt);
1264: if (opt) {
1265: VecSetType(vec, typeName);
1266: } else {
1267: VecSetType(vec, defaultType);
1268: }
1269: return(0);
1270: }
1274: /*@
1275: VecSetFromOptions - Configures the vector from the options database.
1277: Collective on Vec
1279: Input Parameter:
1280: . vec - The vector
1282: Notes: To see all options, run your program with the -help option, or consult the users manual.
1283: Must be called after VecCreate() but before the vector is used.
1285: Level: beginner
1287: Concepts: vectors^setting options
1288: Concepts: vectors^setting type
1290: .keywords: Vec, set, options, database
1291: .seealso: VecCreate(), VecSetOptionsPrefix()
1292: @*/
1293: PetscErrorCode VecSetFromOptions(Vec vec)
1294: {
1300: PetscOptionsBegin(((PetscObject)vec)->comm, ((PetscObject)vec)->prefix, "Vector options", "Vec");
1301: /* Handle vector type options */
1302: VecSetTypeFromOptions_Private(vec);
1304: /* Handle specific vector options */
1305: if (vec->ops->setfromoptions) {
1306: (*vec->ops->setfromoptions)(vec);
1307: }
1308: PetscOptionsEnd();
1310: VecViewFromOptions(vec, ((PetscObject)vec)->name);
1311: return(0);
1312: }
1316: /*@
1317: VecSetSizes - Sets the local and global sizes, and checks to determine compatibility
1319: Collective on Vec
1321: Input Parameters:
1322: + v - the vector
1323: . n - the local size (or PETSC_DECIDE to have it set)
1324: - N - the global size (or PETSC_DECIDE)
1326: Notes:
1327: n and N cannot be both PETSC_DECIDE
1328: If one processor calls this with N of PETSC_DECIDE then all processors must, otherwise the program will hang.
1330: Level: intermediate
1332: .seealso: VecGetSize(), PetscSplitOwnership()
1333: @*/
1334: PetscErrorCode VecSetSizes(Vec v, PetscInt n, PetscInt N)
1335: {
1338: if (N > 0 && n > N) SETERRQ2(PETSC_ERR_ARG_INCOMP,"Local size %D cannot be larger than global size %D",n,N);
1339: if ((v->map.n >= 0 || v->map.N >= 0) && (v->map.n != n || v->map.N != N)) SETERRQ4(PETSC_ERR_SUP,"Cannot change/reset vector sizes to %D local %D global after previously setting them to %D local %D global",n,N,v->map.n,v->map.N);
1340: v->map.n = n;
1341: v->map.N = N;
1342: return(0);
1343: }
1347: /*@
1348: VecSetBlockSize - Sets the blocksize for future calls to VecSetValuesBlocked()
1349: and VecSetValuesBlockedLocal().
1351: Collective on Vec
1353: Input Parameter:
1354: + v - the vector
1355: - bs - the blocksize
1357: Notes:
1358: All vectors obtained by VecDuplicate() inherit the same blocksize.
1360: Level: advanced
1362: .seealso: VecSetValuesBlocked(), VecSetLocalToGlobalMappingBlock(), VecGetBlockSize()
1364: Concepts: block size^vectors
1365: @*/
1366: PetscErrorCode VecSetBlockSize(Vec v,PetscInt bs)
1367: {
1370: if (bs <= 0) bs = 1;
1371: if (bs == v->map.bs) return(0);
1372: if (v->map.N != -1 && v->map.N % bs) SETERRQ2(PETSC_ERR_ARG_OUTOFRANGE,"Vector length not divisible by blocksize %D %D",v->map.N,bs);
1373: if (v->map.n != -1 && v->map.n % bs) SETERRQ2(PETSC_ERR_ARG_OUTOFRANGE,"Local vector length not divisible by blocksize %D %D\n\
1374: Try setting blocksize before setting the vector type",v->map.n,bs);
1375:
1376: v->map.bs = bs;
1377: v->bstash.bs = bs; /* use the same blocksize for the vec's block-stash */
1378: return(0);
1379: }
1383: /*@
1384: VecGetBlockSize - Gets the blocksize for the vector, i.e. what is used for VecSetValuesBlocked()
1385: and VecSetValuesBlockedLocal().
1387: Collective on Vec
1389: Input Parameter:
1390: . v - the vector
1392: Output Parameter:
1393: . bs - the blocksize
1395: Notes:
1396: All vectors obtained by VecDuplicate() inherit the same blocksize.
1398: Level: advanced
1400: .seealso: VecSetValuesBlocked(), VecSetLocalToGlobalMappingBlock(), VecSetBlockSize()
1402: Concepts: vector^block size
1403: Concepts: block^vector
1405: @*/
1406: PetscErrorCode VecGetBlockSize(Vec v,PetscInt *bs)
1407: {
1411: *bs = v->map.bs;
1412: return(0);
1413: }
1417: /*@
1418: VecValid - Checks whether a vector object is valid.
1420: Not Collective
1422: Input Parameter:
1423: . v - the object to check
1425: Output Parameter:
1426: . flg - flag indicating vector status, either
1427: PETSC_TRUE if vector is valid, or PETSC_FALSE otherwise.
1429: Level: developer
1431: @*/
1432: PetscErrorCode VecValid(Vec v,PetscTruth *flg)
1433: {
1436: if (!v) *flg = PETSC_FALSE;
1437: else if (((PetscObject)v)->cookie != VEC_COOKIE) *flg = PETSC_FALSE;
1438: else *flg = PETSC_TRUE;
1439: return(0);
1440: }
1444: /*@C
1445: VecSetOptionsPrefix - Sets the prefix used for searching for all
1446: Vec options in the database.
1448: Collective on Vec
1450: Input Parameter:
1451: + v - the Vec context
1452: - prefix - the prefix to prepend to all option names
1454: Notes:
1455: A hyphen (-) must NOT be given at the beginning of the prefix name.
1456: The first character of all runtime options is AUTOMATICALLY the hyphen.
1458: Level: advanced
1460: .keywords: Vec, set, options, prefix, database
1462: .seealso: VecSetFromOptions()
1463: @*/
1464: PetscErrorCode VecSetOptionsPrefix(Vec v,const char prefix[])
1465: {
1470: PetscObjectSetOptionsPrefix((PetscObject)v,prefix);
1471: return(0);
1472: }
1476: /*@C
1477: VecAppendOptionsPrefix - Appends to the prefix used for searching for all
1478: Vec options in the database.
1480: Collective on Vec
1482: Input Parameters:
1483: + v - the Vec context
1484: - prefix - the prefix to prepend to all option names
1486: Notes:
1487: A hyphen (-) must NOT be given at the beginning of the prefix name.
1488: The first character of all runtime options is AUTOMATICALLY the hyphen.
1490: Level: advanced
1492: .keywords: Vec, append, options, prefix, database
1494: .seealso: VecGetOptionsPrefix()
1495: @*/
1496: PetscErrorCode VecAppendOptionsPrefix(Vec v,const char prefix[])
1497: {
1499:
1502: PetscObjectAppendOptionsPrefix((PetscObject)v,prefix);
1503: return(0);
1504: }
1508: /*@C
1509: VecGetOptionsPrefix - Sets the prefix used for searching for all
1510: Vec options in the database.
1512: Not Collective
1514: Input Parameter:
1515: . v - the Vec context
1517: Output Parameter:
1518: . prefix - pointer to the prefix string used
1520: Notes: On the fortran side, the user should pass in a string 'prefix' of
1521: sufficient length to hold the prefix.
1523: Level: advanced
1525: .keywords: Vec, get, options, prefix, database
1527: .seealso: VecAppendOptionsPrefix()
1528: @*/
1529: PetscErrorCode VecGetOptionsPrefix(Vec v,const char *prefix[])
1530: {
1535: PetscObjectGetOptionsPrefix((PetscObject)v,prefix);
1536: return(0);
1537: }
1541: /*@
1542: VecSetUp - Sets up the internal vector data structures for the later use.
1544: Collective on Vec
1546: Input Parameters:
1547: . v - the Vec context
1549: Notes:
1550: For basic use of the Vec classes the user need not explicitly call
1551: VecSetUp(), since these actions will happen automatically.
1553: Level: advanced
1555: .keywords: Vec, setup
1557: .seealso: VecCreate(), VecDestroy()
1558: @*/
1559: PetscErrorCode VecSetUp(Vec v)
1560: {
1561: PetscMPIInt size;
1566: if (!((PetscObject)v)->type_name) {
1567: MPI_Comm_size(((PetscObject)v)->comm, &size);
1568: if (size == 1) {
1569: VecSetType(v, VECSEQ);
1570: } else {
1571: VecSetType(v, VECMPI);
1572: }
1573: }
1574: return(0);
1575: }
1577: /*
1578: These currently expose the PetscScalar/PetscReal in updating the
1579: cached norm. If we push those down into the implementation these
1580: will become independent of PetscScalar/PetscReal
1581: */
1585: /*@
1586: VecCopy - Copies a vector.
1588: Collective on Vec
1590: Input Parameter:
1591: . x - the vector
1593: Output Parameter:
1594: . y - the copy
1596: Notes:
1597: For default parallel PETSc vectors, both x and y must be distributed in
1598: the same manner; local copies are done.
1600: Level: beginner
1602: .seealso: VecDuplicate()
1603: @*/
1604: PetscErrorCode VecCopy(Vec x,Vec y)
1605: {
1606: PetscTruth flgs[4];
1607: PetscReal norms[4] = {0.0,0.0,0.0,0.0};
1609: PetscInt i;
1617: if (x == y) return(0);
1618: if (x->map.N != y->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
1619: if (x->map.n != y->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
1622: (*x->ops->copy)(x,y);
1625: /*
1626: * Update cached data
1627: */
1628: /* in general we consider this object touched */
1629: PetscObjectStateIncrease((PetscObject)y);
1631: for (i=0; i<4; i++) {
1632: PetscObjectComposedDataGetReal((PetscObject)x,NormIds[i],norms[i],flgs[i]);
1633: }
1634: for (i=0; i<4; i++) {
1635: if (flgs[i]) {
1636: PetscObjectComposedDataSetReal((PetscObject)y,NormIds[i],norms[i]);
1637: }
1638: }
1641: return(0);
1642: }
1646: /*@
1647: VecSwap - Swaps the vectors x and y.
1649: Collective on Vec
1651: Input Parameters:
1652: . x, y - the vectors
1654: Level: advanced
1656: Concepts: vector^swapping values
1658: @*/
1659: PetscErrorCode VecSwap(Vec x,Vec y)
1660: {
1661: PetscReal normxs[4]={0.0,0.0,0.0,0.0},normys[4]={0.0,0.0,0.0,0.0};
1662: PetscTruth flgxs[4],flgys[4];
1664: PetscInt i;
1672: if (x->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1673: if (y->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1674: if (x->map.N != y->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
1675: if (x->map.n != y->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
1678: (*x->ops->swap)(x,y);
1680: /* See if we have cached norms */
1681: for (i=0; i<4; i++) {
1682: PetscObjectComposedDataGetReal((PetscObject)x,NormIds[i],normxs[i],flgxs[i]);
1683: PetscObjectComposedDataGetReal((PetscObject)y,NormIds[i],normys[i],flgys[i]);
1684: }
1685: for (i=0; i<4; i++) {
1686: if (flgxs[i]) {
1687: PetscObjectComposedDataSetReal((PetscObject)y,NormIds[i],normxs[i]);
1688: }
1689: if (flgys[i]) {
1690: PetscObjectComposedDataSetReal((PetscObject)x,NormIds[i],normys[i]);
1691: }
1692: }
1694: return(0);
1695: }
1699: /*@
1700: VecStashView - Prints the entries in the vector stash and block stash.
1702: Collective on Vec
1704: Input Parameters:
1705: + v - the vector
1706: - viewer - the viewer
1708: Level: advanced
1710: Concepts: vector^stash
1711: Concepts: stash^vector
1713: .seealso: VecSetBlockSize(), VecSetValues(), VecSetValuesBlocked()
1715: @*/
1716: PetscErrorCode VecStashView(Vec v,PetscViewer viewer)
1717: {
1719: PetscMPIInt rank;
1720: PetscInt i,j;
1721: PetscTruth match;
1722: VecStash *s;
1723: PetscScalar val;
1730: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&match);
1731: if (!match) SETERRQ1(PETSC_ERR_SUP,"Stash viewer only works with ASCII viewer not %s\n",((PetscObject)v)->type_name);
1732: PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);
1733: MPI_Comm_rank(((PetscObject)v)->comm,&rank);
1734: s = &v->bstash;
1736: /* print block stash */
1737: PetscViewerASCIISynchronizedPrintf(viewer,"[%d]Vector Block stash size %D block size %D\n",rank,s->n,s->bs);
1738: for (i=0; i<s->n; i++) {
1739: PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Element %D ",rank,s->idx[i]);
1740: for (j=0; j<s->bs; j++) {
1741: val = s->array[i*s->bs+j];
1742: #if defined(PETSC_USE_COMPLEX)
1743: PetscViewerASCIISynchronizedPrintf(viewer,"(%18.16e %18.16e) ",PetscRealPart(val),PetscImaginaryPart(val));
1744: #else
1745: PetscViewerASCIISynchronizedPrintf(viewer,"%18.16e ",val);
1746: #endif
1747: }
1748: PetscViewerASCIISynchronizedPrintf(viewer,"\n");
1749: }
1750: PetscViewerFlush(viewer);
1752: s = &v->stash;
1754: /* print basic stash */
1755: PetscViewerASCIISynchronizedPrintf(viewer,"[%d]Vector stash size %D\n",rank,s->n);
1756: for (i=0; i<s->n; i++) {
1757: val = s->array[i];
1758: #if defined(PETSC_USE_COMPLEX)
1759: PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Element %D (%18.16e %18.16e) ",rank,s->idx[i],PetscRealPart(val),PetscImaginaryPart(val));
1760: #else
1761: PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Element %D %18.16e\n",rank,s->idx[i],val);
1762: #endif
1763: }
1764: PetscViewerFlush(viewer);
1766: PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);
1767: return(0);
1768: }