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

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/lib/c-target/main.c
ViewVC logotype

Diff of /branches/pure-cfg/src/lib/c-target/main.c

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

revision 1471, Sat Aug 13 11:46:41 2011 UTC revision 1472, Fri Aug 19 01:54:43 2011 UTC
# Line 123  Line 123 
123    
124        // get correct output file name        // get correct output file name
125          int outFileNameLen = strlen(wrld->name) + 6;          int outFileNameLen = strlen(wrld->name) + 6;
126          char *outFileName = (char *)malloc(outFileNameLen);          char *outFileName = (char *)CheckedAlloc(outFileNameLen);
127          snprintf (outFileName, outFileNameLen, "%s.nrrd", wrld->name);          snprintf (outFileName, outFileNameLen, "%s.nrrd", wrld->name);
128    
129        // allocate the correct amount of space for output        // allocate the correct amount of space for output
# Line 132  Line 132 
132              if (wrld->status[i] == DIDEROT_STABLE)              if (wrld->status[i] == DIDEROT_STABLE)
133                  numStabilized++;                  numStabilized++;
134          }          }
135          void *outData = malloc(numStabilized * Diderot_Strands[0]->outputSzb);          void *outData = CheckedAlloc(numStabilized * Diderot_Strands[0]->outputSzb);
136    
137        // copy data into outData        // copy data into outData
138          void *outPos = outData;          void *outPos = outData;
# Line 156  Line 156 
156    
157        // wrap the data (outData) with the nrrd (outNrrd)        // wrap the data (outData) with the nrrd (outNrrd)
158          if (wrld->isArray) {          if (wrld->isArray) {
159              size_t *sizes = malloc(sizeof(size_t) * wrld->nDims);              size_t *sizes = NEWVEC(size_t, wrld->nDims);
160              for (int i = 0; i < wrld->nDims; i++) {              for (int i = 0; i < wrld->nDims; i++) {
161                  *(sizes + i) = *(wrld->size + i);                  *(sizes + i) = *(wrld->size + i);
162              }              }
# Line 173  Line 173 
173              free(sizes);              free(sizes);
174          }          }
175          else {          else {
176              size_t *sizes = malloc(sizeof(size_t));              size_t *sizes = NEW(size_t);
177              *(sizes) = numStabilized;              *(sizes) = numStabilized;
178              status = nrrdWrap_nva(outNrrd, outData, Diderot_Strands[0]->nrrdType, wrld->nDims, sizes);              status = nrrdWrap_nva(outNrrd, outData, Diderot_Strands[0]->nrrdType, wrld->nDims, sizes);
179              if (status != 0) {              if (status != 0) {
# Line 206  Line 206 
206      else {      else {
207        // 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
208          int outFileNameLen = strlen(wrld->name) + 5;          int outFileNameLen = strlen(wrld->name) + 5;
209          char *outFileName = (char *)malloc(outFileNameLen);          char *outFileName = (char *)CheckedAlloc(outFileNameLen);
210          snprintf (outFileName, outFileNameLen, "%s.txt", wrld->name);          snprintf (outFileName, outFileNameLen, "%s.txt", wrld->name);
211          FILE *outS = fopen(outFileName, "w");          FILE *outS = fopen(outFileName, "w");
212          if (outS == NULL) {          if (outS == NULL) {
# Line 231  Line 231 
231  // this should be the part of the scheduler  // this should be the part of the scheduler
232  void *Diderot_AllocStrand (Strand_t *strand)  void *Diderot_AllocStrand (Strand_t *strand)
233  {  {
234      return malloc(strand->stateSzb);      return CheckedAlloc(strand->stateSzb);
235  }  }
236    
237  // block allocation of an initial collection of strands  // block allocation of an initial collection of strands
# Line 243  Line 243 
243      int32_t *base,              // nDims array of base indices      int32_t *base,              // nDims array of base indices
244      uint32_t *size)             // nDims array of iteration sizes      uint32_t *size)             // nDims array of iteration sizes
245  {  {
246      Diderot_World_t *wrld = (Diderot_World_t *) malloc (sizeof(Diderot_World_t));      Diderot_World_t *wrld = NEW(Diderot_World_t);
247      if (wrld == 0) {      if (wrld == 0) {
248          fprintf (stderr, "unable to allocate world\n");          fprintf (stderr, "unable to allocate world\n");
249          exit (1);          exit (1);
# Line 252  Line 252 
252      wrld->name = name; /* NOTE: we are assuming that name is statically allocated! */      wrld->name = name; /* NOTE: we are assuming that name is statically allocated! */
253      wrld->isArray = isArray;      wrld->isArray = isArray;
254      wrld->nDims = nDims;      wrld->nDims = nDims;
255      wrld->base = (int32_t *) malloc (nDims * sizeof(int32_t));      wrld->base = NEWVEC(int32_t, nDims);
256      wrld->size = (uint32_t *) malloc (nDims * sizeof(uint32_t));      wrld->size = NEWVEC(uint32_t, nDims);
257      size_t numStrands = 1;      size_t numStrands = 1;
258      for (int i = 0;  i < wrld->nDims;  i++) {      for (int i = 0;  i < wrld->nDims;  i++) {
259          numStrands *= size[i];          numStrands *= size[i];
# Line 269  Line 269 
269    
270    // allocate the strand state pointers    // allocate the strand state pointers
271      wrld->numStrands = numStrands;      wrld->numStrands = numStrands;
272      wrld->inState = (void **) malloc (numStrands * sizeof(void *));      wrld->inState = NEWVEC(void *, numStrands);
273      wrld->outState = (void **) malloc (numStrands * sizeof(void *));      wrld->outState = NEWVEC(void *, numStrands);
274      wrld->status = (uint8_t *) malloc (numStrands * sizeof(uint8_t));      wrld->status = NEWVEC(uint8_t, numStrands);
275      if ((wrld->inState == 0) || (wrld->outState == 0) || (wrld->status == 0)) {      if ((wrld->inState == 0) || (wrld->outState == 0) || (wrld->status == 0)) {
276          fprintf (stderr, "unable to allocate strand states\n");          fprintf (stderr, "unable to allocate strand states\n");
277          exit (1);          exit (1);

Legend:
Removed from v.1471  
changed lines
  Added in v.1472

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