~ubuntu-branches/ubuntu/vivid/atlas/vivid

« back to all changes in this revision

Viewing changes to results/reducetvec.c

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-06-11 15:58:16 UTC
  • mfrom: (1.1.3 upstream)
  • mto: (2.2.21 experimental)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: package-import@ubuntu.com-20130611155816-b72z8f621tuhbzn0
Tags: upstream-3.10.1
Import upstream version 3.10.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "atlas_tvec.h"
 
2
 
 
3
void PrintUsage(char *name, char *arg, int i)
 
4
{
 
5
   fprintf(stderr, "This routine gets rid of the repititions within vectors\n");
 
6
   fprintf(stderr, "Vectors are *reduced* or *combined*:\n");
 
7
   fprintf(stderr, "   reduced vectors should be repeats (eg 100, 100)\n");
 
8
   fprintf(stderr,
 
9
      "   combined vectors are combined and produce several vectors:\n");
 
10
   fprintf(stderr, "      v_1...v_<nreps>, v_avg, v_min, v_max\n");
 
11
   fprintf(stderr,
 
12
   "   any vector not collapsed or combined does not appear in the output\n");
 
13
   if (i > 0)
 
14
      fprintf(stderr, "BAD ARG '%s' ON %dth FLAG\n", arg, i);
 
15
   fprintf(stderr, "USAGE: %s <flags> ; flags include:\n", name);
 
16
   fprintf(stderr, "   -i <file> : (stdin) file with vecs to reduce\n");
 
17
   fprintf(stderr, "   -o <file>  : (stdout) file for reduced vecs\n");
 
18
   fprintf(stderr, "   -R # <nam1> ... <nam#>: vectors to collapse\n");
 
19
   fprintf(stderr, "   -C # <nam1> ... <nam#>: vectors to combine\n");
 
20
   fprintf(stderr, "   -c [+,<,>,a] : specify how to combine repeated elts:\n");
 
21
   fprintf(stderr, "      +: repeated vector replaced by average of repeats\n");
 
22
   fprintf(stderr, "      <: repeated vector replaced by minimum of repeats\n");
 
23
   fprintf(stderr, "      >: repeated vector replaced by maximum of repeats\n");
 
24
   exit (i ? i : -1);
 
25
}
 
26
 
 
27
char **GetFlags         /* RETURNS: array of names to combine/reduce */
 
28
(
 
29
   int nargs,
 
30
   char **args,
 
31
   int *ncomb,          /* # of vecs to combine, stored in 1st ncomb elts */
 
32
   int *nred,           /* # of vecs to reduce, stored at end of ret array */
 
33
   FILE **fpin,         /* input stream */
 
34
   FILE **fpout         /* output stream */
 
35
)
 
36
{
 
37
   char **vc=NULL, **vr=NULL, **vv, *sp;
 
38
   int i, j, n, nc=0, nr=0;
 
39
   FILE *fp;
 
40
 
 
41
   *fpin = stdin;
 
42
   *fpout = stdout;
 
43
   for (i=1; i < nargs; i++)
 
44
   {
 
45
      if (args[i][0] != '-')
 
46
         PrintUsage(args[0], "no '-' preceeding flag!", i);
 
47
      switch(args[i][1])
 
48
      {
 
49
      case 'i':    /* -i <file> */
 
50
         if (++i >= nargs)
 
51
            PrintUsage(args[0], "out of flags in -i ", i-1);
 
52
         *fpin = fopen(args[i], "r");
 
53
         assert(*fpin);
 
54
         break;
 
55
      case 'o':    /* -o <file> */
 
56
         if (++i >= nargs)
 
57
            PrintUsage(args[0], "out of flags in -i ", i-1);
 
58
         fp = fopen(args[i], "w");
 
59
         assert(fp);
 
60
         *fpout = fp;
 
61
         break;
 
62
      case 'R':    /* -R # <nam1> ... <nam#> */
 
63
         if (++i >= nargs)
 
64
            PrintUsage(args[0], "out of flags in -R ", i-1);
 
65
         nr = atoi(args[i]);
 
66
         assert(nr > 0 && nr < 2048);
 
67
         vr = malloc(sizeof(char*)*nr);
 
68
         assert(vr);
 
69
         for (j=0; j < nr; j++)
 
70
         {
 
71
            if (++i >= nargs)
 
72
               PrintUsage(args[0], "out of flags in -R ", i-1);
 
73
            vr[j] = args[i];
 
74
         }
 
75
         break;
 
76
      case 'C':    /* -C # <nam1> ... <nam#> */
 
77
         if (++i >= nargs)
 
78
            PrintUsage(args[0], "out of flags in -C ", i-1);
 
79
         nc = atoi(args[i]);
 
80
         assert(nc > 0 && nc < 2048);
 
81
         vc = malloc(sizeof(char*)*nc);
 
82
         assert(vc);
 
83
         for (j=0; j < nc; j++)
 
84
         {
 
85
            if (++i >= nargs)
 
86
               PrintUsage(args[0], "out of flags in -C ", i-1);
 
87
            vc[j] = args[i];
 
88
         }
 
89
         break;
 
90
      default :
 
91
         PrintUsage(args[0], args[i], i);
 
92
      }                                         /* end switch over flags */
 
93
   }                                            /* end for over flags */
 
94
   if (!nr && !nc)
 
95
   {
 
96
      nr = nc = 1;
 
97
      vv = malloc(2*sizeof(char*));
 
98
      assert(vv);
 
99
      vv[0] = "MFLOP";
 
100
      vv[1] = "N";
 
101
   }
 
102
   else
 
103
   {
 
104
      n = nr + nc;
 
105
      vv = malloc(n*sizeof(char*));
 
106
      assert(vv);
 
107
      for (i=0; i < nc; i++)
 
108
         vv[i] = vc[i];
 
109
      if (vc)
 
110
         free(vc);
 
111
      if (vr)
 
112
      {
 
113
         for (; i < n; i++)
 
114
            vv[i] = vr[i-nc];
 
115
         free(vr);
 
116
      }
 
117
   }
 
118
   *ncomb = nc;
 
119
   *nred = nr;
 
120
   return(vv);
 
121
}
 
