~ubuntu-branches/ubuntu/saucy/nwchem/saucy

« back to all changes in this revision

Viewing changes to src/tools/ga-4-3/tcgmsg/ipcv5.0/evlog.c

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2012-02-09 20:02:41 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120209200241-jgk03qfsphal4ug2
Tags: 6.1-1
* New upstream release.

[ Michael Banck ]
* debian/patches/02_makefile_flags.patch: Updated.
* debian/patches/02_makefile_flags.patch: Use internal blas and lapack code.
* debian/patches/02_makefile_flags.patch: Define GCC4 for LINUX and LINUX64
  (Closes: #632611 and LP: #791308).
* debian/control (Build-Depends): Added openssh-client.
* debian/rules (USE_SCALAPACK, SCALAPACK): Removed variables (Closes:
  #654658).
* debian/rules (LIBDIR, USE_MPIF4, ARMCI_NETWORK): New variables.
* debian/TODO: New file.
* debian/control (Build-Depends): Removed libblas-dev, liblapack-dev and
  libscalapack-mpi-dev.
* debian/patches/04_show_testsuite_diff_output.patch: New patch, shows the
  diff output for failed tests.
* debian/patches/series: Adjusted.
* debian/testsuite: Optionally run all tests if "all" is passed as option.
* debian/rules: Run debian/testsuite with "all" if DEB_BUILD_OPTIONS
  contains "checkall".

[ Daniel Leidert ]
* debian/control: Used wrap-and-sort. Added Vcs-Svn and Vcs-Browser fields.
  (Priority): Moved to extra according to policy section 2.5.
  (Standards-Version): Bumped to 3.9.2.
  (Description): Fixed a typo.
* debian/watch: Added.
* debian/patches/03_hurd-i386_define_path_max.patch: Added.
  - Define MAX_PATH if not defines to fix FTBFS on hurd.
* debian/patches/series: Adjusted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Header: /tmp/hpctools/ga/tcgmsg/ipcv5.0/evlog.c,v 1.3 2003-06-27 13:53:12 manoj Exp $ */
 
2
 
 
3
/* Event logging routine with key driven varargs interface */
 
4
 
 
5
#include <stdio.h>
 
6
#include <stdarg.h>
 
7
 
 
8
extern long nodeid_();
 
9
 
 
10
#ifdef SEQUENT
 
11
#include <strings.h>
 
12
#else
 
13
#include <string.h>
 
14
#endif
 
15
 
 
16
#if defined(ALLIANT) || defined(ENCORE) || defined(SEQUENT) || \
 
17
    defined(CONVEX)  || defined(ARDENT) || defined(ULTRIX) || \
 
18
    defined(AIX)     || defined(IPSC)   || defined(NEXT)   || defined(DECOSF)
 
19
extern char *strdup();
 
20
#endif
 
21
 
 
22
#if defined(ULTRIX) || defined(SGI) || defined(NEXT) || defined(KSR) || \
 
23
    defined(DECOSF)
 
24
extern void *malloc();
 
25
#else
 
26
extern char *malloc();
 
27
#endif
 
28
 
 
29
#include "evlog.h"
 
30
 
 
31
static double walltime();
 
32
 
 
33
/* If sprintf returns an integer instead of a character pointer
 
34
   then define the flag INTSPRINTF */
 
35
 
 
36
#if defined(SGI)  || defined(AIX) || defined(IPSC) || defined(CRAY) || \
 
37
    defined(HPUX) || defined(ALLIANT) || defined(CONVEX) || defined(NEXT) || \
 
38
    defined(KSR)  || defined(DECOSF)
 
39
#define INTSPRINTF
 
40
#endif
 
41
 
 
42
void evlog(int farg_key, ...)
 
43
/* 
 
44
  The format of the argument list is as follows:
 
45
 
 
46
  evlog([(int) key, [values, ...]], ..., EVKEY_LAST_ARG)
 
47
 
 
48
  Arguments are read as keys with corresponding values. Recognised keys
 
49
  are defined in evlog.h and are described in detail below.
 
50
 
 
51
  Logging is enabled/disabled by calling evlog with one of EVKEY_ENABLE
 
52
  or EVKEY_DISABLE specified. Note that EVKEY_ENABLE must be the
 
53
  first key specified for it to be recognized and that all keys
 
54
  in the argument list after EVKEY_DISABLE are ignored. By default
 
55
  events are logged in the file events. This can be overridden with
 
56
  the key EVKEY_FILENAME, which takes the filename as its value.
 
57
 
 
58
  The model for logging events assumed by the post-analysis routines
 
59
  assumes that upon logging an event:
 
60
 
 
61
    a) no state chage occurs (EVKEY_EVENT). The event is just recorded.
 
62
 
 
63
    b) the process changes state by pushing the event onto the state stack
 
64
       (EVKEY_BEGIN).
 
65
 
 
66
    c) the process changes state by popping an event off the state stack
 
67
       (EVKEY_END). If the event or state popped off the stack does not
 
68
       match the specified event then the post-analysis may get confused
 
69
       but this does not interfere with the actual logging.
 
70
 
 
71
  EVKEY_EVENT, EVKEY_BEGIN or EVKEY_END must be the first key specified other
 
72
  than a possible EVKEY_ENABLE.
 
73
 
 
74
  Internally an event is stored as a large character string to simplify
 
75
  post-analysis. Users specify data for storage in addition to
 
76
  that which is automatically stored (only the time and process) with
 
77
  key, value combinations (EVKEY_STR_INT, EVKEY_STR_DBL, EVKEY_STR).
 
78
  Many such key-value combinations as required may be specified.
 
79
  Since the internal data format uses colons ':', double quotation
 
80
  marks '"' and carriage returns users should avoid these in their
 
81
  string data.
 
82
 
 
83
  ----------------------------
 
84
  Sample calling sequence:
 
85
 
 
86
  evlog(EVKEY_ENABLE, EVKEY_FILENAME, "events.log", EVKEY_LAST_ARG);
 
87
 
 
88
 
 
89
     evlog(EVKEY_EVENT, "Finished startup code",
 
90
           EVKEY_STR, "Now do some real work",
 
91
           EVKEY_LAST_ARG);
 
92
 
 
93
     evlog(EVKEY_BEGIN, "Get Matrix", EVKEY_LAST_ARG);
 
94
 
 
95
 
 
96
     evlog(EVKEY_END, "Get matrix",
 
97
           EVKEY_STR_INT, "Size of matrix", (int) N,
 
98
           EVKEY_STR_DBL, "Norm of matrix", (double) matrix_norm,
 
99
           EVKEY_LAST_ARG);
 
100
 
 
101
     evlog(EVKEY_BEGIN, "Transform matrix",
 
102
           EVKEY_STR_DBL, "Recomputed norm", (double) matrix_norm,
 
103
           EVKEY_LAST_ARG);
 
104
       
 
105
 
 
106
     evlog(EVKEY_END, "Transform matrix",
 
107
           EVKEY_STR_INT, "No. of iterations", (int) niters,
 
108
           EVKEY_LAST_ARG);
 
109
 
 
110
  evlog(EVKEY_DUMP, EVKEY_DISABLE, EVKEY_LAST_ARG);
 
111
 
 
112
  evlog(EVKEY_EVENT, "Logging is disabled ... this should not print",
 
113
        EVKEY_DUMP, EVKEY_LAST_ARG);
 
114
 
 
115
  ----------------------------
 
116
 
 
117
 EVKEY_LAST_ARG
 
118
      Terminates list ... takes no value and must be present
 
119
 
 
120
 EVKEY_EVENT, (char *) event
 
121
      Simply log occurence of the event
 
122
 
 
123
 EVKEY_BEGIN, (char *) event
 
124
      Push event onto process state stack
 
125
 
 
126
 EVKEY_END, (char *) event
 
127
      Pop event off process state stack
 
128
 
 
129
 EVKEY_MSG_LEN, (int) length
 
130
      Value is (int) mesage length SND/RCV only
 
131
 
 
132
 EVKEY_MSG_TO, (int) to
 
133
      Value is (int) to process id SND/RCV only
 
134
 
 
135
 EVKEY_MSG_FROM, (int) from
 
136
      Value is (int) from process  SND/RCV only
 
137
 
 
138
 EVKEY_MSG_TYPE, (int) type
 
139
      Value is (int) message type  SND/RCV only
 
140
 
 
141
 EVKEY_STR_INT, (char *) string, (int) data
 
142
      User data value pair
 
143
 
 
144
 EVKEY_STR_DBL, (char *) string, (double) data
 
145
      User data value pair (char *), (double)
 
146
 
 
147
 EVKEY_STR, (char *) string
 
148
      User data value (char *)
 
149
 
 
150
 EVKEY_ENABLE
 
151
      Enable logging
 
152
 
 
153
 EVKEY_DISABLE
 
154
      Disable logging
 
155
 
 
156
 EVKEY_DUMP
 
157
      Dump out the current buffer to disk
 
158
 
 
159
 EVKEY_FILE, (char *) filename
 
160
      Use specified file to capture events. Default is "events".
 
161
*/
 
162
{
 
163
  static int   logging=0;  /* Boolean flag for login enabled/disabled */
 
164
  static int   error=0;    /* Boolean flag for error detected         */
 
165
  static int   ncall=0;    /* Need to do stuff on first entry         */
 
166
  static char *buffer;     /* Logging buffer ... null terminated      */
 
167
  static char *bufpt;      /* Pointer to next free char in buffer     */
 
168
  static int   left;       /* Amount of free space in buffer          */
 
169
#define  BUFLEN 262144     /* Size allocated for buffer ... biggish */
 
170
#define  MAX_EV_LEN 1000   /* Assumed maximum size of single event record */
 
171
  static FILE *file;       /* File where events will be dumped */
 
172
  static char *filename = "events";   /* Default name of events file */
 
173
 
 
174
  va_list  ap;             /* For variable argument list */
 
175
  int      key;            /* Hold key being processed   */
 
176
  int      nchars;         /* No. of chars printed by sprintf call */
 
177
  char    *temp;           /* Temporary copy of bufpt */
 
178
  char    *string;         /* Temporary */
 
179
  int      integer;        /* Temporary */
 
180
  double   dbl;            /* Temporary */
 
181
  int      valid;          /* Temporary */
 
182
  
 
183
#define ERROR_RETURN error = 1; return;
 
184
 
 
185
#define DUMPBUF (void) fputs(buffer, file); \
 
186
                (void) fflush(file);\
 
187
                if(ferror(file)) {ERROR_RETURN} \
 
188
                bufpt = buffer; left = BUFLEN;
 
189
/*
 
190
 sprintf is a disaster area!!!!
 
191
#ifdef INTSPRINTF
 
192
#define RECORD(A)  nchars = (A); bufpt += nchars; left -= nchars
 
193
#else
 
194
#define RECORD(A)  nchars = strlen(A); bufpt += nchars; left -= nchars
 
195
#endif
 
196
*/
 
197
#define RECORD(A)  {A; nchars = strlen(bufpt); bufpt += nchars; left -= nchars;}
 
198
 
 
199
 
 
200
  /* If an error was detected on a previous call don't even try to
 
201
     do anything */
 
202
 
 
203
  if (error) {ERROR_RETURN}
 
204
 
 
205
  /* First time in need to allocate the buffer, open the file etc */
 
206
 
 
207
  if (ncall == 0) {
 
208
    ncall = 1;
 
209
    if (!(bufpt = buffer = malloc((unsigned) BUFLEN))) {ERROR_RETURN}
 
210
    left = BUFLEN;
 
211
 
 
212
    if (!(file = fopen(filename, "w"))) {ERROR_RETURN}
 
213
  }
 
214
      
 
215
  /* Parse the arguments */
 
216
 
 
217
  temp = bufpt;    /* Save to check if anything has been logged */
 
218
  valid = 0;       /* One of BEGIN, END or EVENT must preceed most keys */
 
219
  
 
220
  va_start(ap, farg_key);
 
221
  key = farg_key;
 
222
  while (key != EVKEY_LAST_ARG) {
 
223
 
 
224
    if ( (!logging) && (key != EVKEY_ENABLE) )
 
225
      return;
 
226
 
 
227
    switch (key) {
 
228
 
 
229
    case EVKEY_ENABLE:
 
230
      logging = 1;
 
231
      break;
 
232
 
 
233
    case EVKEY_DISABLE:
 
234
      logging = 0;
 
235
      goto done;
 
236
/*      break; */
 
237
 
 
238
    case EVKEY_FILENAME:
 
239
      if (!(filename = strdup(va_arg(ap, char *))))
 
240
        {ERROR_RETURN}
 
241
      if (!(file = freopen(filename, "w", file))) {ERROR_RETURN}
 
242
      break;
 
243
 
 
244
    case EVKEY_BEGIN:
 
245
      valid = 1;
 
246
      RECORD(sprintf(bufpt, ":BEGIN:%s", va_arg(ap, char *)));
 
247
      RECORD(sprintf(bufpt, ":TIME:%.2f", walltime()));
 
248
      break;
 
249
 
 
250
    case EVKEY_END:
 
251
      valid = 1;
 
252
      RECORD(sprintf(bufpt, ":END:%s", va_arg(ap, char *)));
 
253
      RECORD(sprintf(bufpt, ":TIME:%.2f", walltime()));
 
254
      break;
 
255
 
 
256
    case EVKEY_EVENT:
 
257
      valid = 1;
 
258
      RECORD(sprintf(bufpt, ":EVENT:%s", va_arg(ap, char *)));
 
259
      RECORD(sprintf(bufpt, ":TIME:%.2f", walltime()));
 
260
      break;
 
261
 
 
262
    case EVKEY_MSG_LEN:
 
263
      if (!valid) {ERROR_RETURN}
 
264
      RECORD(sprintf(bufpt, ":MSG_LEN:%d", va_arg(ap, int)));
 
265
      break;
 
266
 
 
267
    case EVKEY_MSG_TO:
 
268
      if (!valid) {ERROR_RETURN}
 
269
      RECORD(sprintf(bufpt, ":MSG_TO:%d", va_arg(ap, int)));
 
270
      break;
 
271
 
 
272
    case EVKEY_MSG_FROM:
 
273
      if (!valid) {ERROR_RETURN}
 
274
      RECORD(sprintf(bufpt, ":MSG_FROM:%d", va_arg(ap, int)));
 
275
      break;
 
276
 
 
277
    case EVKEY_MSG_TYPE:
 
278
      if (!valid) {ERROR_RETURN}
 
279
      RECORD(sprintf(bufpt, ":MSG_TYPE:%d", va_arg(ap, int)));
 
280
      break;
 
281
 
 
282
    case EVKEY_MSG_SYNC:
 
283
      if (!valid) {ERROR_RETURN}
 
284
      RECORD(sprintf(bufpt, ":MSG_SYNC:%d", va_arg(ap, int)));
 
285
      break;
 
286
 
 
287
    case EVKEY_STR_INT:
 
288
      if (!valid) {ERROR_RETURN}
 
289
      string  = va_arg(ap, char *);
 
290
      integer = va_arg(ap, int);
 
291
      RECORD(sprintf(bufpt, ":STR_INT:%s:%d", string, integer));
 
292
      break;
 
293
 
 
294
    case EVKEY_STR_DBL:
 
295
      if (!valid) {ERROR_RETURN}
 
296
      string  = va_arg(ap, char *);
 
297
      dbl = va_arg(ap, double);
 
298
      RECORD(sprintf(bufpt, ":STR_DBL:%s:%g", string, dbl));
 
299
      break;
 
300
 
 
301
    case EVKEY_STR:
 
302
      if (!valid) {ERROR_RETURN}
 
303
      RECORD(sprintf(bufpt, ":STR:%s", va_arg(ap, char *)));
 
304
      break;
 
305
 
 
306
    case EVKEY_DUMP:
 
307
      {DUMPBUF}
 
308
      if (temp != bufpt) {
 
309
        RECORD(sprintf(bufpt, "\n"));
 
310
        temp = bufpt;
 
311
      }
 
312
      break;
 
313
 
 
314
    default:
 
315
      {DUMPBUF}
 
316
      {ERROR_RETURN}
 
317
    }
 
318
    key = va_arg(ap, int);
 
319
  }
 
320
  
 
321
 done:
 
322
  va_end(ap);
 
323
 
 
324
  /* Put a linefeed on the end of the record if something is written */
 
325
 
 
326
  if (temp != bufpt) {
 
327
    RECORD(sprintf(bufpt, "\n"));
 
328
    temp = bufpt;
 
329
  }
 
330
  
 
331
  /* Should really check on every access to the buffer that there is
 
332
     enough space ... however just assume a very large maximum size
 
333
     for a single event log entry and check here */
 
334
 
 
335
  if (left <= 0)
 
336
    {ERROR_RETURN}
 
337
 
 
338
  if (left < MAX_EV_LEN)
 
339
    {DUMPBUF}
 
340
}
 
341
 
 
342
#include "sndrcv.h"
 
343
 
 
344
static double walltime()
 
345
/*
 
346
  return the wall time in seconds as a double
 
347
*/
 
348
{
 
349
  return ((double) MTIME_()) * 0.01;
 
350
}
 
351
 
 
352
/*
 
353
int main()
 
354
{
 
355
  int N = 19;
 
356
  double matrix_norm = 99.1;
 
357
  int niters = 5;
 
358
 
 
359
  evlog(EVKEY_ENABLE, EVKEY_FILENAME, "events.log", EVKEY_LAST_ARG);
 
360
 
 
361
 
 
362
     evlog(EVKEY_EVENT, "Finished startup code",
 
363
           EVKEY_STR, "Now do some real work",
 
364
           EVKEY_LAST_ARG);
 
365
 
 
366
     evlog(EVKEY_BEGIN, "Get Matrix", EVKEY_LAST_ARG);
 
367
 
 
368
 
 
369
     evlog(EVKEY_END, "Get matrix",
 
370
           EVKEY_STR_INT, "Size of matrix", (int) N,
 
371
           EVKEY_STR_DBL, "Norm of matrix", (double) matrix_norm,
 
372
           EVKEY_LAST_ARG);
 
373
 
 
374
     evlog(EVKEY_BEGIN, "Transform matrix",
 
375
           EVKEY_STR_DBL, "Recomputed norm", (double) matrix_norm,
 
376
           EVKEY_LAST_ARG);
 
377
       
 
378
 
 
379
     evlog(EVKEY_END, "Transform matrix",
 
380
           EVKEY_STR_INT, "No. of iterations", (int) niters,
 
381
           EVKEY_LAST_ARG);
 
382
 
 
383
  evlog(EVKEY_DUMP, EVKEY_LAST_ARG);
 
384
 
 
385
  evlog(EVKEY_EVENT, "Logging is disabled ... this should not print",
 
386
        EVKEY_DUMP, EVKEY_LAST_ARG);
 
387
 
 
388
  return 0;
 
389
}
 
390
*/