Changeset 941

Show
Ignore:
Timestamp:
10/18/06 17:50:27 (7 years ago)
Author:
leo
Message:

create derived types

Location:
sandbox/trunk/pdp
Files:
3 added
5 modified

Legend:

Unmodified
Added
Removed
  • sandbox/trunk/pdp/build/vc71/N-body/N-body.vcproj

    r939 r941  
    1313                <Configuration 
    1414                        Name="Debug|Win32" 
    15                         OutputDirectory="Debug" 
     15                        OutputDirectory="../Debug" 
    1616                        IntermediateDirectory="Debug" 
    1717                        ConfigurationType="1" 
  • sandbox/trunk/pdp/build/vc71/Replication/Replication.vcproj

    r939 r941  
    112112                        Name="Source Files" 
    113113                        Filter=""> 
     114                        <File 
     115                                RelativePath="..\..\..\src\Replication.cpp"> 
     116                        </File> 
     117                        <File 
     118                                RelativePath="..\..\..\src\Replication.hpp"> 
     119                        </File> 
    114120                </Filter> 
    115121                <Filter 
  • sandbox/trunk/pdp/src/N-body.cpp

    r939 r941  
    3939Particle::toString() const 
    4040{ 
    41         return XERIAL_MESSAGE(Triplet<double>::toString() << format(" m=%1%, v=%2%, a=%3%") % _mass % _velocity.toString() % _acceleration.toString()); 
     41        return XERIAL_MESSAGE(_coordinate.toString() << format(" m=%1%, v=%2%, a=%3%") % _mass % _velocity.toString() % _acceleration.toString()); 
    4242} 
    4343 
     
    7979NBodySimulator::parallelSimulation(double dt, size_t times)  
    8080{ 
     81        XERIAL_INFO(_logger, "parallel mode"); 
     82 
    8183        int numParticle = _particle.size(); 
    82         MPI::COMM_WORLD.BCast(&numParticle, ) 
     84        //MPI::COMM_WORLD.BCast(&numParticle, ) 
     85 
    8386 
    8487        for(size_t step=0; step<times; ++step) 
     
    9396int main(int argc, char** argv) 
    9497{ 
    95         MPIInitializer m(argc, argv); 
     98        // Initialize the MPI library 
     99        // When this MPIInitializer instance is deallocated, MPI::Finalize() will be invoked automatically. 
     100        MPIInitializer m(argc, argv);    
     101        Particle::prepareMPIDatatype();  
    96102        int processID = MPI::COMM_WORLD.Get_rank(); 
    97  
    98103        XERIAL_INFO(_logger, "process id = " << processID); 
     104         
     105        // set up command line option parser 
    99106        enum 
    100107        { 
     
    110117        opt.add(Option(OPT_DISTRIBUTE, "d", "distribute", "distribute mode")); 
    111118        opt.add(OptionWithArgument(OPT_STEP, "s", "step", "STEP", "num calculation steps (default = 100)")); 
    112         opt.add(OptionWithArgument(OPT_PARTICLE, "p", "particle", "NUM", "num particles (default = 10)")); 
     119        opt.add(OptionWithArgument(OPT_NUM_PARTICLE, "p", "particle", "NUM", "num particles (default = 10)")); 
    113120 
    114121        try 
    115122        { 
    116                 opt.getContext(argc, argv); 
     123                // parse command line arguments 
     124                opt.getContext(argc, argv);      
    117125                if(opt.isSet(OPT_HELP)) 
    118126                { 
     
    134142                        randomParticle.add(p); 
    135143                } 
     144 
     145                // simulation phase 
    136146                NBodySimulator simulator(randomParticle); 
    137                  
    138147                int step = Integer::parseInt(opt.getValue(OPT_STEP, "100")); 
    139148                if(opt.isSet(OPT_DISTRIBUTE)) 
     
    155164} 
    156165 
     166void 
     167Particle::prepareMPIDatatype()  
     168{ 
     169        Triplet<double> t; 
     170        Vector<MPI::Aint> tripletDisplacement; 
     171        tripletDisplacement.add(MPI::Get_address(&t.x)); 
     172        tripletDisplacement.add(MPI::Get_address(&t.y)); 
     173        tripletDisplacement.add(MPI::Get_address(&t.z)); 
     174        MPI::Aint base = tripletDisplacement[0]; 
     175        for(int i=0; i<3; ++i) 
     176                tripletDisplacement[i] -= base; 
     177        int tripletBlockLength[] = {1, 1, 1}; 
     178        MPI::Datatype TripletType = MPI::DOUBLE.Create_hindexed(3, tripletBlockLength, &(tripletDisplacement[0])); 
     179        TripletType.Commit(); 
     180        XERIAL_DEBUG(_logger, "Triplet displacement: " <<  tripletDisplacement); 
     181        XERIAL_DEBUG(_logger, "Triplet size = " << TripletType.Get_size()); 
     182        XERIAL_DEBUG(_logger, "sizeof(Triplet) = " << sizeof(Triplet<double>)); 
     183 
     184        Particle p[3]; 
     185        Vector<MPI::Aint> particleDisplacement;; 
     186        particleDisplacement.add(MPI::Get_address(&p[0]._coordinate)); 
     187        particleDisplacement.add(MPI::Get_address(&p[0]._velocity)); 
     188        particleDisplacement.add(MPI::Get_address(&p[0]._acceleration)); 
     189        particleDisplacement.add(MPI::Get_address(&p[0]._mass)); 
     190        base = particleDisplacement[0]; 
     191        for(size_t i=0; i<particleDisplacement.size(); ++i) 
     192                particleDisplacement[i] -= base; 
     193 
     194        int particleBlockLength[] = {1, 1, 1, 1}; 
     195        MPI::Datatype particleDataType[] = {TripletType, TripletType, TripletType, MPI::DOUBLE}; 
     196        MPI::Datatype ParticleType = MPI::Datatype::Create_struct(4, particleBlockLength, &(particleDisplacement[0]), particleDataType); 
     197        ParticleType.Commit(); 
     198 
     199        XERIAL_DEBUG(_logger, "particle displacement: " <<  particleDisplacement); 
     200        XERIAL_DEBUG(_logger, "particle size = " << ParticleType.Get_size()); 
     201        XERIAL_DEBUG(_logger, "sizeof(Particle) = " << sizeof(Particle)); 
     202 
     203 
     204} 
  • sandbox/trunk/pdp/src/N-body.hpp

    r939 r941  
    6363* Particle class represents a two-dimensional point in the universe. 
    6464*/ 
    65 class Particle : public Triplet<double> 
     65class Particle : public xerial::Printable  
    6666{ 
    6767public: 
     68        Particle() 
     69                : _mass(0) 
     70        {} 
    6871        Particle(double x, double y, double z, double mass)  
    69                 : Triplet<double>(x, y, z), _mass(mass) 
     72                : _coordinate(x, y, z), _mass(mass) 
    7073        {} 
    7174        virtual ~Particle() {} 
     
    7376        Force gravitationalForce(const Particle& other, double G) const 
    7477        { 
    75                 Triplet<double> d = *this - other; 
     78                Triplet<double> d = _coordinate - other._coordinate; 
    7679                double distSquare = d.x * d.x + d.y * d.y + d.z * d.z; 
    7780                double c  = G * _mass * other._mass / (distSquare * std::sqrt(distSquare)); 
     
    101104        { 
    102105                _velocity += _acceleration * dt;        // V' = V + A * dt 
    103                 *this += _velocity * dt;                        // P' = P + V * dt 
     106                _coordinate += _velocity * dt;                  // P' = P + V * dt 
    104107        } 
    105108 
     
    118121                return this == boost::addressof(other); 
    119122        } 
     123 
     124        static void prepareMPIDatatype(); 
    120125private: 
    121         double _mass; 
     126        Triplet<double> _coordinate; 
    122127        Velocity _velocity; 
    123128        Acceleration _acceleration; 
     129        double _mass; 
    124130}; 
    125131 
  • sandbox/trunk/pdp/src/Triplet.hpp

    r939 r941  
    2525#define __TRIPLET_HPP20061016161105 
    2626 
    27 #include "xerial/util/Printable.hpp" 
    2827#include "xerial/util/Message.hpp" 
    2928#include "xerial/util/Format.hpp" 
     
    3231 */  
    3332template <class T> 
    34 struct Triplet : public xerial::Printable 
     33struct Triplet  
    3534{ 
    3635        T x;