Equalizer  1.4.1
share/Equalizer/examples/eqNBody/frameData.h
00001 
00002 /*
00003  * Copyright (c) 2009, Philippe Robert <philippe.robert@gmail.com> 
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * - Redistributions of source code must retain the above copyright notice, this
00009  *   list of conditions and the following disclaimer.
00010  * - Redistributions in binary form must reproduce the above copyright notice,
00011  *   this list of conditions and the following disclaimer in the documentation
00012  *   and/or other materials provided with the distribution.
00013  * - Neither the name of Eyescale Software GmbH nor the names of its
00014  *   contributors may be used to endorse or promote products derived from this
00015  *   software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef EQNBODY_FRAMEDATA_H
00031 #define EQNBODY_FRAMEDATA_H
00032 
00033 #include <eq/eq.h>
00034 #include "client.h" // MAX_NGPUS
00035 
00036 namespace eqNbody
00037 {   
00038     enum NBodyConfig
00039     {
00040         NBODY_CONFIG_RANDOM,
00041         NBODY_CONFIG_SHELL,
00042         NBODY_CONFIG_EXPAND,
00043         NBODY_NUM_CONFIGS
00044     };
00045     
00046     class FrameData : public co::Serializable
00047     {
00048     public:
00049 
00050         FrameData();
00051         virtual ~FrameData();
00052 
00053         void init(unsigned int numBodies);
00054         void initHostData();
00055         void exit();        
00056 
00057         void updateParameters( NBodyConfig config, float clusterScale,
00058                                float velocityScale, float ts );
00059         
00060         void toggleStatistics();
00061         bool useStatistics() const { return _statistics; }
00062         
00063         unsigned int getNumDataProxies( void ) const { return _numDataProxies; }
00064         eq::uint128_t getProxyID( unsigned int ndx ) const
00065             { return _dataProxyID[ndx].identifier; }
00066         eq::uint128_t getProxyVersion( unsigned int ndx ) const
00067             { return _dataProxyID[ndx].version; }
00068         eq::uint128_t getVersionForProxyID( const eq::uint128_t& pid ) const;
00069 
00070         void addProxyID( const eq::uint128_t& pid, const float *range );
00071         void updateProxyID( const eq::uint128_t& pid,
00072                             const eq::uint128_t& version,
00073                             const float *range );
00074         
00075         virtual eq::uint128_t commit();
00076         bool isReady();
00077 
00078         const float* getPosData() const { return _hPos; }
00079         const float* getVelData() const { return _hVel; }
00080         const float* getColData() const { return _hCol; }
00081         
00082         float getTimeStep() const { return _deltaTime; }
00083         float getClusterScale() const { return _clusterScale; }
00084         float getVelocityScale() const { return _velocityScale; }
00085         
00086         float* getPos() const { return _hPos; }
00087         float* getVel() const { return _hVel; }
00088         float* getCol() const { return _hCol; }
00089         
00090         uint32_t getNumBytes( void ) const 
00091             { return 4 * sizeof(float) * _numBodies; }
00092         uint32_t getNumBodies( void ) const { return _numBodies; }
00093 
00094     protected:
00095         virtual void serialize( co::DataOStream& os, 
00096                                 const uint64_t dirtyBits );
00097         virtual void deserialize( co::DataIStream& is, 
00098                                   const uint64_t dirtyBits );
00099 
00100         enum DirtyBits
00101         {
00102             DIRTY_DATA      = co::Serializable::DIRTY_CUSTOM << 0,
00103             DIRTY_PROXYDATA = co::Serializable::DIRTY_CUSTOM << 1,
00104             DIRTY_FLAGS     = co::Serializable::DIRTY_CUSTOM << 2
00105         };
00106         
00107     private:                
00108         void _randomizeData( NBodyConfig config );
00109         
00110         bool            _statistics;
00111         bool            _newParameters;
00112 
00113         uint32_t        _numDataProxies;          // total number of proxies
00114         co::ObjectVersion _dataProxyID[ MAX_NGPUS ];// ID, version
00115         float           _dataRanges[ MAX_NGPUS ]; // ranges covered by proxies
00116 
00117         uint32_t    _numBodies;     // number of bodies in the simulation
00118         float       _deltaTime;     // time step
00119         float       _clusterScale;  // scale of the cluster
00120         float       _velocityScale; // velocity scaling
00121         
00122         float*      _hPos;          // initial position data on the host
00123         float*      _hVel;          // initial velocity data on the host
00124         float*      _hCol;          // initial color data
00125     };
00126 }
00127 
00128 #endif // EQNBODY_FRAMEDATA_H
00129 
Generated on Mon Nov 26 2012 14:41:48 for Equalizer 1.4.1 by  doxygen 1.7.6.1