examples/eqNBody/frameData.h

00001 /*
00002  * Copyright (c) 2009, Philippe Robert <probert@eyescale.ch> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #ifndef EQNBODY_FRAMEDATA_H
00019 #define EQNBODY_FRAMEDATA_H
00020 
00021 #include <eq/eq.h>
00022 #include "client.h" // MAX_NGPUS
00023 
00024 namespace eqNbody
00025 {   
00026     enum NBodyConfig
00027     {
00028         NBODY_CONFIG_RANDOM,
00029         NBODY_CONFIG_SHELL,
00030         NBODY_CONFIG_EXPAND,
00031         NBODY_NUM_CONFIGS
00032     };
00033     
00034     class FrameData : public eq::Object
00035     {
00036     public:
00037 
00038         FrameData();
00039         virtual ~FrameData();
00040 
00041         void init(unsigned int numBodies);
00042         void exit();        
00043 
00044         void updateParameters(NBodyConfig config, float clusterScale, float velocityScale, float ts);
00045         
00046         void toggleStatistics();
00047         bool useStatistics() const { return _statistics; }
00048         
00049         unsigned int getNumDataProxies( void ) const { return _numDataProxies; }
00050         unsigned int getProxyID( unsigned int ndx ) const { return _dataProxyID[ndx][0]; }
00051         unsigned int getProxyVersion( unsigned int ndx ) const { return _dataProxyID[ndx][1]; }
00052         unsigned int getVersionForProxyID( unsigned int pid ) const;
00053 
00054         void addProxyID( unsigned int pid, const float *range );
00055         void updateProxyID( unsigned int pid, unsigned int version, const float *range );
00056         
00057         virtual uint32_t commit();
00058         bool isReady();
00059 
00060         const float* getPosData() const {return _hPos;}
00061         const float* getVelData() const {return _hVel;}
00062         const float* getColData() const {return _hCol;}
00063         
00064         float getTimeStep() const { return _deltaTime; }
00065         float getClusterScale() const { return _clusterScale; }
00066         float getVelocityScale() const { return _velocityScale; }
00067         
00068         float* getPos() const { return _hPos; }
00069         float* getVel() const { return _hVel; }
00070         float* getCol() const { return _hCol; }
00071         
00072         unsigned int getNumBytes( void ) const { return 4*sizeof(float)*_numBodies; }
00073         unsigned int getNumBodies( void ) const { return _numBodies; }
00074 
00075     protected:
00076         virtual void serialize( eq::net::DataOStream& os, const uint64_t dirtyBits );
00077         virtual void deserialize( eq::net::DataIStream& is, const uint64_t dirtyBits );
00078 
00079         enum DirtyBits
00080         {
00081             DIRTY_DATA      = eq::Object::DIRTY_CUSTOM << 0,
00082             DIRTY_PROXYDATA = eq::Object::DIRTY_CUSTOM << 1,
00083             DIRTY_FLAGS     = eq::Object::DIRTY_CUSTOM << 2
00084         };
00085         
00086     private:                
00087         void _randomizeData(NBodyConfig config);
00088         
00089         bool            _statistics;
00090         bool            _newParameters;
00091 
00092         unsigned int    _numDataProxies;            // total number of proxies
00093         unsigned int    _dataProxyID[MAX_NGPUS][2]; // ID, version
00094         float           _dataRanges[MAX_NGPUS];     // ranges covered by proxies
00095 
00096         unsigned int    _numBodies;     // number of bodies in the simulation
00097         float           _deltaTime;     // time step
00098         float           _clusterScale;  // scale of the cluster
00099         float           _velocityScale; // velocity scaling
00100         
00101         float*          _hPos;          // initial position data on the host
00102         float*          _hVel;          // initial velocity data on the host
00103         float*          _hCol;          // initial color data
00104     };
00105 }
00106 
00107 
00108 #endif // EQNBODY_FRAMEDATA_H
00109 
Generated on Mon Aug 10 18:58:33 2009 for Equalizer 0.9 by  doxygen 1.5.8