Actual source code: plogmpe.c

  1: /*$Id: plogmpe.c,v 1.57 2001/04/10 19:34:39 bsmith Exp $*/
  2: /*
  3:       PETSc code to log PETSc events using MPE
  4: */
  5: #include "petsc.h"        /*I    "petsc.h"   I*/
  6: #if defined(PETSC_USE_LOG) && defined (PETSC_HAVE_MPE)
  7: #include "petscsys.h"
  8: #include "mpe.h"

 10: /* 
 11:    Make sure that all events used by PETSc have the
 12:    corresponding flags set here: 
 13:      1 - activated for MPE logging
 14:      0 - not activated for MPE logging
 15:  */
 16: int PetscLogEventMPEFlags[] = {  1,1,1,1,1,  /* 0 - 24*/
 17:                         1,1,1,1,1,
 18:                         1,1,1,1,1,
 19:                         1,1,1,1,1,
 20:                         1,1,1,1,1,
 21:                         0,1,1,1,1,  /* 25 -49 */
 22:                         1,1,1,1,1,
 23:                         1,1,0,0,0,
 24:                         1,1,1,1,1,
 25:                         1,1,1,1,1,
 26:                         1,1,1,1,1, /* 50 - 74 */
 27:                         1,1,1,1,1,
 28:                         1,1,1,1,0,
 29:                         0,0,0,0,0,
 30:                         1,1,1,0,1,
 31:                         1,1,1,1,1, /* 75 - 99 */
 32:                         1,1,1,1,1,
 33:                         1,1,0,0,0,
 34:                         1,1,1,1,0,
 35:                         0,0,0,0,0,
 36:                         1,0,0,0,0, /* 100 - 124 */
 37:                         0,0,0,0,0,
 38:                         0,0,0,0,0,
 39:                         0,0,0,0,0,
 40:                         0,0,0,0,0,
 41:                         0,0,0,0,0, /* 125 - 149 */
 42:                         0,0,0,0,0,
 43:                         0,0,0,0,0,
 44:                         0,0,0,0,0,
 45:                         0,0,0,0,0,
 46:                         0,0,0,0,0, /* 150 - 174 */
 47:                         0,0,0,0,0,
 48:                         0,0,0,0,0,
 49:                         0,0,0,0,0,
 50:                         0,0,0,0,0,
 51:                         0,0,0,0,0,
 52:                         0,0,0,0,0, /* 175 - 199 */
 53:                         0,0,0,0,0,
 54:                         0,0,0,0,0,
 55:                         0,0,0,0,0,
 56:                         0,0,0,0,0};

 58: /* For Colors, check out the file  /usr/local/X11/lib/rgb.txt */

 60: char *(PetscLogEventColor[]) = {"OliveDrab:      ",
 61:                             "BlueViolet:     ",
 62:                             "CadetBlue:      ",
 63:                             "CornflowerBlue: ",
 64:                             "DarkGoldenrod:  ",
 65:                             "DarkGreen:      ",
 66:                             "DarkKhaki:      ",
 67:                             "DarkOliveGreen: ",
 68:                             "DarkOrange:     ",
 69:                             "DarkOrchid:     ",
 70:                             "DarkSeaGreen:   ",
 71:                             "DarkSlateGray:  ",
 72:                             "DarkTurquoise:  ",
 73:                             "DeepPink:       ",
 74:                             "DarkKhaki:      ",
 75:                             "DimGray:        ",
 76:                             "DodgerBlue:     ",
 77:                             "GreenYellow:    ",
 78:                             "HotPink:        ",
 79:                             "IndianRed:      ",
 80:                             "LavenderBlush:  ",
 81:                             "LawnGreen:      ",
 82:                             "LemonChiffon:   ",
 83:                             "LightCoral:     ",
 84:                             "LightCyan:      ",
 85:                             "LightPink:      ",
 86:                             "LightSalmon:    ",
 87:                             "LightSlateGray: ",
 88:                             "LightYellow:    ",
 89:                             "LimeGreen:      ",
 90:                             "MediumPurple:   ",
 91:                             "MediumSeaGreen: ",
 92:                             "MediumSlateBlue:",
 93:                             "MidnightBlue:   ",
 94:                             "MintCream:      ",
 95:                             "MistyRose:      ",
 96:                             "NavajoWhite:    ",
 97:                             "NavyBlue:       ",
 98:                             "OliveDrab:      ",
 99:                             "OrangeRed:      ",
100:                             "PaleGoldenrod:  ",
101:                             "PaleVioletRed:  ",
102:                             "PapayaWhip:     ",
103:                             "PeachPuff:      ",
104:                             "RosyBrown:      ",
105:                             "SaddleBrown:    ",
106:                             "OrangeRed:      ",
107:                             "SteelBlue:      ",
108:                             "VioletRed:      ",
109:                             "beige:          ",
110:                             "chocolate:      ",
111:                             "coral:          ",
112:                             "gold:           ",
113:                             "magenta:        ",
114:                             "maroon:         ",
115:                             "orchid:         ",
116:                             "pink:           ",
117:                             "plum:           ",
118:                             "red:            ",
119:                             "tan:            ",
120:                             "tomato:         ",
121:                             "violet:         ",
122:                             "wheat:          ",
123:                             "yellow:         ",
124:                             "AliceBlue:      ",
125:                             "BlueViolet:     ",
126:                             "CadetBlue:      ",
127:                             "CornflowerBlue: ",
128:                             "DarkGoldenrod:  ",
129:                             "DarkGreen:      ",
130:                             "DarkKhaki:      ",
131:                             "DarkOliveGreen: ",
132:                             "DarkOrange:     ",
133:                             "DarkOrchid:     ",
134:                             "DarkSeaGreen:   ",
135:                             "DarkSlateGray:  ",
136:                             "DarkTurquoise:  ",
137:                             "DeepPink:       ",
138:                             "DarkKhaki:      ",
139:                             "DimGray:        ",
140:                             "DodgerBlue:     ",
141:                             "GreenYellow:    ",
142:                             "HotPink:        ",
143:                             "IndianRed:      ",
144:                             "LavenderBlush:  ",
145:                             "LawnGreen:      ",
146:                             "LemonChiffon:   ",
147:                             "LightCoral:     ",
148:                             "LightCyan:      ",
149:                             "LightPink:      ",
150:                             "LightSalmon:    ",
151:                             "LightSlateGray: ",
152:                             "LightYellow:    ",
153:                             "LimeGreen:      ",
154:                             "MediumPurple:   ",
155:                             "MediumSeaGreen: ",
156:                             "MediumSlateBlue:",
157:                             "MidnightBlue:   ",
158:                             "MintCream:      ",
159:                             "MistyRose:      ",
160:                             "NavajoWhite:    ",
161:                             "NavyBlue:       ",
162:                             "OliveDrab:      ",
163:                             "OrangeRed:      ",
164:                             "PaleGoldenrod:  ",
165:                             "PaleVioletRed:  ",
166:                             "PapayaWhip:     ",
167:                             "PeachPuff:      ",
168:                             "RosyBrown:      ",
169:                             "SaddleBrown:    ",
170:                             "OrangeRed:      ",
171:                             "SteelBlue:      ",
172:                             "VioletRed:      ",
173:                             "beige:          ",
174:                             "chocolate:      ",
175:                             "coral:          ",
176:                             "gold:           ",
177:                             "magenta:        ",
178:                             "maroon:         ",
179:                             "orchid:         ",
180:                             "pink:           ",
181:                             "AliceBlue:      ",
182:                             "BlueViolet:     ",
183:                             "CadetBlue:      ",
184:                             "CornflowerBlue: ",
185:                             "DarkGoldenrod:  ",
186:                             "DarkGreen:      ",
187:                             "DarkKhaki:      ",
188:                             "DarkOliveGreen: ",
189:                             "DarkOrange:     ",
190:                             "DarkOrchid:     ",
191:                             "DarkSeaGreen:   ",
192:                             "DarkSlateGray:  ",
193:                             "DarkTurquoise:  ",
194:                             "DeepPink:       ",
195:                             "DarkKhaki:      ",
196:                             "DimGray:        ",
197:                             "DodgerBlue:     ",
198:                             "GreenYellow:    ",
199:                             "HotPink:        ",
200:                             "IndianRed:      ",
201:                             "LavenderBlush:  ",
202:                             "LawnGreen:      ",
203:                             "LemonChiffon:   ",
204:                             "LightCoral:     ",
205:                             "LightCyan:      ",
206:                             "LightPink:      ",
207:                             "LightSalmon:    ",
208:                             "LightSlateGray: ",
209:                             "LightYellow:    ",
210:                             "LimeGreen:      ",
211:                             "MediumPurple:   ",
212:                             "MediumSeaGreen: ",
213:                             "MediumSlateBlue:",
214:                             "MidnightBlue:   ",
215:                             "MintCream:      ",
216:                             "MistyRose:      ",
217:                             "NavajoWhite:    ",
218:                             "NavyBlue:       ",
219:                             "OliveDrab:      ",
220:                             "OrangeRed:      ",
221:                             "PaleGoldenrod:  ",
222:                             "PaleVioletRed:  ",
223:                             "PapayaWhip:     ",
224:                             "PeachPuff:      ",
225:                             "RosyBrown:      ",
226:                             "SaddleBrown:    ",
227:                             "OrangeRed:      ",
228:                             "SteelBlue:      ",
229:                             "VioletRed:      ",
230:                             "beige:          ",
231:                             "chocolate:      ",
232:                             "coral:          ",
233:                             "gold:           ",
234:                             "magenta:        ",
235:                             "maroon:         ",
236:                             "orchid:         ",
237:                             "pink:           ",
238:                             "plum:           ",
239:                             "red:            ",
240:                             "tan:            ",
241:                             "tomato:         ",
242:                             "violet:         ",
243:                             "wheat:          ",
244:                             "yellow:         ",
245:                             "AliceBlue:      ",
246:                             "BlueViolet:     ",
247:                             "CadetBlue:      ",
248:                             "CornflowerBlue: ",
249:                             "DarkGoldenrod:  ",
250:                             "DarkGreen:      ",
251:                             "DarkKhaki:      ",
252:                             "DarkOliveGreen: ",
253:                             "DarkOrange:     ",
254:                             "DarkOrchid:     ",
255:                             "DarkSeaGreen:   ",
256:                             "DarkSlateGray:  ",
257:                             "DarkTurquoise:  ",
258:                             "DeepPink:       ",
259:                             "DarkKhaki:      "};

