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;
17: EXTERN PetscErrorCode VecStashGetInfo_Private(VecStash*,PetscInt*,PetscInt*);
20: /*@
21: VecStashGetInfo - Gets how many values are currently in the vector stash, i.e. need
22: to be communicated to other processors during the VecAssemblyBegin/End() process
24: Not collective
26: Input Parameter:
27: . vec - the vector
29: Output Parameters:
30: + nstash - the size of the stash
31: . reallocs - the number of additional mallocs incurred.
32: . bnstash - the size of the block stash
33: - breallocs - the number of additional mallocs incurred.in the block stash
34:
35: Level: advanced
37: .seealso: VecAssemblyBegin(), VecAssemblyEnd(), Vec, VecStashSetInitialSize(), VecStashView()
38:
39: @*/
40: PetscErrorCode VecStashGetInfo(Vec vec,PetscInt *nstash,PetscInt *reallocs,PetscInt *bnstash,PetscInt *brealloc)
41: {
44: VecStashGetInfo_Private(&vec->stash,nstash,reallocs);
45: VecStashGetInfo_Private(&vec->bstash,nstash,reallocs);
46: return(0);
47: }
51: /*@
52: VecSetLocalToGlobalMapping - Sets a local numbering to global numbering used
53: by the routine VecSetValuesLocal() to allow users to insert vector entries
54: using a local (per-processor) numbering.
56: Collective on Vec
58: Input Parameters:
59: + x - vector
60: - mapping - mapping created with ISLocalToGlobalMappingCreate() or ISLocalToGlobalMappingCreateIS()
62: Notes:
63: All vectors obtained with VecDuplicate() from this vector inherit the same mapping.
65: Level: intermediate
67: Concepts: vector^setting values with local numbering
69: seealso: VecAssemblyBegin(), VecAssemblyEnd(), VecSetValues(), VecSetValuesLocal(),
70: VecSetLocalToGlobalMappingBlock(), VecSetValuesBlockedLocal()
71: @*/
72: PetscErrorCode VecSetLocalToGlobalMapping(Vec x,ISLocalToGlobalMapping mapping)
73: {
80: if (x->mapping) {
81: SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Mapping already set for vector");
82: }
84: if (x->ops->setlocaltoglobalmapping) {
85: (*x->ops->setlocaltoglobalmapping)(x,mapping);
86: } else {
87: x->mapping = mapping;
88: PetscObjectReference((PetscObject)mapping);
89: }
90: return(0);
91: }
95: /*@
96: VecSetLocalToGlobalMappingBlock - Sets a local numbering to global numbering used
97: by the routine VecSetValuesBlockedLocal() to allow users to insert vector entries
98: using a local (per-processor) numbering.
100: Collective on Vec
102: Input Parameters:
103: + x - vector
104: - mapping - mapping created with ISLocalToGlobalMappingCreate() or ISLocalToGlobalMappingCreateIS()
106: Notes:
107: All vectors obtained with VecDuplicate() from this vector inherit the same mapping.
109: Level: intermediate
111: Concepts: vector^setting values blocked with local numbering
113: .seealso: VecAssemblyBegin(), VecAssemblyEnd(), VecSetValues(), VecSetValuesLocal(),
114: VecSetLocalToGlobalMapping(), VecSetValuesBlockedLocal()
115: @*/
116: PetscErrorCode VecSetLocalToGlobalMappingBlock(Vec x,ISLocalToGlobalMapping mapping)
117: {
124: if (x->bmapping) {
125: SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Mapping already set for vector");
126: }
127: x->bmapping = mapping;
128: PetscObjectReference((PetscObject)mapping);
129: return(0);
130: }
134: /*@
135: VecAssemblyBegin - Begins assembling the vector. This routine should
136: be called after completing all calls to VecSetValues().
138: Collective on Vec
140: Input Parameter:
141: . vec - the vector
143: Level: beginner
145: Concepts: assembly^vectors
147: .seealso: VecAssemblyEnd(), VecSetValues()
148: @*/
149: PetscErrorCode VecAssemblyBegin(Vec vec)
150: {
152: PetscTruth flg;
158: PetscOptionsHasName(vec->prefix,"-vec_view_stash",&flg);
159: if (flg) {
160: VecStashView(vec,PETSC_VIEWER_STDOUT_(vec->comm));
161: }
164: if (vec->ops->assemblybegin) {
165: (*vec->ops->assemblybegin)(vec);
166: }
168: PetscObjectStateIncrease((PetscObject)vec);
169: return(0);
170: }
174: /*@
175: VecAssemblyEnd - Completes assembling the vector. This routine should
176: be called after VecAssemblyBegin().
178: Collective on Vec
180: Input Parameter:
181: . vec - the vector
183: Options Database Keys:
184: + -vec_view - Prints vector in ASCII format
185: . -vec_view_matlab - Prints vector in ASCII Matlab format to stdout
186: . -vec_view_matlab_file - Prints vector in Matlab format to matlaboutput.mat
187: . -vec_view_draw - Activates vector viewing using drawing tools
188: . -display <name> - Sets display name (default is host)
189: . -draw_pause <sec> - Sets number of seconds to pause after display
190: - -vec_view_socket - Activates vector viewing using a socket
191:
192: Level: beginner
194: .seealso: VecAssemblyBegin(), VecSetValues()
195: @*/
196: PetscErrorCode VecAssemblyEnd(Vec vec)
197: {
199: PetscTruth flg;
205: if (vec->ops->assemblyend) {
206: (*vec->ops->assemblyend)(vec);
207: }
209: PetscOptionsBegin(vec->comm,vec->prefix,"Vector Options","Vec");
210: PetscOptionsName("-vec_view","Print vector to stdout","VecView",&flg);
211: if (flg) {
212: VecView(vec,PETSC_VIEWER_STDOUT_(vec->comm));
213: }
214: PetscOptionsName("-vec_view_matlab","Print vector to stdout in a format Matlab can read","VecView",&flg);
215: if (flg) {
216: PetscViewerPushFormat(PETSC_VIEWER_STDOUT_(vec->comm),PETSC_VIEWER_ASCII_MATLAB);
217: VecView(vec,PETSC_VIEWER_STDOUT_(vec->comm));
218: PetscViewerPopFormat(PETSC_VIEWER_STDOUT_(vec->comm));
219: }
220: #if defined(PETSC_HAVE_MATLAB)
221: PetscOptionsName("-vec_view_matlab_file","Print vector to matlaboutput.mat format Matlab can read","VecView",&flg);
222: if (flg) {
223: VecView(vec,PETSC_VIEWER_MATLAB_(vec->comm));
224: }
225: #endif
226: #if defined(PETSC_USE_SOCKET_VIEWER)
227: PetscOptionsName("-vec_view_socket","Send vector to socket (can be read from matlab)","VecView",&flg);
228: if (flg) {
229: VecView(vec,PETSC_VIEWER_SOCKET_(vec->comm));
230: PetscViewerFlush(PETSC_VIEWER_SOCKET_(vec->comm));
231: }
232: #endif
233: PetscOptionsName("-vec_view_binary","Save vector to file in binary format","VecView",&flg);
234: if (flg) {
235: VecView(vec,PETSC_VIEWER_BINARY_(vec->comm));
236: PetscViewerFlush(PETSC_VIEWER_BINARY_(vec->comm));
237: }
238: PetscOptionsEnd();
239: /* These invoke PetscDrawGetDraw which invokes PetscOptionsBegin/End, */
240: /* hence they should not be inside the above PetscOptionsBegin/End block. */
241: PetscOptionsHasName(vec->prefix,"-vec_view_draw",&flg);
242: if (flg) {
243: VecView(vec,PETSC_VIEWER_DRAW_(vec->comm));
244: PetscViewerFlush(PETSC_VIEWER_DRAW_(vec->comm));
245: }
246: PetscOptionsHasName(vec->prefix,"-vec_view_draw_lg",&flg);
247: if (flg) {
248: PetscViewerSetFormat(PETSC_VIEWER_DRAW_(vec->comm),PETSC_VIEWER_DRAW_LG);
249: VecView(vec,PETSC_VIEWER_DRAW_(vec->comm));
250: PetscViewerFlush(PETSC_VIEWER_DRAW_(vec->comm));
251: }
252: return(0);
253: }
257: /*@
258: VecPointwiseMax - Computes the componentwise maximum w_i = max(x_i, y_i).
260: Collective on Vec
262: Input Parameters:
263: . x, y - the vectors
265: Output Parameter:
266: . w - the result
268: Level: advanced
270: Notes: any subset of the x, y, and w may be the same vector.
271: For complex numbers compares only the real part
273: Concepts: vector^pointwise multiply
275: .seealso: VecPointwiseDivide(), VecPointwiseMult(), VecPointwiseMin(), VecPointwiseMaxAbs(), VecMaxPointwiseDivide()
276: @*/
277: PetscErrorCode VecPointwiseMax(Vec w,Vec x,Vec y)
278: {
290: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
291: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
293: (*w->ops->pointwisemax)(w,x,y);
294: PetscObjectStateIncrease((PetscObject)w);
295: return(0);
296: }
301: /*@
302: VecPointwiseMin - Computes the componentwise minimum w_i = min(x_i, y_i).
304: Collective on Vec
306: Input Parameters:
307: . x, y - the vectors
309: Output Parameter:
310: . w - the result
312: Level: advanced
314: Notes: any subset of the x, y, and w may be the same vector.
315: For complex numbers compares only the real part
317: Concepts: vector^pointwise multiply
319: .seealso: VecPointwiseDivide(), VecPointwiseMult(), VecPointwiseMin(), VecPointwiseMaxAbs(), VecMaxPointwiseDivide()
320: @*/
321: PetscErrorCode VecPointwiseMin(Vec w,Vec x,Vec y)
322: {
334: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
335: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
337: (*w->ops->pointwisemin)(w,x,y);
338: PetscObjectStateIncrease((PetscObject)w);
339: return(0);
340: }
344: /*@
345: VecPointwiseMaxAbs - Computes the componentwise maximum of the absolute values w_i = max(abs(x_i), abs(y_i)).
347: Collective on Vec
349: Input Parameters:
350: . x, y - the vectors
352: Output Parameter:
353: . w - the result
355: Level: advanced
357: Notes: any subset of the x, y, and w may be the same vector.
359: Concepts: vector^pointwise multiply
361: .seealso: VecPointwiseDivide(), VecPointwiseMult(), VecPointwiseMin(), VecPointwiseMax(), VecMaxPointwiseDivide()
362: @*/
363: PetscErrorCode VecPointwiseMaxAbs(Vec w,Vec x,Vec y)
364: {
376: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
377: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
379: (*w->ops->pointwisemaxabs)(w,x,y);
380: PetscObjectStateIncrease((PetscObject)w);
381: return(0);
382: }
386: /*@
387: VecPointwiseDivide - Computes the componentwise division w = x/y.
389: Collective on Vec
391: Input Parameters:
392: . x, y - the vectors
394: Output Parameter:
395: . w - the result
397: Level: advanced
399: Notes: any subset of the x, y, and w may be the same vector.
401: Concepts: vector^pointwise divide
403: .seealso: VecPointwiseMult(), VecPointwiseMax(), VecPointwiseMin(), VecPointwiseMaxAbs(), VecMaxPointwiseDivide()
404: @*/
405: PetscErrorCode VecPointwiseDivide(Vec w,Vec x,Vec y)
406: {
418: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
419: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
421: (*w->ops->pointwisedivide)(w,x,y);
422: PetscObjectStateIncrease((PetscObject)w);
423: return(0);
424: }
429: /*@
430: VecDuplicate - Creates a new vector of the same type as an existing vector.
432: Collective on Vec
434: Input Parameters:
435: . v - a vector to mimic
437: Output Parameter:
438: . newv - location to put new vector
440: Notes:
441: VecDuplicate() does not copy the vector, but rather allocates storage
442: for the new vector. Use VecCopy() to copy a vector.
444: Use VecDestroy() to free the space. Use VecDuplicateVecs() to get several
445: vectors.
447: Level: beginner
449: .seealso: VecDestroy(), VecDuplicateVecs(), VecCreate(), VecCopy()
450: @*/
451: PetscErrorCode VecDuplicate(Vec x,Vec *newv)
452: {
459: (*x->ops->duplicate)(x,newv);
460: PetscObjectStateIncrease((PetscObject)*newv);
461: return(0);
462: }
466: /*@
467: VecDestroy - Destroys a vector.
469: Collective on Vec
471: Input Parameters:
472: . v - the vector
474: Level: beginner
476: .seealso: VecDuplicate(), VecDestroyVecs()
477: @*/
478: PetscErrorCode VecDestroy(Vec v)
479: {
484: if (--v->refct > 0) return(0);
485: /* destroy the internal part */
486: if (v->ops->destroy) {
487: (*v->ops->destroy)(v);
488: }
489: /* destroy the external/common part */
490: if (v->mapping) {
491: ISLocalToGlobalMappingDestroy(v->mapping);
492: }
493: if (v->bmapping) {
494: ISLocalToGlobalMappingDestroy(v->bmapping);
495: }
496: PetscFree(v->map.range);
497: PetscHeaderDestroy(v);
498: return(0);
499: }
503: /*@C
504: VecDuplicateVecs - Creates several vectors of the same type as an existing vector.
506: Collective on Vec
508: Input Parameters:
509: + m - the number of vectors to obtain
510: - v - a vector to mimic
512: Output Parameter:
513: . V - location to put pointer to array of vectors
515: Notes:
516: Use VecDestroyVecs() to free the space. Use VecDuplicate() to form a single
517: vector.
519: Fortran Note:
520: The Fortran interface is slightly different from that given below, it
521: requires one to pass in V a Vec (integer) array of size at least m.
522: See the Fortran chapter of the users manual and petsc/src/vec/examples for details.
524: Level: intermediate
526: .seealso: VecDestroyVecs(), VecDuplicate(), VecCreate(), VecDuplicateVecsF90()
527: @*/
528: PetscErrorCode VecDuplicateVecs(Vec v,PetscInt m,Vec *V[])
529: {
536: (*v->ops->duplicatevecs)(v, m,V);
537: return(0);
538: }
542: /*@C
543: VecDestroyVecs - Frees a block of vectors obtained with VecDuplicateVecs().
545: Collective on Vec
547: Input Parameters:
548: + vv - pointer to array of vector pointers
549: - m - the number of vectors previously obtained
551: Fortran Note:
552: The Fortran interface is slightly different from that given below.
553: See the Fortran chapter of the users manual and
554: petsc/src/vec/examples for details.
556: Level: intermediate
558: .seealso: VecDuplicateVecs(), VecDestroyVecsf90()
559: @*/
560: PetscErrorCode VecDestroyVecs(Vec vv[],PetscInt m)
561: {
568: (*(*vv)->ops->destroyvecs)(vv,m);
569: return(0);
570: }
572: #undef __FUNCT__
574: /*@
575: VecViewFromOptions - This function visualizes the vector based upon user options.
577: Collective on Vec
579: Input Parameters:
580: . vec - The vector
581: . title - The title
583: Level: intermediate
585: .keywords: Vec, view, options, database
586: .seealso: VecSetFromOptions(), VecView()
587: @*/
588: PetscErrorCode VecViewFromOptions(Vec vec, char *title)
589: {
590: PetscViewer viewer;
591: PetscDraw draw;
592: PetscTruth opt;
593: char *titleStr;
594: char typeName[1024];
595: char fileName[PETSC_MAX_PATH_LEN];
596: size_t len;
600: PetscOptionsHasName(vec->prefix, "-vec_view", &opt);
601: if (opt) {
602: PetscOptionsGetString(vec->prefix, "-vec_view", typeName, 1024, &opt);
603: PetscStrlen(typeName, &len);
604: if (len > 0) {
605: PetscViewerCreate(vec->comm, &viewer);
606: PetscViewerSetType(viewer, typeName);
607: PetscOptionsGetString(vec->prefix, "-vec_view_file", fileName, 1024, &opt);
608: if (opt) {
609: PetscViewerFileSetName(viewer, fileName);
610: } else {
611: PetscViewerFileSetName(viewer, vec->name);
612: }
613: VecView(vec, viewer);
614: PetscViewerFlush(viewer);
615: PetscViewerDestroy(viewer);
616: } else {
617: VecView(vec, PETSC_VIEWER_STDOUT_(vec->comm));
618: }
619: }
620: PetscOptionsHasName(vec->prefix, "-vec_view_draw", &opt);
621: if (opt) {
622: PetscViewerDrawOpen(vec->comm, 0, 0, 0, 0, 300, 300, &viewer);
623: PetscViewerDrawGetDraw(viewer, 0, &draw);
624: if (title) {
625: titleStr = title;
626: } else {
627: PetscObjectName((PetscObject) vec);
628: titleStr = vec->name;
629: }
630: PetscDrawSetTitle(draw, titleStr);
631: VecView(vec, viewer);
632: PetscViewerFlush(viewer);
633: PetscDrawPause(draw);
634: PetscViewerDestroy(viewer);
635: }
636: return(0);
637: }
641: /*@C
642: VecView - Views a vector object.
644: Collective on Vec
646: Input Parameters:
647: + v - the vector
648: - viewer - an optional visualization context
650: Notes:
651: The available visualization contexts include
652: + PETSC_VIEWER_STDOUT_SELF - standard output (default)
653: - PETSC_VIEWER_STDOUT_WORLD - synchronized standard
654: output where only the first processor opens
655: the file. All other processors send their
656: data to the first processor to print.
658: You can change the format the vector is printed using the
659: option PetscViewerSetFormat().
661: The user can open alternative visualization contexts with
662: + PetscViewerASCIIOpen() - Outputs vector to a specified file
663: . PetscViewerBinaryOpen() - Outputs vector in binary to a
664: specified file; corresponding input uses VecLoad()
665: . PetscViewerDrawOpen() - Outputs vector to an X window display
666: - PetscViewerSocketOpen() - Outputs vector to Socket viewer
668: The user can call PetscViewerSetFormat() to specify the output
669: format of ASCII printed objects (when using PETSC_VIEWER_STDOUT_SELF,
670: PETSC_VIEWER_STDOUT_WORLD and PetscViewerASCIIOpen). Available formats include
671: + PETSC_VIEWER_ASCII_DEFAULT - default, prints vector contents
672: . PETSC_VIEWER_ASCII_MATLAB - prints vector contents in Matlab format
673: . PETSC_VIEWER_ASCII_INDEX - prints vector contents, including indices of vector elements
674: - PETSC_VIEWER_ASCII_COMMON - prints vector contents, using a
675: format common among all vector types
677: Level: beginner
679: Concepts: vector^printing
680: Concepts: vector^saving to disk
682: .seealso: PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscDrawLGCreate(),
683: PetscViewerSocketOpen(), PetscViewerBinaryOpen(), VecLoad(), PetscViewerCreate(),
684: PetscRealView(), PetscScalarView(), PetscIntView()
685: @*/
686: PetscErrorCode VecView(Vec vec,PetscViewer viewer)
687: {
688: PetscErrorCode ierr;
689: PetscViewerFormat format;
694: if (!viewer) viewer = PETSC_VIEWER_STDOUT_(vec->comm);
697: if (vec->stash.n || vec->bstash.n) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call VecAssemblyBegin/End() before viewing this vector");
699: /*
700: Check if default viewer has been overridden, but user request it anyways
701: */
702: PetscViewerGetFormat(viewer,&format);
703: if (vec->ops->viewnative && format == PETSC_VIEWER_NATIVE) {
704: PetscViewerPopFormat(viewer);
705: (*vec->ops->viewnative)(vec,viewer);
706: PetscViewerPushFormat(viewer,PETSC_VIEWER_NATIVE);
707: } else {
708: (*vec->ops->view)(vec,viewer);
709: }
710: return(0);
711: }
715: /*@
716: VecGetSize - Returns the global number of elements of the vector.
718: Not Collective
720: Input Parameter:
721: . x - the vector
723: Output Parameters:
724: . size - the global length of the vector
726: Level: beginner
728: Concepts: vector^local size
730: .seealso: VecGetLocalSize()
731: @*/
732: PetscErrorCode VecGetSize(Vec x,PetscInt *size)
733: {
740: (*x->ops->getsize)(x,size);
741: return(0);
742: }
746: /*@
747: VecGetLocalSize - Returns the number of elements of the vector stored
748: in local memory. This routine may be implementation dependent, so use
749: with care.
751: Not Collective
753: Input Parameter:
754: . x - the vector
756: Output Parameter:
757: . size - the length of the local piece of the vector
759: Level: beginner
761: Concepts: vector^size
763: .seealso: VecGetSize()
764: @*/
765: PetscErrorCode VecGetLocalSize(Vec x,PetscInt *size)
766: {
773: (*x->ops->getlocalsize)(x,size);
774: return(0);
775: }
779: /*@C
780: VecGetOwnershipRange - Returns the range of indices owned by
781: this processor, assuming that the vectors are laid out with the
782: first n1 elements on the first processor, next n2 elements on the
783: second, etc. For certain parallel layouts this range may not be
784: well defined.
786: Not Collective
788: Input Parameter:
789: . x - the vector
791: Output Parameters:
792: + low - the first local element, pass in PETSC_NULL if not interested
793: - high - one more than the last local element, pass in PETSC_NULL if not interested
795: Note:
796: The high argument is one more than the last element stored locally.
798: Fortran: PETSC_NULL_INTEGER should be used instead of PETSC_NULL
800: Level: beginner
802: Concepts: ownership^of vectors
803: Concepts: vector^ownership of elements
805: @*/
806: PetscErrorCode VecGetOwnershipRange(Vec x,PetscInt *low,PetscInt *high)
807: {
813: if (low) *low = x->map.rstart;
814: if (high) *high = x->map.rend;
815: return(0);
816: }
820: /*@
821: VecSetOption - Sets an option for controling a vector's behavior.
823: Collective on Vec
825: Input Parameter:
826: + x - the vector
827: - op - the option
829: Supported Options:
830: + VEC_IGNORE_OFF_PROC_ENTRIES, which causes VecSetValues() to ignore
831: entries destined to be stored on a separate processor. This can be used
832: to eliminate the global reduction in the VecAssemblyXXXX() if you know
833: that you have only used VecSetValues() to set local elements
834: - VEC_TREAT_OFF_PROC_ENTRIES restores the treatment of off processor entries.
836: Level: intermediate
838: @*/
839: PetscErrorCode VecSetOption(Vec x,VecOption op)
840: {
846: if (x->ops->setoption) {
847: (*x->ops->setoption)(x,op);
848: }
849: return(0);
850: }
854: /* Default routines for obtaining and releasing; */
855: /* may be used by any implementation */
856: PetscErrorCode VecDuplicateVecs_Default(Vec w,PetscInt m,Vec *V[])
857: {
859: PetscInt i;
864: if (m <= 0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"m must be > 0: m = %D",m);
865: PetscMalloc(m*sizeof(Vec*),V);
866: for (i=0; i<m; i++) {VecDuplicate(w,*V+i);}
867: return(0);
868: }
872: PetscErrorCode VecDestroyVecs_Default(Vec v[], PetscInt m)
873: {
875: PetscInt i;
879: if (m <= 0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"m must be > 0: m = %D",m);
880: for (i=0; i<m; i++) {VecDestroy(v[i]);}
881: PetscFree(v);
882: return(0);
883: }
887: /*@
888: VecResetArray - Resets a vector to use its default memory. Call this
889: after the use of VecPlaceArray().
891: Not Collective
893: Input Parameters:
894: . vec - the vector
896: Level: developer
898: .seealso: VecGetArray(), VecRestoreArray(), VecReplaceArray(), VecPlaceArray()
900: @*/
901: PetscErrorCode VecResetArray(Vec vec)
902: {
908: if (vec->ops->resetarray) {
909: (*vec->ops->resetarray)(vec);
910: } else {
911: SETERRQ(PETSC_ERR_SUP,"Cannot reset array in this type of vector");
912: }
913: PetscObjectStateIncrease((PetscObject)vec);
914: return(0);
915: }
919: /*@C
920: VecLoadIntoVector - Loads a vector that has been stored in binary format
921: with VecView().
923: Collective on PetscViewer
925: Input Parameters:
926: + viewer - binary file viewer, obtained from PetscViewerBinaryOpen()
927: - vec - vector to contain files values (must be of correct length)
929: Level: intermediate
931: Notes:
932: The input file must contain the full global vector, as
933: written by the routine VecView().
935: Use VecLoad() to create the vector as the values are read in
937: Notes for advanced users:
938: Most users should not need to know the details of the binary storage
939: format, since VecLoad() and VecView() completely hide these details.
940: But for anyone who's interested, the standard binary matrix storage
941: format is
942: .vb
943: int VEC_FILE_COOKIE
944: int number of rows
945: PetscScalar *values of all nonzeros
946: .ve
948: Note for Cray users, the int's stored in the binary file are 32 bit
949: integers; not 64 as they are represented in the memory, so if you
950: write your own routines to read/write these binary files from the Cray
951: you need to adjust the integer sizes that you read in, see
952: PetscBinaryRead() and PetscBinaryWrite() to see how this may be
953: done.
955: In addition, PETSc automatically does the byte swapping for
956: machines that store the bytes reversed, e.g. DEC alpha, freebsd,
957: linux, Windows and the paragon; thus if you write your own binary
958: read/write routines you have to swap the bytes; see PetscBinaryRead()
959: and PetscBinaryWrite() to see how this may be done.
961: Concepts: vector^loading from file
963: .seealso: PetscViewerBinaryOpen(), VecView(), MatLoad(), VecLoad()
964: @*/
965: PetscErrorCode VecLoadIntoVector(PetscViewer viewer,Vec vec)
966: {
973: if (!vec->ops->loadintovector) {
974: SETERRQ(PETSC_ERR_SUP,"Vector does not support load");
975: }
976: (*vec->ops->loadintovector)(viewer,vec);
977: PetscObjectStateIncrease((PetscObject)vec);
978: return(0);
979: }
983: /*@
984: VecReciprocal - Replaces each component of a vector by its reciprocal.
986: Collective on Vec
988: Input Parameter:
989: . v - the vector
991: Output Parameter:
992: . v - the vector reciprocal
994: Level: intermediate
996: Concepts: vector^reciprocal
998: @*/
999: PetscErrorCode VecReciprocal(Vec vec)
1000: {
1006: if (vec->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1007: if (!vec->ops->reciprocal) {
1008: SETERRQ(PETSC_ERR_SUP,"Vector does not support reciprocal operation");
1009: }
1010: (*vec->ops->reciprocal)(vec);
1011: PetscObjectStateIncrease((PetscObject)vec);
1012: return(0);
1013: }
1017: PetscErrorCode VecSetOperation(Vec vec,VecOperation op, void (*f)(void))
1018: {
1021: /* save the native version of the viewer */
1022: if (op == VECOP_VIEW && !vec->ops->viewnative) {
1023: vec->ops->viewnative = vec->ops->view;
1024: }
1025: (((void(**)(void))vec->ops)[(int)op]) = f;
1026: return(0);
1027: }
1032: /*@
1033: VecStashSetInitialSize - sets the sizes of the vec-stash, that is
1034: used during the assembly process to store values that belong to
1035: other processors.
1037: Collective on Vec
1039: Input Parameters:
1040: + vec - the vector
1041: . size - the initial size of the stash.
1042: - bsize - the initial size of the block-stash(if used).
1044: Options Database Keys:
1045: + -vecstash_initial_size <size> or <size0,size1,...sizep-1>
1046: - -vecstash_block_initial_size <bsize> or <bsize0,bsize1,...bsizep-1>
1048: Level: intermediate
1050: Notes:
1051: The block-stash is used for values set with VecSetValuesBlocked() while
1052: the stash is used for values set with VecSetValues()
1054: Run with the option -info and look for output of the form
1055: VecAssemblyBegin_MPIXXX:Stash has MM entries, uses nn mallocs.
1056: to determine the appropriate value, MM, to use for size and
1057: VecAssemblyBegin_MPIXXX:Block-Stash has BMM entries, uses nn mallocs.
1058: to determine the value, BMM to use for bsize
1060: Concepts: vector^stash
1061: Concepts: stash^vector
1063: .seealso: VecSetBlockSize(), VecSetValues(), VecSetValuesBlocked(), VecStashView()
1065: @*/
1066: PetscErrorCode VecStashSetInitialSize(Vec vec,PetscInt size,PetscInt bsize)
1067: {
1072: VecStashSetInitialSize_Private(&vec->stash,size);
1073: VecStashSetInitialSize_Private(&vec->bstash,bsize);
1074: return(0);
1075: }
1079: /*@
1080: VecConjugate - Conjugates a vector.
1082: Collective on Vec
1084: Input Parameters:
1085: . x - the vector
1087: Level: intermediate
1089: Concepts: vector^conjugate
1091: @*/
1092: PetscErrorCode VecConjugate(Vec x)
1093: {
1094: #ifdef PETSC_USE_COMPLEX
1100: if (x->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1101: (*x->ops->conjugate)(x);
1102: /* we need to copy norms here */
1103: PetscObjectStateIncrease((PetscObject)x);
1104: return(0);
1105: #else
1106: return(0);
1107: #endif
1108: }
1112: /*@
1113: VecPointwiseMult - Computes the componentwise multiplication w = x*y.
1115: Collective on Vec
1117: Input Parameters:
1118: . x, y - the vectors
1120: Output Parameter:
1121: . w - the result
1123: Level: advanced
1125: Notes: any subset of the x, y, and w may be the same vector.
1127: Concepts: vector^pointwise multiply
1129: .seealso: VecPointwiseDivide(), VecPointwiseMax(), VecPointwiseMin(), VecPointwiseMaxAbs(), VecMaxPointwiseDivide()
1130: @*/
1131: PetscErrorCode VecPointwiseMult(Vec w, Vec x,Vec y)
1132: {
1144: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
1145: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
1148: (*w->ops->pointwisemult)(w,x,y);
1150: PetscObjectStateIncrease((PetscObject)w);
1151: return(0);
1152: }
1156: /*@
1157: VecSetRandom - Sets all components of a vector to random numbers.
1159: Collective on Vec
1161: Input Parameters:
1162: + x - the vector
1163: - rctx - the random number context, formed by PetscRandomCreate(), or PETSC_NULL and
1164: it will create one internally.
1166: Output Parameter:
1167: . x - the vector
1169: Example of Usage:
1170: .vb
1171: PetscRandomCreate(PETSC_COMM_WORLD,&rctx);
1172: VecSetRandom(x,rctx);
1173: PetscRandomDestroy(rctx);
1174: .ve
1176: Level: intermediate
1178: Concepts: vector^setting to random
1179: Concepts: random^vector
1181: .seealso: VecSet(), VecSetValues(), PetscRandomCreate(), PetscRandomDestroy()
1182: @*/
1183: PetscErrorCode VecSetRandom(Vec x,PetscRandom rctx)
1184: {
1186: PetscRandom randObj = PETSC_NULL;
1192: if (x->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1194: if (!rctx) {
1195: MPI_Comm comm;
1196: PetscObjectGetComm((PetscObject)x,&comm);
1197: PetscRandomCreate(comm,&randObj);
1198: PetscRandomSetFromOptions(randObj);
1199: rctx = randObj;
1200: }
1203: (*x->ops->setrandom)(x,rctx);
1205:
1206: if (randObj) {
1207: PetscRandomDestroy(randObj);
1208: }
1209: PetscObjectStateIncrease((PetscObject)x);
1210: return(0);
1211: }
1213: /*@
1214: VecZeroEntries - puts a 0.0 in each element of a vector
1216: Collective on Vec
1218: Input Parameter:
1219: . vec - The vector
1221: Level: beginner
1223: .keywords: Vec, set, options, database
1224: .seealso: VecCreate(), VecSetOptionsPrefix(), VecSet(), VecSetValues()
1225: @*/
1226: PetscErrorCode VecZeroEntries (Vec vec)
1227: {
1230: VecSet(vec,0);
1231: return(0);
1232: }
1236: /*
1237: VecSetTypeFromOptions_Private - Sets the type of vector from user options. Defaults to a PETSc sequential vector on one
1238: processor and a PETSc MPI vector on more than one processor.
1240: Collective on Vec
1242: Input Parameter:
1243: . vec - The vector
1245: Level: intermediate
1247: .keywords: Vec, set, options, database, type
1248: .seealso: VecSetFromOptions(), VecSetType()
1249: */
1250: static PetscErrorCode VecSetTypeFromOptions_Private(Vec vec)
1251: {
1252: PetscTruth opt;
1253: const char *defaultType;
1254: char typeName[256];
1255: PetscMPIInt size;
1259: if (vec->type_name) {
1260: defaultType = vec->type_name;
1261: } else {
1262: MPI_Comm_size(vec->comm, &size);
1263: if (size > 1) {
1264: defaultType = VECMPI;
1265: } else {
1266: defaultType = VECSEQ;
1267: }
1268: }
1270: if (!VecRegisterAllCalled) {
1271: VecRegisterAll(PETSC_NULL);
1272: }
1273: PetscOptionsList("-vec_type","Vector type","VecSetType",VecList,defaultType,typeName,256,&opt);
1274: if (opt) {
1275: VecSetType(vec, typeName);
1276: } else {
1277: VecSetType(vec, defaultType);
1278: }
1279: return(0);
1280: }
1284: /*@
1285: VecSetFromOptions - Configures the vector from the options database.
1287: Collective on Vec
1289: Input Parameter:
1290: . vec - The vector
1292: Notes: To see all options, run your program with the -help option, or consult the users manual.
1293: Must be called after VecCreate() but before the vector is used.
1295: Level: beginner
1297: Concepts: vectors^setting options
1298: Concepts: vectors^setting type
1300: .keywords: Vec, set, options, database
1301: .seealso: VecCreate(), VecSetOptionsPrefix()
1302: @*/
1303: PetscErrorCode VecSetFromOptions(Vec vec)
1304: {
1310: PetscOptionsBegin(vec->comm, vec->prefix, "Vector options", "Vec");
1311: /* Handle vector type options */
1312: VecSetTypeFromOptions_Private(vec);
1314: /* Handle specific vector options */
1315: if (vec->ops->setfromoptions) {
1316: (*vec->ops->setfromoptions)(vec);
1317: }
1318: PetscOptionsEnd();
1320: VecViewFromOptions(vec, vec->name);
1321: return(0);
1322: }
1326: /*@
1327: VecSetSizes - Sets the local and global sizes, and checks to determine compatibility
1329: Collective on Vec
1331: Input Parameters:
1332: + v - the vector
1333: . n - the local size (or PETSC_DECIDE to have it set)
1334: - N - the global size (or PETSC_DECIDE)
1336: Notes:
1337: n and N cannot be both PETSC_DECIDE
1338: If one processor calls this with N of PETSC_DECIDE then all processors must, otherwise the program will hang.
1340: Level: intermediate
1342: .seealso: VecGetSize(), PetscSplitOwnership()
1343: @*/
1344: PetscErrorCode VecSetSizes(Vec v, PetscInt n, PetscInt N)
1345: {
1348: if (N > 0 && n > N) SETERRQ2(PETSC_ERR_ARG_INCOMP,"Local size %D cannot be larger than global size %D",n,N);
1349: 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);
1350: v->map.n = n;
1351: v->map.N = N;
1352: return(0);
1353: }
1357: /*@
1358: VecSetBlockSize - Sets the blocksize for future calls to VecSetValuesBlocked()
1359: and VecSetValuesBlockedLocal().
1361: Collective on Vec
1363: Input Parameter:
1364: + v - the vector
1365: - bs - the blocksize
1367: Notes:
1368: All vectors obtained by VecDuplicate() inherit the same blocksize.
1370: Level: advanced
1372: .seealso: VecSetValuesBlocked(), VecSetLocalToGlobalMappingBlock(), VecGetBlockSize()
1374: Concepts: block size^vectors
1375: @*/
1376: PetscErrorCode VecSetBlockSize(Vec v,PetscInt bs)
1377: {
1380: if (bs <= 0) bs = 1;
1381: if (bs == v->map.bs) return(0);
1382: 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);
1383: if (v->map.n != -1 && v->map.n % bs) SETERRQ2(PETSC_ERR_ARG_OUTOFRANGE,"Local vector length not divisible by blocksize %D %D\n\
1384: Try setting blocksize before setting the vector type",v->map.n,bs);
1385:
1386: v->map.bs = bs;
1387: v->bstash.bs = bs; /* use the same blocksize for the vec's block-stash */
1388: return(0);
1389: }
1393: /*@
1394: VecGetBlockSize - Gets the blocksize for the vector, i.e. what is used for VecSetValuesBlocked()
1395: and VecSetValuesBlockedLocal().
1397: Collective on Vec
1399: Input Parameter:
1400: . v - the vector
1402: Output Parameter:
1403: . bs - the blocksize
1405: Notes:
1406: All vectors obtained by VecDuplicate() inherit the same blocksize.
1408: Level: advanced
1410: .seealso: VecSetValuesBlocked(), VecSetLocalToGlobalMappingBlock(), VecSetBlockSize()
1412: Concepts: vector^block size
1413: Concepts: block^vector
1415: @*/
1416: PetscErrorCode VecGetBlockSize(Vec v,PetscInt *bs)
1417: {
1421: *bs = v->map.bs;
1422: return(0);
1423: }
1427: /*@
1428: VecValid - Checks whether a vector object is valid.
1430: Not Collective
1432: Input Parameter:
1433: . v - the object to check
1435: Output Parameter:
1436: flg - flag indicating vector status, either
1437: PETSC_TRUE if vector is valid, or PETSC_FALSE otherwise.
1439: Level: developer
1441: @*/
1442: PetscErrorCode VecValid(Vec v,PetscTruth *flg)
1443: {
1446: if (!v) *flg = PETSC_FALSE;
1447: else if (v->cookie != VEC_COOKIE) *flg = PETSC_FALSE;
1448: else *flg = PETSC_TRUE;
1449: return(0);
1450: }
1454: /*@C
1455: VecSetOptionsPrefix - Sets the prefix used for searching for all
1456: Vec options in the database.
1458: Collective on Vec
1460: Input Parameter:
1461: + v - the Vec context
1462: - prefix - the prefix to prepend to all option names
1464: Notes:
1465: A hyphen (-) must NOT be given at the beginning of the prefix name.
1466: The first character of all runtime options is AUTOMATICALLY the hyphen.
1468: Level: advanced
1470: .keywords: Vec, set, options, prefix, database
1472: .seealso: VecSetFromOptions()
1473: @*/
1474: PetscErrorCode VecSetOptionsPrefix(Vec v,const char prefix[])
1475: {
1480: PetscObjectSetOptionsPrefix((PetscObject)v,prefix);
1481: return(0);
1482: }
1486: /*@C
1487: VecAppendOptionsPrefix - Appends to the prefix used for searching for all
1488: Vec options in the database.
1490: Collective on Vec
1492: Input Parameters:
1493: + v - the Vec context
1494: - prefix - the prefix to prepend to all option names
1496: Notes:
1497: A hyphen (-) must NOT be given at the beginning of the prefix name.
1498: The first character of all runtime options is AUTOMATICALLY the hyphen.
1500: Level: advanced
1502: .keywords: Vec, append, options, prefix, database
1504: .seealso: VecGetOptionsPrefix()
1505: @*/
1506: PetscErrorCode VecAppendOptionsPrefix(Vec v,const char prefix[])
1507: {
1509:
1512: PetscObjectAppendOptionsPrefix((PetscObject)v,prefix);
1513: return(0);
1514: }
1518: /*@C
1519: VecGetOptionsPrefix - Sets the prefix used for searching for all
1520: Vec options in the database.
1522: Not Collective
1524: Input Parameter:
1525: . A - the Vec context
1527: Output Parameter:
1528: . prefix - pointer to the prefix string used
1530: Notes: On the fortran side, the user should pass in a string 'prefix' of
1531: sufficient length to hold the prefix.
1533: Level: advanced
1535: .keywords: Vec, get, options, prefix, database
1537: .seealso: VecAppendOptionsPrefix()
1538: @*/
1539: PetscErrorCode VecGetOptionsPrefix(Vec v,const char *prefix[])
1540: {
1545: PetscObjectGetOptionsPrefix((PetscObject)v,prefix);
1546: return(0);
1547: }
1551: /*@
1552: VecSetUp - Sets up the internal vector data structures for the later use.
1554: Collective on Vec
1556: Input Parameters:
1557: . v - the Vec context
1559: Notes:
1560: For basic use of the Vec classes the user need not explicitly call
1561: VecSetUp(), since these actions will happen automatically.
1563: Level: advanced
1565: .keywords: Vec, setup
1567: .seealso: VecCreate(), VecDestroy()
1568: @*/
1569: PetscErrorCode VecSetUp(Vec v)
1570: {
1575: VecSetFromOptions(v);
1576: return(0);
1577: }
1579: /*
1580: These currently expose the PetscScalar/PetscReal in updating the
1581: cached norm. If we push those down into the implementation these
1582: will become independent of PetscScalar/PetscReal
1583: */
1587: /*@
1588: VecCopy - Copies a vector.
1590: Collective on Vec
1592: Input Parameter:
1593: . x - the vector
1595: Output Parameter:
1596: . y - the copy
1598: Notes:
1599: For default parallel PETSc vectors, both x and y must be distributed in
1600: the same manner; local copies are done.
1602: Level: beginner
1604: .seealso: VecDuplicate()
1605: @*/
1606: PetscErrorCode VecCopy(Vec x,Vec y)
1607: {
1608: PetscTruth flgs[4];
1609: PetscReal norms[4] = {0.0,0.0,0.0,0.0};
1611: PetscInt i;
1619: if (x == y) return(0);
1620: if (x->map.N != y->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
1621: if (x->map.n != y->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
1624: (*x->ops->copy)(x,y);
1627: /*
1628: * Update cached data
1629: */
1630: /* in general we consider this object touched */
1631: PetscObjectStateIncrease((PetscObject)y);
1633: for (i=0; i<4; i++) {
1634: PetscObjectComposedDataGetReal((PetscObject)x,NormIds[i],norms[i],flgs[i]);
1635: }
1636: for (i=0; i<4; i++) {
1637: if (flgs[i]) {
1638: PetscObjectComposedDataSetReal((PetscObject)y,NormIds[i],norms[i]);
1639: }
1640: }
1643: return(0);
1644: }
1648: /*@
1649: VecSwap - Swaps the vectors x and y.
1651: Collective on Vec
1653: Input Parameters:
1654: . x, y - the vectors
1656: Level: advanced
1658: Concepts: vector^swapping values
1660: @*/
1661: PetscErrorCode VecSwap(Vec x,Vec y)
1662: {
1663: PetscReal normxs[4]={0.0,0.0,0.0,0.0},normys[4]={0.0,0.0,0.0,0.0};
1664: PetscTruth flgxs[4],flgys[4];
1666: PetscInt i;
1674: if (x->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1675: if (y->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1676: if (x->map.N != y->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
1677: if (x->map.n != y->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
1680: (*x->ops->swap)(x,y);
1682: /* See if we have cached norms */
1683: for (i=0; i<4; i++) {
1684: PetscObjectComposedDataGetReal((PetscObject)x,NormIds[i],normxs[i],flgxs[i]);
1685: PetscObjectComposedDataGetReal((PetscObject)y,NormIds[i],normys[i],flgys[i]);
1686: }
1687: for (i=0; i<4; i++) {
1688: if (flgxs[i]) {
1689: PetscObjectComposedDataSetReal((PetscObject)y,NormIds[i],normxs[i]);
1690: }
1691: if (flgys[i]) {
1692: PetscObjectComposedDataSetReal((PetscObject)x,NormIds[i],normys[i]);
1693: }
1694: }
1696: return(0);
1697: }
1701: /*@
1702: VecStashView - Prints the entries in the vector stash and block stash.
1704: Collective on Vec
1706: Input Parameters:
1707: + vec - the vector
1708: - viewer - the viewer
1710: Level: advanced
1712: Concepts: vector^stash
1713: Concepts: stash^vector
1715: .seealso: VecSetBlockSize(), VecSetValues(), VecSetValuesBlocked()
1717: @*/
1718: PetscErrorCode VecStashView(Vec v,PetscViewer viewer)
1719: {
1721: PetscMPIInt rank;
1722: PetscInt i,j;
1723: PetscTruth match;
1724: VecStash *s;
1725: PetscScalar val;
1732: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&match);
1733: if (!match) SETERRQ1(PETSC_ERR_SUP,"Stash viewer only works with ASCII viewer not %s\n",((PetscObject)v)->type_name);
1734: PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);
1735: MPI_Comm_rank(v->comm,&rank);
1736: s = &v->bstash;
1738: /* print block stash */
1739: PetscViewerASCIISynchronizedPrintf(viewer,"[%d]Vector Block stash size %D block size %D\n",rank,s->n,s->bs);
1740: for (i=0; i<s->n; i++) {
1741: PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Element %D ",rank,s->idx[i]);
1742: for (j=0; j<s->bs; j++) {
1743: val = s->array[i*s->bs+j];
1744: #if defined(PETSC_USE_COMPLEX)
1745: PetscViewerASCIISynchronizedPrintf(viewer,"(%18.16e %18.16e) ",PetscRealPart(val),PetscImaginaryPart(val));
1746: #else
1747: PetscViewerASCIISynchronizedPrintf(viewer,"%18.16e ",val);
1748: #endif
1749: }
1750: PetscViewerASCIISynchronizedPrintf(viewer,"\n");
1751: }
1752: PetscViewerFlush(viewer);
1754: s = &v->stash;
1756: /* print basic stash */
1757: PetscViewerASCIISynchronizedPrintf(viewer,"[%d]Vector stash size %D\n",rank,s->n);
1758: for (i=0; i<s->n; i++) {
1759: val = s->array[i];
1760: #if defined(PETSC_USE_COMPLEX)
1761: PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Element %D (%18.16e %18.16e) ",rank,s->idx[i],PetscRealPart(val),PetscImaginaryPart(val));
1762: #else
1763: PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Element %D %18.16e\n",rank,s->idx[i],val);
1764: #endif
1765: }
1766: PetscViewerFlush(viewer);
1768: PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);
1769: return(0);
1770: }