122
 
 
123
int main(int nargs, char **args)
 
124
{
 
125
   FILE *fpin, *fpout;
 
126
   char **redarr, **combarr, *cmnt;
 
127
   int N, Nc, Nr, i, j, RNGINC=0, nrep;
 
128
   ATL_tvec_t *tr, *tc, *tp, *np, *nb=NULL;
 
129
 
 
130
   combarr = GetFlags(nargs, args, &Nc, &Nr, &fpin, &fpout);
 
131
   redarr = combarr + Nc;
 
132
 
 
133
/*
 
134
 * Grab only the vectors to be combined and reduced (in the order the user
 
135
 * has specified) from list, and free all unused vectors
 
136
 */
 
137
 
 
138
   np = ATL_ReadTvecFile(fpin, &cmnt, &N, &nrep);
 
139
   if (fpin != stdin)
 
140
      fclose(fpin);
 
141
   tc = ATL_PullNamedVecsFromList(Nc, combarr, &np);
 
142
   tr = ATL_PullNamedVecsFromList(Nr, redarr, &np);
 
143
   if (np)
 
144
      ATL_KillAllTvecs(np);
 
145
/*
 
146
 * Create all individual run vectors, add to new list
 
147
 */
 
148
   for (tp=tc; tp; tp = tp->next)
 
149
   {
 
150
      ATL_tvec_t *p;
 
151
      p = ATL_SplitRepsVector(tp);
 
152
      ATL_FindLastVecInList(p)->next = nb;
 
153
      nb = p;
 
154
   }
 
155
/*
 
156
 * Create all statistic vectors in queue
 
157
 */
 
158
   for (tp=tc; tp; tp = tp->next)
 
159
   {
 
160
      ATL_tvec_t *p;
 
161
      assert(tp->pre == 'd');         /* relax this later if needed */
 
162
      p = ATL_GetStatVecsDOUBLE(tp);
 
163
      p->next->next->next = nb;
 
164
      nb = p;
 
165
   }
 
166
   ATL_KillAllTvecs(tc);
 
167
/*
 
168
 * Now reduce any repeated vectors
 
169
 */
 
170
   for (tp=tr; tp; tp = tp->next)
 
171
   {
 
172
      ATL_tvec_t *p;
 
173
      int i;
 
174
      char *sp;
 
175
 
 
176
      p = ATL_GetRep1Vector(tp, 0);
 
177
      p->next = nb;
 
178
      nb = p;
 
179
 
 
180
      for (sp=p->name,i=0; sp[i] != '_'; i++);   /* fix name back to orig */
 
181
      sp[i] = '\0';                              /* from name_0 */
 
182
   }
 
183
   ATL_KillAllTvecs(tr);
 
184
 
 
185
   ATL_WriteTvecFile(fpout, cmnt, ATL_CountTVecsInList(nb), 1, nb);
 
186
   ATL_KillAllTvecs(nb);
 
187
   free(cmnt);
 
188
   if (fpout != stdout && fpout != stderr)
 
189
      fclose(fpout);
 
190
   return(0);
 
191
}