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

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/armci/tcgmsg/ipcv4.0/parse.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
#if HAVE_CONFIG_H
 
2
#   include "config.h"
 
3
#endif
 
4
 
 
5
#if HAVE_STDIO_H
 
6
#   include <stdio.h>
 
7
#endif
 
8
#if HAVE_STDLIB_H
 
9
#   include <stdlib.h>
 
10
#endif
 
11
 
 
12
#define MAX_TOKEN 2048
 
13
 
 
14
/**
 
15
 * Read next token from file. Tokens are separated by the character
 
16
 * delimeter.
 
17
 * Tokens are returned as NUL terminated character strings which
 
18
 * almost certainly should always be freed with free() after use.
 
19
 *
 
20
 * There is an internally imposed maximum token size of MAX_TOKEN bytes.
 
21
 *
 
22
 * All errors are handled by returning a NULL pointer.
 
23
 */
 
24
char *ReadToken(FILE *file, char delimiter)
 
25
{
 
26
    char *buf = malloc((unsigned) MAX_TOKEN);
 
27
    char *temp;
 
28
    int input, used=0;
 
29
 
 
30
    if (!buf) {
 
31
        return (char *) NULL;
 
32
    }
 
33
 
 
34
    temp = buf;
 
35
 
 
36
    while ( (input = getc(file)) != EOF ) {
 
37
 
 
38
        used++;
 
39
 
 
40
        if (input == delimiter) {
 
41
            *temp = '\0';
 
42
            break;
 
43
        }
 
44
        else {
 
45
            *temp++ = (char) input;
 
46
            if (used == MAX_TOKEN) {
 
47
                used = 0; break;
 
48
            }
 
49
        }
 
50
    }
 
51
 
 
52
    /* duplicate string to minimize problems if string is not
 
53
       freed in calling program */
 
54
 
 
55
    if (used) {
 
56
        temp = strdup(buf);
 
57
    }
 
58
    else {
 
59
        temp = (char *) NULL;
 
60
    }
 
61
 
 
62
    (void) free(buf);
 
63
 
 
64
    return temp;
 
65
}
 
66
 
 
67
 
 
68
int FindToken(char *token, FILE *file, char delimiter)
 
69
{
 
70
    char *input;
 
71
 
 
72
    while (input = ReadToken(file, delimiter)) {
 
73
        if (strcmp(input, token) == 0) {
 
74
            return 1;
 
75
        }
 
76
        else {
 
77
            (void) free(input);
 
78
        }
 
79
    }
 
80
 
 
81
    return 0;
 
82
}
 
83
 
 
84
 
 
85
/**
 
86
 * Return the starting time and duration of the events file.
 
87
 */
 
88
void GetTimeSpan(FILE *file, DoublePrecision *start, DoublePrecision *duration)
 
89
{
 
90
    char *input;
 
91
    DoublePrecision end;
 
92
 
 
93
    end = *start = 0.0;
 
94
 
 
95
    if (FindToken("TIME", file, ':')) {
 
96
        end = *start = atof(input = ReadToken(file, ':'));
 
97
        (void) free(input);
 
98
    }
 
99
 
 
100
    while (FindToken("TIME", file, ':')) {
 
101
        end = atof(input = ReadToken(file, ':'));
 
102
        (void) free(input);
 
103
    }
 
104
 
 
105
    *duration = end - *start;
 
106
 
 
107
    (void) fseek(file, 0L, 0);
 
108
}
 
109
  
 
110
 
 
111
int main(int argc, char **argv)
 
