Actual source code: xmon.c
1: /*$Id: xmon.c,v 1.50 2001/04/10 19:36:24 bsmith Exp $*/
3: #include src/sles/ksp/kspimpl.h
5: #undef __FUNCT__
7: /*@C
8: KSPLGMonitorCreate - Creates a line graph context for use with
9: KSP to monitor convergence of preconditioned residual norms.
11: Collective on KSP
13: Input Parameters:
14: + host - the X display to open, or null for the local machine
15: . label - the title to put in the title bar
16: . x, y - the screen coordinates of the upper left coordinate of
17: the window
18: - m, n - the screen width and height in pixels
20: Output Parameter:
21: . draw - the drawing context
23: Options Database Key:
24: . -ksp_xmonitor - Sets line graph monitor
26: Notes:
27: Use KSPLGMonitorDestroy() to destroy this line graph; do not use PetscDrawLGDestroy().
29: Level: intermediate
31: .keywords: KSP, monitor, line graph, residual, create
33: .seealso: KSPLGMonitorDestroy(), KSPSetMonitor(), KSPLGTrueMonitorCreate()
34: @*/
35: int KSPLGMonitorCreate(char *host,char *label,int x,int y,int m,int n,PetscDrawLG *draw)
36: {
37: PetscDraw win;
38: int ierr;
41: PetscDrawCreate(PETSC_COMM_SELF,host,label,x,y,m,n,&win);
42: PetscDrawSetType(win,PETSC_DRAW_X);
43: PetscDrawLGCreate(win,1,draw);
44: PetscLogObjectParent(*draw,win);
45: return(0);
46: }
48: #undef __FUNCT__
50: int KSPLGMonitor(KSP ksp,int n,PetscReal rnorm,void *monctx)
51: {
52: PetscDrawLG lg = (PetscDrawLG) monctx;
53: int ierr;
54: PetscReal x,y;
57: if (!monctx) {
58: MPI_Comm comm;
59: PetscViewer viewer;
61: ierr = PetscObjectGetComm((PetscObject)ksp,&comm);
62: viewer = PETSC_VIEWER_DRAW_(comm);
63: ierr = PetscViewerDrawGetDrawLG(viewer,0,&lg);
64: }
66: if (!n) {PetscDrawLGReset(lg);}
67: x = (PetscReal) n;
68: if (rnorm > 0.0) y = log10(rnorm); else y = -15.0;
69: PetscDrawLGAddPoint(lg,&x,&y);
70: if (n < 20 || !(n % 5)) {
71: PetscDrawLGDraw(lg);
72: }
73: return(0);
74: }
75:
76: #undef __FUNCT__
78: /*@C
79: KSPLGMonitorDestroy - Destroys a line graph context that was created
80: with KSPLGMonitorCreate().
82: Collective on KSP
84: Input Parameter:
85: . draw - the drawing context
87: Level: intermediate
89: .keywords: KSP, monitor, line graph, destroy
91: .seealso: KSPLGMonitorCreate(), KSPLGTrueMonitorDestroy(), KSPSetMonitor()
92: @*/
93: int KSPLGMonitorDestroy(PetscDrawLG drawlg)
94: {
95: PetscDraw draw;
96: int ierr;
99: PetscDrawLGGetDraw(drawlg,&draw);
100: if (draw) { PetscDrawDestroy(draw);}
101: PetscDrawLGDestroy(drawlg);
102: return(0);
103: }
105: #undef __FUNCT__
107: /*@C
108: KSPLGTrueMonitorCreate - Creates a line graph context for use with
109: KSP to monitor convergence of true residual norms (as opposed to
110: preconditioned residual norms).
112: Collective on KSP
114: Input Parameters:
115: + host - the X display to open, or null for the local machine
116: . label - the title to put in the title bar
117: . x, y - the screen coordinates of the upper left coordinate of
118: the window
119: - m, n - the screen width and height in pixels
121: Output Parameter:
122: . draw - the drawing context
124: Options Database Key:
125: . -ksp_xtruemonitor - Sets true line graph monitor
127: Notes:
128: Use KSPLGTrueMonitorDestroy() to destroy this line graph, not
129: PetscDrawLGDestroy().
131: Level: intermediate
133: .keywords: KSP, monitor, line graph, residual, create, true
135: .seealso: KSPLGMonitorDestroy(), KSPSetMonitor(), KSPDefaultMonitor()
136: @*/
137: int KSPLGTrueMonitorCreate(MPI_Comm comm,char *host,char *label,int x,int y,int m,int n,PetscDrawLG *draw)
138: {
139: PetscDraw win;
140: int ierr,rank;
143: MPI_Comm_rank(comm,&rank);
144: if (rank) { *draw = 0; return(0);}
146: PetscDrawCreate(PETSC_COMM_SELF,host,label,x,y,m,n,&win);
147: PetscDrawSetType(win,PETSC_DRAW_X);
148: PetscDrawLGCreate(win,2,draw);
149: PetscLogObjectParent(*draw,win);
150: return(0);
151: }
153: #undef __FUNCT__
155: int KSPLGTrueMonitor(KSP ksp,int n,PetscReal rnorm,void *monctx)
156: {
157: PetscDrawLG lg = (PetscDrawLG) monctx;
158: PetscReal x[2],y[2],scnorm;
159: int ierr,rank;
160: Vec resid,work;
163: if (!monctx) {
164: MPI_Comm comm;
165: PetscViewer viewer;
167: ierr = PetscObjectGetComm((PetscObject)ksp,&comm);
168: viewer = PETSC_VIEWER_DRAW_(comm);
169: ierr = PetscViewerDrawGetDrawLG(viewer,0,&lg);
170: }
172: MPI_Comm_rank(ksp->comm,&rank);
173: if (!rank) {
174: if (!n) {PetscDrawLGReset(lg);}
175: x[0] = x[1] = (PetscReal) n;
176: if (rnorm > 0.0) y[0] = log10(rnorm); else y[0] = -15.0;
177: }
179: VecDuplicate(ksp->vec_rhs,&work);
180: KSPBuildResidual(ksp,0,work,&resid);
181: VecNorm(resid,NORM_2,&scnorm);
182: VecDestroy(work);
184: if (!rank) {
185: if (scnorm > 0.0) y[1] = log10(scnorm); else y[1] = -15.0;
186: PetscDrawLGAddPoint(lg,x,y);
187: if (n <= 20 || (n % 3)) {
188: PetscDrawLGDraw(lg);
189: }
190: }
191: return(0);
192: }
193:
194: #undef __FUNCT__
196: /*@C
197: KSPLGTrueMonitorDestroy - Destroys a line graph context that was created
198: with KSPLGTrueMonitorCreate().
200: Collective on KSP
202: Input Parameter:
203: . draw - the drawing context
205: Level: intermediate
207: .keywords: KSP, monitor, line graph, destroy, true
209: .seealso: KSPLGTrueMonitorCreate(), KSPSetMonitor()
210: @*/
211: int KSPLGTrueMonitorDestroy(PetscDrawLG drawlg)
212: {
213: int ierr;
214: PetscDraw draw;
217: PetscDrawLGGetDraw(drawlg,&draw);
218: PetscDrawDestroy(draw);
219: PetscDrawLGDestroy(drawlg);
220: return(0);
221: }