261: /*
262:     Indicates if a color was malloced for each event, or if it is
263:   the default color. Used to ensure malloced space is properly freed.
264: */
265: int PetscLogEventColorMalloced[] = {0,0,0,0,0,0,0,0,0,0,
266:                                 0,0,0,0,0,0,0,0,0,0,
267:                                 0,0,0,0,0,0,0,0,0,0,
268:                                 0,0,0,0,0,0,0,0,0,0,
269:                                 0,0,0,0,0,0,0,0,0,0,
270:                                 0,0,0,0,0,0,0,0,0,0,
271:                                 0,0,0,0,0,0,0,0,0,0,
272:                                 0,0,0,0,0,0,0,0,0,0,
273:                                 0,0,0,0,0,0,0,0,0,0,
274:                                 0,0,0,0,0,0,0,0,0,0,
275:                                 0,0,0,0,0,0,0,0,0,0,
276:                                 0,0,0,0,0,0,0,0,0,0,
277:                                 0,0,0,0,0,0,0,0,0,0,
278:                                 0,0,0,0,0,0,0,0,0,0,
279:                                 0,0,0,0,0,0,0,0,0,0,
280:                                 0,0,0,0,0,0,0,0,0,0,
281:                                 0,0,0,0,0,0,0,0,0,0,
282:                                 0,0,0,0,0,0,0,0,0,0,
283:                                 0,0,0,0,0,0,0,0,0,0,
284:                                 0,0,0,0,0,0,0,0,0,0};

