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

SCM Repository

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

Diff of /branches/pure-cfg/src/lib/common/output.c

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

revision 1518, Sat Oct 8 02:39:41 2011 UTC revision 1519, Sun Oct 9 18:30:16 2011 UTC
# Line 10  Line 10 
10    
11  #include <stdio.h>  #include <stdio.h>
12  #include "Diderot/diderot.h"  #include "Diderot/diderot.h"
 #include "Diderot/output.h"  
13  #include <teem/nrrd.h>  #include <teem/nrrd.h>
14  #include <teem/air.h>  #include <teem/air.h>
15    
16    // FIXME: to make this compatible with OpenCL (and CUDA), we should be copying the
17    // output state to the output array on the GPU and then just uploading the output
18    // array to the CPU.  This will require changing the interface of these functions.
19    
20  /*! \brief Print the strand output state to a text file.  /*! \brief Print the strand output state to a text file.
21   */   */
22  void Diderot_Print (Output_Args_t *args)  void Diderot_Print (Diderot_World_t *wrld)
23  {  {
24        WorldPrefix_t *hdr = (WorldPrefix_t *)wrld;
25      airArray *mop = airMopNew();      airArray *mop = airMopNew();
26    
27    // 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
28      int outFileNameLen = strlen(args->name) + 5;      int outFileNameLen = strlen(hdr->name) + 5;
29      char *outFileName = (char *)CheckedAlloc(outFileNameLen);      char *outFileName = (char *)CheckedAlloc(outFileNameLen);
30      airMopAdd(mop, outFileName, airFree, airMopAlways);      airMopAdd(mop, outFileName, airFree, airMopAlways);
31      snprintf (outFileName, outFileNameLen, "%s.txt", args->name);      snprintf (outFileName, outFileNameLen, "%s.txt", hdr->name);
32      FILE *outS = fopen(outFileName, "w");      FILE *outS = fopen(outFileName, "w");
33      if (outS == NULL) {      if (outS == NULL) {
34          fprintf (stderr, "Cannot open output file %s\n", outFileName);          fprintf (stderr, "Cannot open output file %s\n", outFileName);
# Line 33  Line 37 
37      }      }
38      airMopAdd(mop, outS, (airMopper)airFclose, airMopAlways);      airMopAdd(mop, outS, (airMopper)airFclose, airMopAlways);
39    
40      uint8_t *strandPtr = (uint8_t *)args->inState;    // print the strand output states
41      for (int i = 0;  i < args->numStrands;  i++, strandPtr += args->outputSzb) {      for (int i = 0;  i < hdr->numStrands;  i++) {
42            if (hdr->status[i] == DIDEROT_STABLE) {
43          if (args->status[i] == DIDEROT_STABLE) {              Diderot_Strands[0]->print (outS, Diderot_InState(wrld, i));
             Diderot_Strands[0]->print (outS, strandPtr);  
44          }          }
45      }      }
46    
47      airMopOkay(mop);      airMopOkay(mop);
48  }  }
49    
50    /*! \brief Output the strand output state to a nrrd file.
 /*! \brief Output the strand output state to a nrrd or text file.  
51   */   */
52  void Diderot_Output (Output_Args_t *args)  void Diderot_Output (Diderot_World_t *wrld, size_t outStateSzb)
53  {  {
54        WorldPrefix_t *hdr = (WorldPrefix_t *)wrld;
55      airArray *mop = airMopNew();      airArray *mop = airMopNew();
56      int status;      int status;
57      char *err;      char *err;
58    
59    // get correct output file name    // get correct output file name
60      int outFileNameLen = strlen(args->name) + 6;      int outFileNameLen = strlen(hdr->name) + 6;
61      char *outFileName = (char *)CheckedAlloc(outFileNameLen);      char *outFileName = (char *)CheckedAlloc(outFileNameLen);
62      airMopAdd(mop, outFileName, airFree, airMopAlways);      airMopAdd(mop, outFileName, airFree, airMopAlways);
63      snprintf (outFileName, outFileNameLen, "%s.nrrd", args->name);      snprintf (outFileName, outFileNameLen, "%s.nrrd", hdr->name);
64      fprintf(stderr, "%d", 1);      fprintf(stderr, "%d", 1);
65    // allocate the correct amount of space for output  
66      int numStabilized = 0;    // calculate the amount of space needed for the output array
67      for (int i = 0;  i < args->numStrands;  i++) {      int numStabilized;
68          if (args->status[i] == DIDEROT_STABLE)      if (hdr->isArray) {
69            numStabilized = hdr->numStrands;
70        }
71        else {
72            numStabilized = 0;
73            for (int i = 0;  i < hdr->numStrands;  i++) {
74                if (hdr->status[i] == DIDEROT_STABLE)
75              numStabilized++;              numStabilized++;
76      }      }
77      void *outData = CheckedAlloc(numStabilized * args->outputSzb);      }
78    
79      // allocate the output object
80        void *outData = CheckedAlloc(numStabilized * outStateSzb);
81      airMopAdd(mop, outData, airFree, airMopAlways);      airMopAdd(mop, outData, airFree, airMopAlways);
82      fprintf(stderr, "%d", 2);      fprintf(stderr, "%d", 2);
83    
84    // copy data into outData    // copy data into outData
85      void *outPos = outData;      void *outPos = outData;
86      for (int i = 0;  i < args->numStrands;  i++) {      for (int i = 0;  i < hdr->numStrands;  i++) {
87          if (args->status[i] == DIDEROT_STABLE) {          if (hdr->status[i] == DIDEROT_STABLE) {
88              Diderot_Strands[0]->output (outPos, &args->inState[i]);              Diderot_Strands[0]->output (outPos, Diderot_InState(wrld, i));
89              outPos += args->outputSzb;              outPos += outStateSzb;
90          }          }
91      }      }
92    
# Line 90  Line 102 
102      fprintf(stderr, "%d", 4);      fprintf(stderr, "%d", 4);
103    
104    // wrap the data (outData) with the nrrd (outNrrd)    // wrap the data (outData) with the nrrd (outNrrd)
105      if (args->isArray) {      if (hdr->isArray) {
106          size_t *sizes = NEWVEC(size_t, args->nDims + 1);          size_t *sizes = NEWVEC(size_t, hdr->nDims + 1);
107          airMopAdd(mop, sizes, airFree, airMopAlways);          airMopAdd(mop, sizes, airFree, airMopAlways);
108          switch(Diderot_Strands[0]->nrrdType) {          switch(Diderot_Strands[0]->nrrdType) {
109              case nrrdTypeInt:              case nrrdTypeInt:
110              case nrrdTypeFloat:              case nrrdTypeFloat:
111                  sizes[0] = args->outputSzb >> 2;                  sizes[0] = outStateSzb >> 2;
112                  break;                  break;
113              case nrrdTypeLLong:              case nrrdTypeLLong:
114              case nrrdTypeDouble:              case nrrdTypeDouble:
115                  sizes[0] = args->outputSzb >> 3;                  sizes[0] = outStateSzb >> 3;
116                  break;                  break;
117              default:              default:
118                  fprintf(stderr, "Bad nrrdType\n");                  fprintf(stderr, "Bad nrrdType\n");
# Line 108  Line 120 
120                  exit(1);                  exit(1);
121                  break;                  break;
122          }          }
123          for (int i = 1; i <= args->nDims; i++) {          for (int i = 1; i <= hdr->nDims; i++) {
124              sizes[i] = args->size[args->nDims - i];              sizes[i] = hdr->size[hdr->nDims - i];
125          }          }
126          status = nrrdWrap_nva(outNrrd, outData, Diderot_Strands[0]->nrrdType, args->nDims + 1, sizes);          status = nrrdWrap_nva(outNrrd, outData, Diderot_Strands[0]->nrrdType, hdr->nDims + 1, sizes);
127          if (status) {          if (status) {
128              err = biffGetDone(NRRD);              err = biffGetDone(NRRD);
129              fprintf(stderr, "Trouble wrapping nrrd struct:\n%s", err);              fprintf(stderr, "Trouble wrapping nrrd struct:\n%s", err);
# Line 126  Line 138 
138          switch(Diderot_Strands[0]->nrrdType) {          switch(Diderot_Strands[0]->nrrdType) {
139              case nrrdTypeInt:              case nrrdTypeInt:
140              case nrrdTypeFloat:              case nrrdTypeFloat:
141                  sizes[0] = args->outputSzb >> 2;                  sizes[0] = outStateSzb >> 2;
142                  break;                  break;
143              case nrrdTypeLLong:              case nrrdTypeLLong:
144              case nrrdTypeDouble:              case nrrdTypeDouble:
145                  sizes[0] = args->outputSzb >> 3;                  sizes[0] = outStateSzb >> 3;
146                  break;                  break;
147              default:              default:
148                  fprintf(stderr, "Bad nrrdType\n");                  fprintf(stderr, "Bad nrrdType\n");
# Line 139  Line 151 
151                  break;                  break;
152          }          }
153          sizes[1] = numStabilized;          sizes[1] = numStabilized;
154          status = nrrdWrap_nva(outNrrd, outData, Diderot_Strands[0]->nrrdType, args->nDims, sizes);          status = nrrdWrap_nva(outNrrd, outData, Diderot_Strands[0]->nrrdType, hdr->nDims, sizes);
155          if (status != 0) {          if (status != 0) {
156              err = biffGetDone(NRRD);              err = biffGetDone(NRRD);
157              fprintf(stderr, "Trouble wrapping nrrd struct:\n%s", err);              fprintf(stderr, "Trouble wrapping nrrd struct:\n%s", err);

Legend:
Removed from v.1518  
changed lines
  Added in v.1519

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