RE: [pooma-dev] IO question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [pooma-dev] IO question



Christian,

  Sorry no one has gotten back to you sooner.

  Initializing Pooma arrays with data from disk should be straight-forward,
provided you can write the C++ code to read the file (i.e., you understand
how the 3-D array is stored in that file). Pooma 2 Arrays and Fields can be
indexed in scalar mode and this may be the quickest way to get something
working. If you are running in parallel, then you may need to do a bit of
extra work. 

  For example, if the shorts are stored in column major order in a binary
file, and you are running in serial, the simplest thing to do would be to
just write a loop reading a short and stuffing it into the Field. I'll use
an Array here since I don't have to invent as many details (besides, I'm not
sure what good a Field of shorts is - you can't use differential operators
on shorts, so it isn't obvious what Field is buying you that Array doesn't
have).

(Note that I haven't tried to compile these examples, but they should be
approximately right.)

      typedef Array<3,short,Brick> Array_t;

      // These are the dimensions of the data stored in 
      // the file - where these come from, I don't know.

      int nx, ny, nz; // = ???
      Array_t a(nx, ny, nz);

      // The name of the file
      
      const char *filename; // = ???

      ifstream fin(filename, std::ios::binary)

      Pooma::blockAndEvaluate(); // good practice to put this in before 
                                 // scalar access as out-of-order evaluators
                                 // might not be finished modifying the
array

      short s;
      for (int k = 0; k < nz; ++k)
        for (int j = 0; j < ny; ++j)
          for (int i = 0; i < nx; ++i)
            {
              fin.read(&s,sizeof(s));
              if (fin.gcount() != sizeof(s)) 
                ; // Ack! read error!
              a(i,j,k) = s;
            }

Actually, you can be trickier here if the data is in column major format as
that is the storage order used by Brick-Engine. Thus you could read all of
the data at once and construct the brick engine directly from the input
buffer - i.e. something like this:

      short pbuff = new short[nx*ny*nz];
      fin.read(pbuff, nx*ny*nz*sizeof(short));
      // check fin.gcount() to make sure there were no errors

      typedef Interval<1> D1_t;
      Interval<Dim> domain(D1_t(nx),D1_t(ny),D1_t(nz));
      Array_t::Engine_t e(pbuff, domain);
      Array_t a(e);

Note that this array does not own its data - its lifetime is managed by that
of pbuff. If this is bad, you can declare a new array, make a copy, and
delete pbuff; i.e.

      Array_t b(domain);
      b = a;
      Pooma::blockAndEvaluate();
      delete pbuff; // don't use a after this as it is invalid!!!

If the shorts are in an ASCII file, you'll have to parse the file, which
will depend on its format.

If your array is parallel and all the data is in a single file (in a single
block - i.e. as above), you can declare the parallel array and a
Remote<Brick> array, read the data into the Remote<Brick> on context 0 only,
and then perform the assignment on all contexts to distribute the array. If
the data in the file is stored in a patch-decomposed format, then things get
trickier. 

  I hope this helps. If this is not sufficient, we'll need more detail about
exactly what it is that you're trying to do.

  Also, you should be warned that we are switching over to the experimental
"Field" that was distributed in Pooma 2.3 as src/NewField. The old Field is
deprecated and will be gone in the Pooma 2.4 release. This will require at
least minor changes to your code (the template arguments to Field have
changed), and if you were using more advanced centerings, then the changes
may be more substantial (the resulting code should be simpler - we've spent
a lot of time trying to clean up the Field abstraction).

  Jim


> -----Original Message-----
> From: Riedel, Christian H., M.D. [mailto:Riedel.Christian@xxxxxxxx]
> Sent: Thursday, September 27, 2001 9:56 AM
> To: pooma-dev@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [pooma-dev] IO question
> 
> 
> Dear sirs,
> 
> I am currently working on a simulation project in which I especially 
> need the Field and Particle classes in POOMA. I would like to 
> import a 
> 3-dimensional array of short integer values from a file into 
> an instance 
> of the Field class. Which would be the best way to get this done ? 
> Thank you very much in advance,
> 
> Christian Riedel
>