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 *breallocs)
41: {
44: VecStashGetInfo_Private(&vec->stash,nstash,reallocs);
45: VecStashGetInfo_Private(&vec->bstash,bnstash,breallocs);
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: PetscObjectReference((PetscObject)mapping);
88: if (x->mapping) { ISLocalToGlobalMappingDestroy(x->mapping); }
89: x->mapping = mapping;
90: }
91: return(0);
92: }
96: /*@
97: VecSetLocalToGlobalMappingBlock - Sets a local numbering to global numbering used
98: by the routine VecSetValuesBlockedLocal() to allow users to insert vector entries
99: using a local (per-processor) numbering.
101: Collective on Vec
103: Input Parameters:
104: + x - vector
105: - mapping - mapping created with ISLocalToGlobalMappingCreate() or ISLocalToGlobalMappingCreateIS()
107: Notes:
108: All vectors obtained with VecDuplicate() from this vector inherit the same mapping.
110: Level: intermediate
112: Concepts: vector^setting values blocked with local numbering
114: .seealso: VecAssemblyBegin(), VecAssemblyEnd(), VecSetValues(), VecSetValuesLocal(),
115: VecSetLocalToGlobalMapping(), VecSetValuesBlockedLocal()
116: @*/
117: PetscErrorCode VecSetLocalToGlobalMappingBlock(Vec x,ISLocalToGlobalMapping mapping)
118: {
125: if (x->bmapping) {
126: SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Mapping already set for vector");
127: }
128: PetscObjectReference((PetscObject)mapping);
129: if (x->bmapping) { ISLocalToGlobalMappingDestroy(x->bmapping); }
130: x->bmapping = mapping;
131: return(0);
132: }
136: /*@
137: VecAssemblyBegin - Begins assembling the vector. This routine should
138: be called after completing all calls to VecSetValues().
140: Collective on Vec
142: Input Parameter:
143: . vec - the vector
145: Level: beginner
147: Concepts: assembly^vectors
149: .seealso: VecAssemblyEnd(), VecSetValues()
150: @*/
151: PetscErrorCode VecAssemblyBegin(Vec vec)
152: {
154: PetscTruth flg;
160: PetscOptionsHasName(vec->prefix,"-vec_view_stash",&flg);
161: if (flg) {
162: PetscViewer viewer;
163: PetscViewerASCIIGetStdout(vec->comm,&viewer);
164: VecStashView(vec,viewer);
165: }
168: if (vec->ops->assemblybegin) {
169: (*vec->ops->assemblybegin)(vec);
170: }
172: PetscObjectStateIncrease((PetscObject)vec);
173: return(0);
174: }
178: /*
179: Processes command line options to determine if/how a matrix
180: is to be viewed. Called by VecAssemblyEnd().
182: .seealso: MatView_Private()
184: */
185: PetscErrorCode VecView_Private(Vec vec)
186: {
188: PetscTruth flg;
191: PetscOptionsBegin(vec->comm,vec->prefix,"Vector Options","Vec");
192: PetscOptionsName("-vec_view","Print vector to stdout","VecView",&flg);
193: if (flg) {
194: PetscViewer viewer;
195: PetscViewerASCIIGetStdout(vec->comm,&viewer);
196: VecView(vec,viewer);
197: }
198: PetscOptionsName("-vec_view_matlab","Print vector to stdout in a format Matlab can read","VecView",&flg);
199: if (flg) {
200: PetscViewer viewer;
201: PetscViewerASCIIGetStdout(vec->comm,&viewer);
202: PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_MATLAB);
203: VecView(vec,viewer);
204: PetscViewerPopFormat(viewer);
205: }
206: #if defined(PETSC_HAVE_MATLAB_ENGINE)
207: PetscOptionsName("-vec_view_matlab_file","Print vector to matlaboutput.mat format Matlab can read","VecView",&flg);
208: if (flg) {
209: VecView(vec,PETSC_VIEWER_MATLAB_(vec->comm));
210: }
211: #endif
212: #if defined(PETSC_USE_SOCKET_VIEWER)
213: PetscOptionsName("-vec_view_socket","Send vector to socket (can be read from matlab)","VecView",&flg);
214: if (flg) {
215: VecView(vec,PETSC_VIEWER_SOCKET_(vec->comm));
216: PetscViewerFlush(PETSC_VIEWER_SOCKET_(vec->comm));
217: }
218: #endif
219: PetscOptionsName("-vec_view_binary","Save vector to file in binary format","VecView",&flg);
220: if (flg) {
221: VecView(vec,PETSC_VIEWER_BINARY_(vec->comm));
222: PetscViewerFlush(PETSC_VIEWER_BINARY_(vec->comm));
223: }
224: PetscOptionsEnd();
225: /* These invoke PetscDrawGetDraw which invokes PetscOptionsBegin/End, */
226: /* hence they should not be inside the above PetscOptionsBegin/End block. */
227: PetscOptionsHasName(vec->prefix,"-vec_view_draw",&flg);
228: if (flg) {
229: VecView(vec,PETSC_VIEWER_DRAW_(vec->comm));
230: PetscViewerFlush(PETSC_VIEWER_DRAW_(vec->comm));
231: }
232: PetscOptionsHasName(vec->prefix,"-vec_view_draw_lg",&flg);
233: if (flg) {
234: PetscViewerSetFormat(PETSC_VIEWER_DRAW_(vec->comm),PETSC_VIEWER_DRAW_LG);
235: VecView(vec,PETSC_VIEWER_DRAW_(vec->comm));
236: PetscViewerFlush(PETSC_VIEWER_DRAW_(vec->comm));
237: }
238: return(0);
239: }
243: /*@
244: VecAssemblyEnd - Completes assembling the vector. This routine should
245: be called after VecAssemblyBegin().
247: Collective on Vec
249: Input Parameter:
250: . vec - the vector
252: Options Database Keys:
253: + -vec_view - Prints vector in ASCII format
254: . -vec_view_matlab - Prints vector in ASCII Matlab format to stdout
255: . -vec_view_matlab_file - Prints vector in Matlab format to matlaboutput.mat
256: . -vec_view_draw - Activates vector viewing using drawing tools
257: . -display <name> - Sets display name (default is host)
258: . -draw_pause <sec> - Sets number of seconds to pause after display
259: - -vec_view_socket - Activates vector viewing using a socket
260:
261: Level: beginner
263: .seealso: VecAssemblyBegin(), VecSetValues()
264: @*/
265: PetscErrorCode VecAssemblyEnd(Vec vec)
266: {
273: if (vec->ops->assemblyend) {
274: (*vec->ops->assemblyend)(vec);
275: }
277: VecView_Private(vec);
278: return(0);
279: }
283: /*@
284: VecPointwiseMax - Computes the componentwise maximum w_i = max(x_i, y_i).
286: Collective on Vec
288: Input Parameters:
289: . x, y - the vectors
291: Output Parameter:
292: . w - the result
294: Level: advanced
296: Notes: any subset of the x, y, and w may be the same vector.
297: For complex numbers compares only the real part
299: Concepts: vector^pointwise multiply
301: .seealso: VecPointwiseDivide(), VecPointwiseMult(), VecPointwiseMin(), VecPointwiseMaxAbs(), VecMaxPointwiseDivide()
302: @*/
303: PetscErrorCode VecPointwiseMax(Vec w,Vec x,Vec y)
304: {
316: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
317: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
319: (*w->ops->pointwisemax)(w,x,y);
320: PetscObjectStateIncrease((PetscObject)w);
321: return(0);
322: }
327: /*@
328: VecPointwiseMin - Computes the componentwise minimum w_i = min(x_i, y_i).
330: Collective on Vec
332: Input Parameters:
333: . x, y - the vectors
335: Output Parameter:
336: . w - the result
338: Level: advanced
340: Notes: any subset of the x, y, and w may be the same vector.
341: For complex numbers compares only the real part
343: Concepts: vector^pointwise multiply
345: .seealso: VecPointwiseDivide(), VecPointwiseMult(), VecPointwiseMin(), VecPointwiseMaxAbs(), VecMaxPointwiseDivide()
346: @*/
347: PetscErrorCode VecPointwiseMin(Vec w,Vec x,Vec y)
348: {
360: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
361: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
363: (*w->ops->pointwisemin)(w,x,y);
364: PetscObjectStateIncrease((PetscObject)w);
365: return(0);
366: }
370: /*@
371: VecPointwiseMaxAbs - Computes the componentwise maximum of the absolute values w_i = max(abs(x_i), abs(y_i)).
373: Collective on Vec
375: Input Parameters:
376: . x, y - the vectors
378: Output Parameter:
379: . w - the result
381: Level: advanced
383: Notes: any subset of the x, y, and w may be the same vector.
385: Concepts: vector^pointwise multiply
387: .seealso: VecPointwiseDivide(), VecPointwiseMult(), VecPointwiseMin(), VecPointwiseMax(), VecMaxPointwiseDivide()
388: @*/
389: PetscErrorCode VecPointwiseMaxAbs(Vec w,Vec x,Vec y)
390: {
402: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
403: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
405: (*w->ops->pointwisemaxabs)(w,x,y);
406: PetscObjectStateIncrease((PetscObject)w);
407: return(0);
408: }
412: /*@
413: VecPointwiseDivide - Computes the componentwise division w = x/y.
415: Collective on Vec
417: Input Parameters:
418: . x, y - the vectors
420: Output Parameter:
421: . w - the result
423: Level: advanced
425: Notes: any subset of the x, y, and w may be the same vector.
427: Concepts: vector^pointwise divide
429: .seealso: VecPointwiseMult(), VecPointwiseMax(), VecPointwiseMin(), VecPointwiseMaxAbs(), VecMaxPointwiseDivide()
430: @*/
431: PetscErrorCode VecPointwiseDivide(Vec w,Vec x,Vec y)
432: {
444: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
445: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
447: (*w->ops->pointwisedivide)(w,x,y);
448: PetscObjectStateIncrease((PetscObject)w);
449: return(0);
450: }
455: /*@
456: VecDuplicate - Creates a new vector of the same type as an existing vector.
458: Collective on Vec
460: Input Parameters:
461: . v - a vector to mimic
463: Output Parameter:
464: . newv - location to put new vector
466: Notes:
467: VecDuplicate() does not copy the vector, but rather allocates storage
468: for the new vector. Use VecCopy() to copy a vector.
470: Use VecDestroy() to free the space. Use VecDuplicateVecs() to get several
471: vectors.
473: Level: beginner
475: .seealso: VecDestroy(), VecDuplicateVecs(), VecCreate(), VecCopy()
476: @*/
477: PetscErrorCode VecDuplicate(Vec v,Vec *newv)
478: {
485: (*v->ops->duplicate)(v,newv);
486: PetscObjectStateIncrease((PetscObject)*newv);
487: return(0);
488: }
492: /*@
493: VecDestroy - Destroys a vector.
495: Collective on Vec
497: Input Parameters:
498: . v - the vector
500: Level: beginner
502: .seealso: VecDuplicate(), VecDestroyVecs()
503: @*/
504: PetscErrorCode VecDestroy(Vec v)
505: {
510: if (--v->refct > 0) return(0);
511: /* destroy the internal part */
512: if (v->ops->destroy) {
513: (*v->ops->destroy)(v);
514: }
515: /* destroy the external/common part */
516: if (v->mapping) {
517: ISLocalToGlobalMappingDestroy(v->mapping);
518: }
519: if (v->bmapping) {
520: ISLocalToGlobalMappingDestroy(v->bmapping);
521: }
522: PetscFree(v->map.range);
523: PetscHeaderDestroy(v);
524: return(0);
525: }
529: /*@C
530: VecDuplicateVecs - Creates several vectors of the same type as an existing vector.
532: Collective on Vec
534: Input Parameters:
535: + m - the number of vectors to obtain
536: - v - a vector to mimic
538: Output Parameter:
539: . V - location to put pointer to array of vectors
541: Notes:
542: Use VecDestroyVecs() to free the space. Use VecDuplicate() to form a single
543: vector.
545: Fortran Note:
546: The Fortran interface is slightly different from that given below, it
547: requires one to pass in V a Vec (integer) array of size at least m.
548: See the Fortran chapter of the users manual and petsc/src/vec/examples for details.
550: Level: intermediate
552: .seealso: VecDestroyVecs(), VecDuplicate(), VecCreate(), VecDuplicateVecsF90()
553: @*/
554: PetscErrorCode VecDuplicateVecs(Vec v,PetscInt m,Vec *V[])
555: {
562: (*v->ops->duplicatevecs)(v, m,V);
563: return(0);
564: }
568: /*@C
569: VecDestroyVecs - Frees a block of vectors obtained with VecDuplicateVecs().
571: Collective on Vec
573: Input Parameters:
574: + vv - pointer to array of vector pointers
575: - m - the number of vectors previously obtained
577: Fortran Note:
578: The Fortran interface is slightly different from that given below.
579: See the Fortran chapter of the users manual and
580: petsc/src/vec/examples for details.
582: Level: intermediate
584: .seealso: VecDuplicateVecs(), VecDestroyVecsf90()
585: @*/
586: PetscErrorCode VecDestroyVecs(Vec vv[],PetscInt m)
587: {
594: (*(*vv)->ops->destroyvecs)(vv,m);
595: return(0);
596: }
598: #undef __FUNCT__
600: /*@
601: VecViewFromOptions - This function visualizes the vector based upon user options.
603: Collective on Vec
605: Input Parameters:
606: . vec - The vector
607: . title - The title
609: Level: intermediate
611: .keywords: Vec, view, options, database
612: .seealso: VecSetFromOptions(), VecView()
613: @*/
614: PetscErrorCode VecViewFromOptions(Vec vec, char *title)
615: {
616: PetscViewer viewer;
617: PetscDraw draw;
618: PetscTruth opt;
619: char *titleStr;
620: char typeName[1024];
621: char fileName[PETSC_MAX_PATH_LEN];
622: size_t len;
626: PetscOptionsHasName(vec->prefix, "-vec_view", &opt);
627: if (opt) {
628: PetscOptionsGetString(vec->prefix, "-vec_view", typeName, 1024, &opt);
629: PetscStrlen(typeName, &len);
630: if (len > 0) {
631: PetscViewerCreate(vec->comm, &viewer);
632: PetscViewerSetType(viewer, typeName);
633: PetscOptionsGetString(vec->prefix, "-vec_view_file", fileName, 1024, &opt);
634: if (opt) {
635: PetscViewerFileSetName(viewer, fileName);
636: } else {
637: PetscViewerFileSetName(viewer, vec->name);
638: }
639: VecView(vec, viewer);
640: PetscViewerFlush(viewer);
641: PetscViewerDestroy(viewer);
642: } else {
643: PetscViewerASCIIGetStdout(vec->comm,&viewer);
644: VecView(vec, viewer);
645: }
646: }
647: PetscOptionsHasName(vec->prefix, "-vec_view_draw", &opt);
648: if (opt) {
649: PetscViewerDrawOpen(vec->comm, 0, 0, 0, 0, 300, 300, &viewer);
650: PetscViewerDrawGetDraw(viewer, 0, &draw);
651: if (title) {
652: titleStr = title;
653: } else {
654: PetscObjectName((PetscObject) vec);
655: titleStr = vec->name;
656: }
657: PetscDrawSetTitle(draw, titleStr);
658: VecView(vec, viewer);
659: PetscViewerFlush(viewer);
660: PetscDrawPause(draw);
661: PetscViewerDestroy(viewer);
662: }
663: return(0);
664: }
668: /*@C
669: VecView - Views a vector object.
671: Collective on Vec
673: Input Parameters:
674: + vec - the vector
675: - viewer - an optional visualization context
677: Notes:
678: The available visualization contexts include
679: + PETSC_VIEWER_STDOUT_SELF - standard output (default)
680: - PETSC_VIEWER_STDOUT_WORLD - synchronized standard
681: output where only the first processor opens
682: the file. All other processors send their
683: data to the first processor to print.
685: You can change the format the vector is printed using the
686: option PetscViewerSetFormat().
688: The user can open alternative visualization contexts with
689: + PetscViewerASCIIOpen() - Outputs vector to a specified file
690: . PetscViewerBinaryOpen() - Outputs vector in binary to a
691: specified file; corresponding input uses VecLoad()
692: . PetscViewerDrawOpen() - Outputs vector to an X window display
693: - PetscViewerSocketOpen() - Outputs vector to Socket viewer
695: The user can call PetscViewerSetFormat() to specify the output
696: format of ASCII printed objects (when using PETSC_VIEWER_STDOUT_SELF,
697: PETSC_VIEWER_STDOUT_WORLD and PetscViewerASCIIOpen). Available formats include
698: + PETSC_VIEWER_ASCII_DEFAULT - default, prints vector contents
699: . PETSC_VIEWER_ASCII_MATLAB - prints vector contents in Matlab format
700: . PETSC_VIEWER_ASCII_INDEX - prints vector contents, including indices of vector elements
701: - PETSC_VIEWER_ASCII_COMMON - prints vector contents, using a
702: format common among all vector types
704: Level: beginner
706: Concepts: vector^printing
707: Concepts: vector^saving to disk
709: .seealso: PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscDrawLGCreate(),
710: PetscViewerSocketOpen(), PetscViewerBinaryOpen(), VecLoad(), PetscViewerCreate(),
711: PetscRealView(), PetscScalarView(), PetscIntView()
712: @*/
713: PetscErrorCode VecView(Vec vec,PetscViewer viewer)
714: {
715: PetscErrorCode ierr;
716: PetscViewerFormat format;
721: if (!viewer) {
722: PetscViewerASCIIGetStdout(vec->comm,&viewer);
723: }
726: if (vec->stash.n || vec->bstash.n) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call VecAssemblyBegin/End() before viewing this vector");
728: /*
729: Check if default viewer has been overridden, but user request it anyways
730: */
731: PetscViewerGetFormat(viewer,&format);
732: if (vec->ops->viewnative && format == PETSC_VIEWER_NATIVE) {
733: PetscViewerPopFormat(viewer);
734: (*vec->ops->viewnative)(vec,viewer);
735: PetscViewerPushFormat(viewer,PETSC_VIEWER_NATIVE);
736: } else {
737: (*vec->ops->view)(vec,viewer);
738: }
739: return(0);
740: }
744: /*@
745: VecGetSize - Returns the global number of elements of the vector.
747: Not Collective
749: Input Parameter:
750: . x - the vector
752: Output Parameters:
753: . size - the global length of the vector
755: Level: beginner
757: Concepts: vector^local size
759: .seealso: VecGetLocalSize()
760: @*/
761: PetscErrorCode VecGetSize(Vec x,PetscInt *size)
762: {
769: (*x->ops->getsize)(x,size);
770: return(0);
771: }
775: /*@
776: VecGetLocalSize - Returns the number of elements of the vector stored
777: in local memory. This routine may be implementation dependent, so use
778: with care.
780: Not Collective
782: Input Parameter:
783: . x - the vector
785: Output Parameter:
786: . size - the length of the local piece of the vector
788: Level: beginner
790: Concepts: vector^size
792: .seealso: VecGetSize()
793: @*/
794: PetscErrorCode VecGetLocalSize(Vec x,PetscInt *size)
795: {
802: (*x->ops->getlocalsize)(x,size);
803: return(0);
804: }
808: /*@C
809: VecGetOwnershipRange - Returns the range of indices owned by
810: this processor, assuming that the vectors are laid out with the
811: first n1 elements on the first processor, next n2 elements on the
812: second, etc. For certain parallel layouts this range may not be
813: well defined.
815: Not Collective
817: Input Parameter:
818: . x - the vector
820: Output Parameters:
821: + low - the first local element, pass in PETSC_NULL if not interested
822: - high - one more than the last local element, pass in PETSC_NULL if not interested
824: Note:
825: The high argument is one more than the last element stored locally.
827: Fortran: PETSC_NULL_INTEGER should be used instead of PETSC_NULL
829: Level: beginner
831: Concepts: ownership^of vectors
832: Concepts: vector^ownership of elements
834: @*/
835: PetscErrorCode VecGetOwnershipRange(Vec x,PetscInt *low,PetscInt *high)
836: {
842: if (low) *low = x->map.rstart;
843: if (high) *high = x->map.rend;
844: return(0);
845: }
849: /*@
850: VecSetOption - Sets an option for controling a vector's behavior.
852: Collective on Vec
854: Input Parameter:
855: + x - the vector
856: - op - the option
858: Supported Options:
859: + VEC_IGNORE_OFF_PROC_ENTRIES, which causes VecSetValues() to ignore
860: entries destined to be stored on a separate processor. This can be used
861: to eliminate the global reduction in the VecAssemblyXXXX() if you know
862: that you have only used VecSetValues() to set local elements
863: . VEC_TREAT_OFF_PROC_ENTRIES restores the treatment of off processor entries.
864: . VEC_IGNORE_NEGATIVE_INDICES, which means you can pass negative indices
865: in ix in calls to VecSetValues or VecGetValues. These rows are simply
866: ignored.
867: - VEC_TREAT_NEGATIVE_INDICES restores the treatment of negative indices in ix in
868: VecSetValues/VecGetValues.
870: Level: intermediate
872: @*/
873: PetscErrorCode VecSetOption(Vec x,VecOption op)
874: {
880: if (x->ops->setoption) {
881: (*x->ops->setoption)(x,op);
882: }
883: return(0);
884: }
888: /* Default routines for obtaining and releasing; */
889: /* may be used by any implementation */
890: PetscErrorCode VecDuplicateVecs_Default(Vec w,PetscInt m,Vec *V[])
891: {
893: PetscInt i;
898: if (m <= 0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"m must be > 0: m = %D",m);
899: PetscMalloc(m*sizeof(Vec*),V);
900: for (i=0; i<m; i++) {VecDuplicate(w,*V+i);}
901: return(0);
902: }
906: PetscErrorCode VecDestroyVecs_Default(Vec v[], PetscInt m)
907: {
909: PetscInt i;
913: if (m <= 0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"m must be > 0: m = %D",m);
914: for (i=0; i<m; i++) {VecDestroy(v[i]);}
915: PetscFree(v);
916: return(0);
917: }
921: /*@
922: VecResetArray - Resets a vector to use its default memory. Call this
923: after the use of VecPlaceArray().
925: Not Collective
927: Input Parameters:
928: . vec - the vector
930: Level: developer
932: .seealso: VecGetArray(), VecRestoreArray(), VecReplaceArray(), VecPlaceArray()
934: @*/
935: PetscErrorCode VecResetArray(Vec vec)
936: {
942: if (vec->ops->resetarray) {
943: (*vec->ops->resetarray)(vec);
944: } else {
945: SETERRQ(PETSC_ERR_SUP,"Cannot reset array in this type of vector");
946: }
947: PetscObjectStateIncrease((PetscObject)vec);
948: return(0);
949: }
953: /*@C
954: VecLoadIntoVector - Loads a vector that has been stored in binary format
955: with VecView().
957: Collective on PetscViewer
959: Input Parameters:
960: + viewer - binary file viewer, obtained from PetscViewerBinaryOpen()
961: - vec - vector to contain files values (must be of correct length)
963: Level: intermediate
965: Notes:
966: The input file must contain the full global vector, as
967: written by the routine VecView().
969: Use VecLoad() to create the vector as the values are read in
971: Notes for advanced users:
972: Most users should not need to know the details of the binary storage
973: format, since VecLoad() and VecView() completely hide these details.
974: But for anyone who's interested, the standard binary matrix storage
975: format is
976: .vb
977: int VEC_FILE_COOKIE
978: int number of rows
979: PetscScalar *values of all nonzeros
980: .ve
982: Note for Cray users, the int's stored in the binary file are 32 bit
983: integers; not 64 as they are represented in the memory, so if you
984: write your own routines to read/write these binary files from the Cray
985: you need to adjust the integer sizes that you read in, see
986: PetscBinaryRead() and PetscBinaryWrite() to see how this may be
987: done.
989: In addition, PETSc automatically does the byte swapping for
990: machines that store the bytes reversed, e.g. DEC alpha, freebsd,
991: linux, Windows and the paragon; thus if you write your own binary
992: read/write routines you have to swap the bytes; see PetscBinaryRead()
993: and PetscBinaryWrite() to see how this may be done.
995: Concepts: vector^loading from file
997: .seealso: PetscViewerBinaryOpen(), VecView(), MatLoad(), VecLoad()
998: @*/
999: PetscErrorCode VecLoadIntoVector(PetscViewer viewer,Vec vec)
1000: {
1007: if (!vec->ops->loadintovector) {
1008: SETERRQ(PETSC_ERR_SUP,"Vector does not support load");
1009: }
1010: (*vec->ops->loadintovector)(viewer,vec);
1011: PetscObjectStateIncrease((PetscObject)vec);
1012: return(0);
1013: }
1017: /*@
1018: VecReciprocal - Replaces each component of a vector by its reciprocal.
1020: Collective on Vec
1022: Input Parameter:
1023: . vec - the vector
1025: Output Parameter:
1026: . vec - the vector reciprocal
1028: Level: intermediate
1030: Concepts: vector^reciprocal
1032: @*/
1033: PetscErrorCode VecReciprocal(Vec vec)
1034: {
1040: if (vec->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1041: if (!vec->ops->reciprocal) {
1042: SETERRQ(PETSC_ERR_SUP,"Vector does not support reciprocal operation");
1043: }
1044: (*vec->ops->reciprocal)(vec);
1045: PetscObjectStateIncrease((PetscObject)vec);
1046: return(0);
1047: }
1051: PetscErrorCode VecSetOperation(Vec vec,VecOperation op, void (*f)(void))
1052: {
1055: /* save the native version of the viewer */
1056: if (op == VECOP_VIEW && !vec->ops->viewnative) {
1057: vec->ops->viewnative = vec->ops->view;
1058: }
1059: (((void(**)(void))vec->ops)[(int)op]) = f;
1060: return(0);
1061: }
1066: /*@
1067: VecStashSetInitialSize - sets the sizes of the vec-stash, that is
1068: used during the assembly process to store values that belong to
1069: other processors.
1071: Collective on Vec
1073: Input Parameters:
1074: + vec - the vector
1075: . size - the initial size of the stash.
1076: - bsize - the initial size of the block-stash(if used).
1078: Options Database Keys:
1079: + -vecstash_initial_size <size> or <size0,size1,...sizep-1>
1080: - -vecstash_block_initial_size <bsize> or <bsize0,bsize1,...bsizep-1>
1082: Level: intermediate
1084: Notes:
1085: The block-stash is used for values set with VecSetValuesBlocked() while
1086: the stash is used for values set with VecSetValues()
1088: Run with the option -info and look for output of the form
1089: VecAssemblyBegin_MPIXXX:Stash has MM entries, uses nn mallocs.
1090: to determine the appropriate value, MM, to use for size and
1091: VecAssemblyBegin_MPIXXX:Block-Stash has BMM entries, uses nn mallocs.
1092: to determine the value, BMM to use for bsize
1094: Concepts: vector^stash
1095: Concepts: stash^vector
1097: .seealso: VecSetBlockSize(), VecSetValues(), VecSetValuesBlocked(), VecStashView()
1099: @*/
1100: PetscErrorCode VecStashSetInitialSize(Vec vec,PetscInt size,PetscInt bsize)
1101: {
1106: VecStashSetInitialSize_Private(&vec->stash,size);
1107: VecStashSetInitialSize_Private(&vec->bstash,bsize);
1108: return(0);
1109: }
1113: /*@
1114: VecConjugate - Conjugates a vector.
1116: Collective on Vec
1118: Input Parameters:
1119: . x - the vector
1121: Level: intermediate
1123: Concepts: vector^conjugate
1125: @*/
1126: PetscErrorCode VecConjugate(Vec x)
1127: {
1128: #ifdef PETSC_USE_COMPLEX
1134: if (x->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1135: (*x->ops->conjugate)(x);
1136: /* we need to copy norms here */
1137: PetscObjectStateIncrease((PetscObject)x);
1138: return(0);
1139: #else
1140: return(0);
1141: #endif
1142: }
1146: /*@
1147: VecPointwiseMult - Computes the componentwise multiplication w = x*y.
1149: Collective on Vec
1151: Input Parameters:
1152: . x, y - the vectors
1154: Output Parameter:
1155: . w - the result
1157: Level: advanced
1159: Notes: any subset of the x, y, and w may be the same vector.
1161: Concepts: vector^pointwise multiply
1163: .seealso: VecPointwiseDivide(), VecPointwiseMax(), VecPointwiseMin(), VecPointwiseMaxAbs(), VecMaxPointwiseDivide()
1164: @*/
1165: PetscErrorCode VecPointwiseMult(Vec w, Vec x,Vec y)
1166: {
1178: if (x->map.N != y->map.N || x->map.N != w->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
1179: if (x->map.n != y->map.n || x->map.n != w->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
1182: (*w->ops->pointwisemult)(w,x,y);
1184: PetscObjectStateIncrease((PetscObject)w);
1185: return(0);
1186: }
1190: /*@
1191: VecSetRandom - Sets all components of a vector to random numbers.
1193: Collective on Vec
1195: Input Parameters:
1196: + x - the vector
1197: - rctx - the random number context, formed by PetscRandomCreate(), or PETSC_NULL and
1198: it will create one internally.
1200: Output Parameter:
1201: . x - the vector
1203: Example of Usage:
1204: .vb
1205: PetscRandomCreate(PETSC_COMM_WORLD,&rctx);
1206: VecSetRandom(x,rctx);
1207: PetscRandomDestroy(rctx);
1208: .ve
1210: Level: intermediate
1212: Concepts: vector^setting to random
1213: Concepts: random^vector
1215: .seealso: VecSet(), VecSetValues(), PetscRandomCreate(), PetscRandomDestroy()
1216: @*/
1217: PetscErrorCode VecSetRandom(Vec x,PetscRandom rctx)
1218: {
1220: PetscRandom randObj = PETSC_NULL;
1226: if (x->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1228: if (!rctx) {
1229: MPI_Comm comm;
1230: PetscObjectGetComm((PetscObject)x,&comm);
1231: PetscRandomCreate(comm,&randObj);
1232: PetscRandomSetFromOptions(randObj);
1233: rctx = randObj;
1234: }
1237: (*x->ops->setrandom)(x,rctx);
1239:
1240: if (randObj) {
1241: PetscRandomDestroy(randObj);
1242: }
1243: PetscObjectStateIncrease((PetscObject)x);
1244: return(0);
1245: }
1247: /*@
1248: VecZeroEntries - puts a 0.0 in each element of a vector
1250: Collective on Vec
1252: Input Parameter:
1253: . vec - The vector
1255: Level: beginner
1257: .keywords: Vec, set, options, database
1258: .seealso: VecCreate(), VecSetOptionsPrefix(), VecSet(), VecSetValues()
1259: @*/
1260: PetscErrorCode VecZeroEntries (Vec vec)
1261: {
1264: VecSet(vec,0);
1265: return(0);
1266: }
1270: /*
1271: VecSetTypeFromOptions_Private - Sets the type of vector from user options. Defaults to a PETSc sequential vector on one
1272: processor and a PETSc MPI vector on more than one processor.
1274: Collective on Vec
1276: Input Parameter:
1277: . vec - The vector
1279: Level: intermediate
1281: .keywords: Vec, set, options, database, type
1282: .seealso: VecSetFromOptions(), VecSetType()
1283: */
1284: static PetscErrorCode VecSetTypeFromOptions_Private(Vec vec)
1285: {
1286: PetscTruth opt;
1287: const char *defaultType;
1288: char typeName[256];
1289: PetscMPIInt size;
1293: if (vec->type_name) {
1294: defaultType = vec->type_name;
1295: } else {
1296: MPI_Comm_size(vec->comm, &size);
1297: if (size > 1) {
1298: defaultType = VECMPI;
1299: } else {
1300: defaultType = VECSEQ;
1301: }
1302: }
1304: if (!VecRegisterAllCalled) {
1305: VecRegisterAll(PETSC_NULL);
1306: }
1307: PetscOptionsList("-vec_type","Vector type","VecSetType",VecList,defaultType,typeName,256,&opt);
1308: if (opt) {
1309: VecSetType(vec, typeName);
1310: } else {
1311: VecSetType(vec, defaultType);
1312: }
1313: return(0);
1314: }
1318: /*@
1319: VecSetFromOptions - Configures the vector from the options database.
1321: Collective on Vec
1323: Input Parameter:
1324: . vec - The vector
1326: Notes: To see all options, run your program with the -help option, or consult the users manual.
1327: Must be called after VecCreate() but before the vector is used.
1329: Level: beginner
1331: Concepts: vectors^setting options
1332: Concepts: vectors^setting type
1334: .keywords: Vec, set, options, database
1335: .seealso: VecCreate(), VecSetOptionsPrefix()
1336: @*/
1337: PetscErrorCode VecSetFromOptions(Vec vec)
1338: {
1344: PetscOptionsBegin(vec->comm, vec->prefix, "Vector options", "Vec");
1345: /* Handle vector type options */
1346: VecSetTypeFromOptions_Private(vec);
1348: /* Handle specific vector options */
1349: if (vec->ops->setfromoptions) {
1350: (*vec->ops->setfromoptions)(vec);
1351: }
1352: PetscOptionsEnd();
1354: VecViewFromOptions(vec, vec->name);
1355: return(0);
1356: }
1360: /*@
1361: VecSetSizes - Sets the local and global sizes, and checks to determine compatibility
1363: Collective on Vec
1365: Input Parameters:
1366: + v - the vector
1367: . n - the local size (or PETSC_DECIDE to have it set)
1368: - N - the global size (or PETSC_DECIDE)
1370: Notes:
1371: n and N cannot be both PETSC_DECIDE
1372: If one processor calls this with N of PETSC_DECIDE then all processors must, otherwise the program will hang.
1374: Level: intermediate
1376: .seealso: VecGetSize(), PetscSplitOwnership()
1377: @*/
1378: PetscErrorCode VecSetSizes(Vec v, PetscInt n, PetscInt N)
1379: {
1382: if (N > 0 && n > N) SETERRQ2(PETSC_ERR_ARG_INCOMP,"Local size %D cannot be larger than global size %D",n,N);
1383: 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);
1384: v->map.n = n;
1385: v->map.N = N;
1386: return(0);
1387: }
1391: /*@
1392: VecSetBlockSize - Sets the blocksize for future calls to VecSetValuesBlocked()
1393: and VecSetValuesBlockedLocal().
1395: Collective on Vec
1397: Input Parameter:
1398: + v - the vector
1399: - bs - the blocksize
1401: Notes:
1402: All vectors obtained by VecDuplicate() inherit the same blocksize.
1404: Level: advanced
1406: .seealso: VecSetValuesBlocked(), VecSetLocalToGlobalMappingBlock(), VecGetBlockSize()
1408: Concepts: block size^vectors
1409: @*/
1410: PetscErrorCode VecSetBlockSize(Vec v,PetscInt bs)
1411: {
1414: if (bs <= 0) bs = 1;
1415: if (bs == v->map.bs) return(0);
1416: 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);
1417: if (v->map.n != -1 && v->map.n % bs) SETERRQ2(PETSC_ERR_ARG_OUTOFRANGE,"Local vector length not divisible by blocksize %D %D\n\
1418: Try setting blocksize before setting the vector type",v->map.n,bs);
1419:
1420: v->map.bs = bs;
1421: v->bstash.bs = bs; /* use the same blocksize for the vec's block-stash */
1422: return(0);
1423: }
1427: /*@
1428: VecGetBlockSize - Gets the blocksize for the vector, i.e. what is used for VecSetValuesBlocked()
1429: and VecSetValuesBlockedLocal().
1431: Collective on Vec
1433: Input Parameter:
1434: . v - the vector
1436: Output Parameter:
1437: . bs - the blocksize
1439: Notes:
1440: All vectors obtained by VecDuplicate() inherit the same blocksize.
1442: Level: advanced
1444: .seealso: VecSetValuesBlocked(), VecSetLocalToGlobalMappingBlock(), VecSetBlockSize()
1446: Concepts: vector^block size
1447: Concepts: block^vector
1449: @*/
1450: PetscErrorCode VecGetBlockSize(Vec v,PetscInt *bs)
1451: {
1455: *bs = v->map.bs;
1456: return(0);
1457: }
1461: /*@
1462: VecValid - Checks whether a vector object is valid.
1464: Not Collective
1466: Input Parameter:
1467: . v - the object to check
1469: Output Parameter:
1470: . flg - flag indicating vector status, either
1471: PETSC_TRUE if vector is valid, or PETSC_FALSE otherwise.
1473: Level: developer
1475: @*/
1476: PetscErrorCode VecValid(Vec v,PetscTruth *flg)
1477: {
1480: if (!v) *flg = PETSC_FALSE;
1481: else if (v->cookie != VEC_COOKIE) *flg = PETSC_FALSE;
1482: else *flg = PETSC_TRUE;
1483: return(0);
1484: }
1488: /*@C
1489: VecSetOptionsPrefix - Sets the prefix used for searching for all
1490: Vec options in the database.
1492: Collective on Vec
1494: Input Parameter:
1495: + v - the Vec context
1496: - prefix - the prefix to prepend to all option names
1498: Notes:
1499: A hyphen (-) must NOT be given at the beginning of the prefix name.
1500: The first character of all runtime options is AUTOMATICALLY the hyphen.
1502: Level: advanced
1504: .keywords: Vec, set, options, prefix, database
1506: .seealso: VecSetFromOptions()
1507: @*/
1508: PetscErrorCode VecSetOptionsPrefix(Vec v,const char prefix[])
1509: {
1514: PetscObjectSetOptionsPrefix((PetscObject)v,prefix);
1515: return(0);
1516: }
1520: /*@C
1521: VecAppendOptionsPrefix - Appends to the prefix used for searching for all
1522: Vec options in the database.
1524: Collective on Vec
1526: Input Parameters:
1527: + v - the Vec context
1528: - prefix - the prefix to prepend to all option names
1530: Notes:
1531: A hyphen (-) must NOT be given at the beginning of the prefix name.
1532: The first character of all runtime options is AUTOMATICALLY the hyphen.
1534: Level: advanced
1536: .keywords: Vec, append, options, prefix, database
1538: .seealso: VecGetOptionsPrefix()
1539: @*/
1540: PetscErrorCode VecAppendOptionsPrefix(Vec v,const char prefix[])
1541: {
1543:
1546: PetscObjectAppendOptionsPrefix((PetscObject)v,prefix);
1547: return(0);
1548: }
1552: /*@C
1553: VecGetOptionsPrefix - Sets the prefix used for searching for all
1554: Vec options in the database.
1556: Not Collective
1558: Input Parameter:
1559: . v - the Vec context
1561: Output Parameter:
1562: . prefix - pointer to the prefix string used
1564: Notes: On the fortran side, the user should pass in a string 'prefix' of
1565: sufficient length to hold the prefix.
1567: Level: advanced
1569: .keywords: Vec, get, options, prefix, database
1571: .seealso: VecAppendOptionsPrefix()
1572: @*/
1573: PetscErrorCode VecGetOptionsPrefix(Vec v,const char *prefix[])
1574: {
1579: PetscObjectGetOptionsPrefix((PetscObject)v,prefix);
1580: return(0);
1581: }
1585: /*@
1586: VecSetUp - Sets up the internal vector data structures for the later use.
1588: Collective on Vec
1590: Input Parameters:
1591: . v - the Vec context
1593: Notes:
1594: For basic use of the Vec classes the user need not explicitly call
1595: VecSetUp(), since these actions will happen automatically.
1597: Level: advanced
1599: .keywords: Vec, setup
1601: .seealso: VecCreate(), VecDestroy()
1602: @*/
1603: PetscErrorCode VecSetUp(Vec v)
1604: {
1609: VecSetFromOptions(v);
1610: return(0);
1611: }
1613: /*
1614: These currently expose the PetscScalar/PetscReal in updating the
1615: cached norm. If we push those down into the implementation these
1616: will become independent of PetscScalar/PetscReal
1617: */
1621: /*@
1622: VecCopy - Copies a vector.
1624: Collective on Vec
1626: Input Parameter:
1627: . x - the vector
1629: Output Parameter:
1630: . y - the copy
1632: Notes:
1633: For default parallel PETSc vectors, both x and y must be distributed in
1634: the same manner; local copies are done.
1636: Level: beginner
1638: .seealso: VecDuplicate()
1639: @*/
1640: PetscErrorCode VecCopy(Vec x,Vec y)
1641: {
1642: PetscTruth flgs[4];
1643: PetscReal norms[4] = {0.0,0.0,0.0,0.0};
1645: PetscInt i;
1653: if (x == y) return(0);
1654: if (x->map.N != y->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
1655: if (x->map.n != y->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
1658: (*x->ops->copy)(x,y);
1661: /*
1662: * Update cached data
1663: */
1664: /* in general we consider this object touched */
1665: PetscObjectStateIncrease((PetscObject)y);
1667: for (i=0; i<4; i++) {
1668: PetscObjectComposedDataGetReal((PetscObject)x,NormIds[i],norms[i],flgs[i]);
1669: }
1670: for (i=0; i<4; i++) {
1671: if (flgs[i]) {
1672: PetscObjectComposedDataSetReal((PetscObject)y,NormIds[i],norms[i]);
1673: }
1674: }
1677: return(0);
1678: }
1682: /*@
1683: VecSwap - Swaps the vectors x and y.
1685: Collective on Vec
1687: Input Parameters:
1688: . x, y - the vectors
1690: Level: advanced
1692: Concepts: vector^swapping values
1694: @*/
1695: PetscErrorCode VecSwap(Vec x,Vec y)
1696: {
1697: PetscReal normxs[4]={0.0,0.0,0.0,0.0},normys[4]={0.0,0.0,0.0,0.0};
1698: PetscTruth flgxs[4],flgys[4];
1700: PetscInt i;
1708: if (x->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1709: if (y->stash.insertmode != NOT_SET_VALUES) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled vector");
1710: if (x->map.N != y->map.N) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector global lengths");
1711: if (x->map.n != y->map.n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Incompatible vector local lengths");
1714: (*x->ops->swap)(x,y);
1716: /* See if we have cached norms */
1717: for (i=0; i<4; i++) {
1718: PetscObjectComposedDataGetReal((PetscObject)x,NormIds[i],normxs[i],flgxs[i]);
1719: PetscObjectComposedDataGetReal((PetscObject)y,NormIds[i],normys[i],flgys[i]);
1720: }
1721: for (i=0; i<4; i++) {
1722: if (flgxs[i]) {
1723: PetscObjectComposedDataSetReal((PetscObject)y,NormIds[i],normxs[i]);
1724: }
1725: if (flgys[i]) {
1726: PetscObjectComposedDataSetReal((PetscObject)x,NormIds[i],normys[i]);
1727: }
1728: }
1730: return(0);
1731: }
1735: /*@
1736: VecStashView - Prints the entries in the vector stash and block stash.
1738: Collective on Vec
1740: Input Parameters:
1741: + v - the vector
1742: - viewer - the viewer
1744: Level: advanced
1746: Concepts: vector^stash
1747: Concepts: stash^vector
1749: .seealso: VecSetBlockSize(), VecSetValues(), VecSetValuesBlocked()
1751: @*/
1752: PetscErrorCode VecStashView(Vec v,PetscViewer viewer)
1753: {
1755: PetscMPIInt rank;
1756: PetscInt i,j;
1757: PetscTruth match;
1758: VecStash *s;
1759: PetscScalar val;
1766: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&match);
1767: if (!match) SETERRQ1(PETSC_ERR_SUP,"Stash viewer only works with ASCII viewer not %s\n",((PetscObject)v)->type_name);
1768: PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);
1769: MPI_Comm_rank(v->comm,&rank);
1770: s = &v->bstash;
1772: /* print block stash */
1773: PetscViewerASCIISynchronizedPrintf(viewer,"[%d]Vector Block stash size %D block size %D\n",rank,s->n,s->bs);
1774: for (i=0; i<s->n; i++) {
1775: PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Element %D ",rank,s->idx[i]);
1776: for (j=0; j<s->bs; j++) {
1777: val = s->array[i*s->bs+j];
1778: #if defined(PETSC_USE_COMPLEX)
1779: PetscViewerASCIISynchronizedPrintf(viewer,"(%18.16e %18.16e) ",PetscRealPart(val),PetscImaginaryPart(val));
1780: #else
1781: PetscViewerASCIISynchronizedPrintf(viewer,"%18.16e ",val);
1782: #endif
1783: }
1784: PetscViewerASCIISynchronizedPrintf(viewer,"\n");
1785: }
1786: PetscViewerFlush(viewer);
1788: s = &v->stash;
1790: /* print basic stash */
1791: PetscViewerASCIISynchronizedPrintf(viewer,"[%d]Vector stash size %D\n",rank,s->n);
1792: for (i=0; i<s->n; i++) {
1793: val = s->array[i];
1794: #if defined(PETSC_USE_COMPLEX)
1795: PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Element %D (%18.16e %18.16e) ",rank,s->idx[i],PetscRealPart(val),PetscImaginaryPart(val));
1796: #else
1797: PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Element %D %18.16e\n",rank,s->idx[i],val);
1798: #endif
1799: }
1800: PetscViewerFlush(viewer);
1802: PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);
1803: return(0);
1804: }