286: PetscTruth UseMPE = PETSC_FALSE;
287: PetscTruth PetscBeganMPE = PETSC_FALSE;
288: extern char *PetscLogEventName[];

290: /*@C
291:    PetscLogMPEBegin - Turns on MPE logging of events. This creates large log files 
292:    and slows the program down.

294:    Collective over PETSC_COMM_WORLD

296:    Options Database Keys:
297: . -log_mpe - Prints extensive log information (for code compiled
298:              with PETSC_USE_LOG)

300:    Notes:
301:    A related routine is PetscLogBegin (with the options key -log), which is 
302:    intended for production runs since it logs only flop rates and object
303:    creation (and should not significantly slow the programs).

305:    Level: advanced

307:    Concepts: logging^MPE
308:    Concepts: logging^message passing

310: .seealso: PetscLogDump(), PetscLogBegin(), PetscLogAllBegin(), PetscLogEventActivate(),
311:           PetscLogEventDeactivate()
312: @*/
313: int PetscLogMPEBegin(void)
314: {
315:   int        i,rank,ierr;
316:   PetscTruth flg;
317: 
319:   /* Do MPE initialization */
320: #if defined (PETSC_HAVE_MPE_INITIALIZED_LOGGING)
321:   if (!MPE_Initialized_logging()) { /* This function exists in mpich 1.1.2 and higher */
322:     PetscLogInfo(0,"PetscLogMPEBegin: Initializing MPE.n");
323:     MPE_Init_log();
324:     PetscBeganMPE = PETSC_TRUE;
325:   } else {
326:     PetscLogInfo(0,"PetscLogMPEBegin: MPE already initialized. Not attempting to reinitialize.n");
327:   }
328: #else
329:   PetscOptionsHasName(PETSC_NULL,"-log_mpe_avoid_init",&flg);
330:   if (flg) {
331:     PetscLogInfo(0,"PetscLogMPEBegin: Not initializing MPE.n");
332:   } else {
333:     PetscLogInfo(0,"PetscLogMPEBegin: Initializing MPE.n");
334:     MPE_Init_log();
335:     PetscBeganMPE = PETSC_TRUE;
336:   }
337: #endif
338:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
339:   if (!rank) {
340:     for (i=0; i < PETSC_LOG_USER_EVENT_HIGH; i++) {
341:       if (PetscLogEventMPEFlags[i]) {
342:         MPE_Describe_state(MPEBEGIN+2*i,MPEBEGIN+2*i+1,PetscLogEventName[i],PetscLogEventColor[i]);
343:       }
344:     }
345:   }
346:   UseMPE = PETSC_TRUE;
347:   return(0);
348: }