112
{
 
113
    char filename[11];
 
114
    FILE *file, *plot;
 
115
    char *token;
 
116
    char *event;
 
117
    DoublePrecision time, start, duration=0.0, otim, span, margin, comms, useful;
 
118
    int newstate, state, i, nproc, lo, hi;
 
119
 
 
120
    if (argc == 1) {
 
121
        lo = 0;
 
122
        hi = 127;
 
123
    }
 
124
    else if (argc == 3) {
 
125
        lo = atoi(argv[1]);
 
126
        hi = atoi(argv[2]);
 
127
    }
 
128
    else {
 
129
        (void) fprintf(stderr, "usage: %s [lo hi]\n", argv[0]);
 
130
        (void) fprintf(stderr, "... with no arguments parse all event files\n");
 
131
        (void) fprintf(stderr, "... or with lo & hi only files in this range\n");
 
132
        (void) fprintf(stderr, "... e.g.  parse 16 31\n");
 
133
        return 1;
 
134
    }
 
135
 
 
136
    /* open the file that will have the plot stuff in it */
 
137
    /* change of heart here ... just write to stdout */
 
138
 
 
139
    /* 
 
140
       if (!(plot = fopen("plot", "w"))) {
 
141
       perror("failed to open plot file");
 
142
       return 1;
 
143
       }
 
144
       */
 
145
 
 
146
    plot = stdout;
 
147
 
 
148
    /* Determine how many processes there are and maximum time span */
 
149
 
 
150
    nproc = 0;
 
151
    for (i=lo; i<=hi; i++) {
 
152
 
 
153
        (void) sprintf(filename, "events.%03d", nproc);
 
154
 
 
155
        if ( !(file = fopen(filename, "r")) ) {
 
156
            break;
 
157
        }
 
158
 
 
159
        GetTimeSpan(file, &start, &span);
 
160
        (void) fclose(file);
 
161
 
 
162
        if (span > duration) {
 
163
            duration = span;
 
164
        }
 
165
 
 
166
        nproc++;
 
167
    }      
 
168
 
 
169
    margin = duration * 0.1;
 
170
 
 
171
    (void) fprintf(plot, "s %d %d %d %d\n",0,0,
 
172
                   (int) ((margin*2.0+duration)*100.0), 5*nproc);
 
173
    /* (void) fprintf(stderr, "nproc=%d, duration=%4.2f\n", nproc, duration); */
 
174
 
 
175
    /* Now go thru the files and actually parse the contents */
 
176
 
 
177
    for (i=lo; i<=hi; i++) {
 
178
        (void) sprintf(filename, "events.%03d", i);
 
179
 
 
180
        if ( !(file = fopen(filename, "r")) ) {
 
181
            break;
 
182
        }
 
183
 
 
184
        GetTimeSpan(file, &start, &span);
 
185
 
 
186
        comms = 0.0;
 
187
        state = 5*(i-lo);
 
188
        otim = 0.0 + margin;
 
189
 
 
190
        (void) fprintf(plot, "t %d %d %d\n", 0, state, i);
 
191
 
 
192
        while ( token = ReadToken(file, ':') ) {
 
193
            if (strcmp(token, "BEGIN") == 0)  {
 
194
                newstate = 5*(i-lo) + 1;
 
195
            }
 
196
            else if (strcmp(token, "END") == 0) {
 
197
                newstate = 5*(i-lo);
 
198
            }
 
199
            else {
 
200
                continue;
 
201
            }
 
202
 
 
203
            /* Have a BEGIN or END ... only process Snd/Rcv at moment */
 
204
 
 
205
            event = ReadToken(file, ':');
 
206
            if ((strcmp(event, "Snd") == 0)
 
207
                    || (strcmp(event,"Rcv") == 0)
 
208
                    || (strcmp(event,"Waitcom") == 0)) {
 
209
 
 
210
                if (FindToken("TIME", file, ':')) {
 
211
                    time = atof(ReadToken(file, ':')) - start + margin;
 
212
 
 
213
                    (void) fprintf(plot, "l %d %d %d %d\n",
 
214
                                   (int) (otim*100.0), state,
 
215
                                   (int) (time*100.0), state);
 
216
                    (void) fprintf(plot, "l %d %d %d %d\n",
 
217
                                   (int) (time*100.0), state,
 
218
                                   (int) (time*100.0), newstate);
 
219
 
 
220
                    /* Accumulate the time spent in communication */
 
221
 
 
222
                    if (newstate == (5*(i-lo)))  {
 
223
                        comms = comms + time - otim;
 
224
                    }
 
225
 
 
226
                    otim = time;
 
227
                    state = newstate;
 
228
                }
 
229
            }
 
230
            else if (strcmp(event, "Process") == 0) {
 
231
                if (FindToken("TIME", file, ':')) {
 
232
                    time = atof(ReadToken(file, ':')) - start + margin;
 
233
 
 
234
                    (void) fprintf(plot, "l %d %d %d %d\n", (int) (otim*100.0), state,
 
235
                                   (int) (time*100.0), state);
 
236
                    otim = time;
 
237
                }
 
238
            }
 
239
        }
 
240
 
 
241
        /* Assume that non-communication time is useful */
 
242
 
 
243
        useful = 100.0 * (span - comms) / duration;
 
244
 
 
245
        (void) fprintf(plot, "t %d %d %4.1f%%\n",
 
246
                       (int) (100.0*duration+150.0*margin), 5*(i-lo), useful);
 
247
 
 
248
        (void) fflush(plot);
 
249
        (void) fclose(file);
 
250
    }
 
251
    return 0;
 
252
}