Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /trunk/src/lib/c-target/main.c
ViewVC logotype

Diff of /trunk/src/lib/c-target/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1232, Mon May 16 23:37:52 2011 UTC revision 1301, Thu Jun 9 23:58:40 2011 UTC
# Line 13  Line 13 
13  #include <assert.h>  #include <assert.h>
14  #include <Diderot/diderot.h>  #include <Diderot/diderot.h>
15    
16    // NOTE: we probably should put this in a file that supports runtime printing
17    static bool     VerboseFlg = false;
18    static bool     TimingFlg = false;
19    
20  struct struct_world {  struct struct_world {
21        const char          *name;          // the program name
22      bool                isArray;        // is the initialization an array or collection?      bool                isArray;        // is the initialization an array or collection?
23      uint32_t            nDims;          // depth of iteration nesting      uint32_t            nDims;          // depth of iteration nesting
24      int32_t             *base;          // nDims array of base indices      int32_t             *base;          // nDims array of base indices
# Line 28  Line 33 
33    
34  int main (int argc, const char **argv)  int main (int argc, const char **argv)
35  {  {
36    //      Diderot_Options_t *opts = Diderot_OptNew ();
37  printf("initializing globals ...\n");  
38      Diderot_InitGlobals (argc, argv);      Diderot_OptAddFlag (opts, "verbose", "enable runtime-system messages", &VerboseFlg);
39        Diderot_OptAddFlag (opts, "timing", "enable execution timing", &TimingFlg);
40        Diderot_RegisterGlobalOpts (opts);
41        Diderot_OptProcess (opts, argc, argv);
42        Diderot_OptFree (opts);
43    
44      // run the generated global initialization code
45        if (VerboseFlg) fprintf (stderr, "initializing globals ...\n");
46        Diderot_InitGlobals ();
47    
48    // FIXME: we need to figure out how initialization should be handled.    // FIXME: we need to figure out how initialization should be handled.
49  printf("initializing strands ...\n");      if (VerboseFlg) fprintf (stderr, "initializing strands ...\n");
50      Diderot_World_t *wrld = Diderot_Initially ();      Diderot_World_t *wrld = Diderot_Initially ();
51      for (int i = 0;  i < wrld->numStrands;  i++) {      for (int i = 0;  i < wrld->numStrands;  i++) {
52        // hack to make the invariant part of the state the same in both copies        // hack to make the invariant part of the state the same in both copies
# Line 41  Line 54 
54      }      }
55    
56    // iterate until all strands are stable    // iterate until all strands are stable
57  printf("run with %d strands ...\n", wrld->numStrands);      if (VerboseFlg) fprintf(stderr, "run with %d strands ...\n", wrld->numStrands);
58        double t0 = GetTime();
59      int nSteps = 0, nUpdates = 0;      int nSteps = 0, nUpdates = 0;
60      int nActive = wrld->numStrands;      int nActive = wrld->numStrands;
61      while (nActive > 0) {      while (nActive > 0) {
# Line 82  Line 96 
96          wrld->inState = wrld->outState;          wrld->inState = wrld->outState;
97          wrld->outState = tmp;          wrld->outState = tmp;
98      }      }
99        double totalTime = GetTime() - t0;
100    
101        if (VerboseFlg)
102            fprintf (stderr, "done: %d updates, %d steps, in %f seconds\n", nUpdates, nSteps, totalTime);
103        else if (TimingFlg)
104            printf ("usr=%f\n", totalTime);
105    
 printf("done: %d updates, %d steps\n", nUpdates, nSteps);  
106    // here we have the final state of all of the strands in the "in" buffer    // here we have the final state of all of the strands in the "in" buffer
107      FILE *outS = fopen("mip.txt", "w");      int outFileNameLen = strlen(wrld->name) + 5;
108        char *outFileName = (char *)malloc(outFileNameLen);
109        snprintf (outFileName, outFileNameLen, "%s.txt", wrld->name);
110        FILE *outS = fopen(outFileName, "w");
111      if (outS == NULL) {      if (outS == NULL) {
112          fprintf (stderr, "Cannot open output file\n");          fprintf (stderr, "Cannot open output file %s\n", outFileName);
113          exit (8);          exit (8);
114      }      }
115    
# Line 112  Line 134 
134    
135  // block allocation of an initial collection of strands  // block allocation of an initial collection of strands
136  Diderot_World_t *Diderot_AllocInitially (  Diderot_World_t *Diderot_AllocInitially (
137        const char *name,           // the name of the program
138      Strand_t *strand,           // the type of strands being allocated      Strand_t *strand,           // the type of strands being allocated
139      bool isArray,               // is the initialization an array or collection?      bool isArray,               // is the initialization an array or collection?
140      uint32_t nDims,             // depth of iteration nesting      uint32_t nDims,             // depth of iteration nesting
# Line 124  Line 147 
147          exit (1);          exit (1);
148      }      }
149    
150        wrld->name = name; /* NOTE: we are assuming that name is statically allocated! */
151      wrld->isArray = isArray;      wrld->isArray = isArray;
152      wrld->nDims = nDims;      wrld->nDims = nDims;
153      wrld->base = (int32_t *) malloc (nDims * sizeof(int32_t));      wrld->base = (int32_t *) malloc (nDims * sizeof(int32_t));
# Line 135  Line 159 
159          wrld->size[i] = size[i];          wrld->size[i] = size[i];
160      }      }
161    
162  printf("AllocInitially: %d", size[0]);      if (VerboseFlg) {
163  for (int i = 1;  i < nDims;  i++) printf(" x %d", size[i]);          fprintf(stderr, "AllocInitially: %d", size[0]);
164  printf("\n");          for (int i = 1;  i < nDims;  i++) fprintf(stderr, " x %d", size[i]);
165            fprintf(stderr, "\n");
166        }
167    
168    // allocate the strand state pointers    // allocate the strand state pointers
169      wrld->numStrands = numStrands;      wrld->numStrands = numStrands;

Legend:
Removed from v.1232  
changed lines
  Added in v.1301

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0