350: /*@
351:     PetscLogEventMPEDeactivate - Indicates that a particular event should not be
352:        logged using MPE. Note: the event may be either a pre-defined
353:        PETSc event (found in include/petsclog.h) or an event number obtained
354:        with PetscLogEventRegister().

356:    Not Collective

358:    Input Parameter:
359: .  event - integer indicating event

361:    Example of Usage:
362: .vb
363:      PetscLogEventMPEDeactivate(VEC_SetValues);
364:         [code where you do not want to log VecSetValues()]
365:      PetscLogEventMPEActivate(VEC_SetValues);
366:         [code where you do want to log VecSetValues()]
367: .ve

369:    Level: advanced

371: .seealso: PetscLogEventMPEActivate(), PetscLogEventActivate(), PetscLogEventDeactivate()
372: @*/
373: int PetscLogEventMPEDeactivate(int event)
374: {
376:   PetscLogEventMPEFlags[event] = 0;
377:   return(0);
378: }

380: /*@
381:     PetscLogEventMPEActivate - Indicates that a particular event should be
382:        logged using MPE. Note: the event may be either a pre-defined
383:        PETSc event (found in include/petsclog.h) or an event number obtained
384:        with PetscLogEventRegister().

386:    Not Collective

388:    Input Parameter:
389: .  event - integer indicating event

391:    Example of Usage:
392: .vb
393:      PetscLogEventMPEDeactivate(VEC_SetValues);
394:         [code where you do not want to log VecSetValues()]
395:      PetscLogEventMPEActivate(VEC_SetValues);
396:         [code where you do want to log VecSetValues()]
397: .ve

399:    Level: advanced

401: .seealso: PetscLogEventMPEDeactivate(), PetscLogEventActivate(), PetscLogEventDeactivate()
402: @*/
403: int PetscLogEventMPEActivate(int event)
404: {
406:   PetscLogEventMPEFlags[event] = 1;
407:   return(0);
408: }

410: /*@C
411:    PetscLogMPEDump - Dumps the MPE logging info to file for later use with Upshot.

413:    Collective over PETSC_COMM_WORLD

415:    Level: advanced

417: .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogMPEBegin()
418: @*/
419: int PetscLogMPEDump(const char sname[])
420: {
421:   char name[256];
422:   int  ierr;

425:   if (PetscBeganMPE) {
426:     PetscLogInfo(0,"PetscLogMPEDump: Finalizing MPE.n");
427:     if (sname) { PetscStrcpy(name,sname);}
428:     else { PetscGetProgramName(name,256);}
429:     MPE_Finish_log(name);
430:   } else {
431:     PetscLogInfo(0,"PetscLogMPEDump: Not finalizing MPE.n");
432:   }
433:   return(0);
434: }

436: #else

438: /*
439:      Dummy function so that compilers will not complain about 
440:   empty files.
441: */
442: int PETScMPEDummy(int dummy)
443: {
444:   return 0;
445: }

447: #endif