Changeset 941
- Timestamp:
- 10/18/06 17:50:27 (7 years ago)
- Location:
- sandbox/trunk/pdp
- Files:
-
- 3 added
- 5 modified
-
assignment.txt (added)
-
build/vc71/N-body/N-body.vcproj (modified) (1 diff)
-
build/vc71/Replication/Replication.vcproj (modified) (1 diff)
-
src/N-body.cpp (modified) (6 diffs)
-
src/N-body.hpp (modified) (4 diffs)
-
src/Replication.cpp (added)
-
src/Replication.hpp (added)
-
src/Triplet.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sandbox/trunk/pdp/build/vc71/N-body/N-body.vcproj
r939 r941 13 13 <Configuration 14 14 Name="Debug|Win32" 15 OutputDirectory=" Debug"15 OutputDirectory="../Debug" 16 16 IntermediateDirectory="Debug" 17 17 ConfigurationType="1" -
sandbox/trunk/pdp/build/vc71/Replication/Replication.vcproj
r939 r941 112 112 Name="Source Files" 113 113 Filter=""> 114 <File 115 RelativePath="..\..\..\src\Replication.cpp"> 116 </File> 117 <File 118 RelativePath="..\..\..\src\Replication.hpp"> 119 </File> 114 120 </Filter> 115 121 <Filter -
sandbox/trunk/pdp/src/N-body.cpp
r939 r941 39 39 Particle::toString() const 40 40 { 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()); 42 42 } 43 43 … … 79 79 NBodySimulator::parallelSimulation(double dt, size_t times) 80 80 { 81 XERIAL_INFO(_logger, "parallel mode"); 82 81 83 int numParticle = _particle.size(); 82 MPI::COMM_WORLD.BCast(&numParticle, ) 84 //MPI::COMM_WORLD.BCast(&numParticle, ) 85 83 86 84 87 for(size_t step=0; step<times; ++step) … … 93 96 int main(int argc, char** argv) 94 97 { 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(); 96 102 int processID = MPI::COMM_WORLD.Get_rank(); 97 98 103 XERIAL_INFO(_logger, "process id = " << processID); 104 105 // set up command line option parser 99 106 enum 100 107 { … … 110 117 opt.add(Option(OPT_DISTRIBUTE, "d", "distribute", "distribute mode")); 111 118 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)")); 113 120 114 121 try 115 122 { 116 opt.getContext(argc, argv); 123 // parse command line arguments 124 opt.getContext(argc, argv); 117 125 if(opt.isSet(OPT_HELP)) 118 126 { … … 134 142 randomParticle.add(p); 135 143 } 144 145 // simulation phase 136 146 NBodySimulator simulator(randomParticle); 137 138 147 int step = Integer::parseInt(opt.getValue(OPT_STEP, "100")); 139 148 if(opt.isSet(OPT_DISTRIBUTE)) … … 155 164 } 156 165 166 void 167 Particle::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 63 63 * Particle class represents a two-dimensional point in the universe. 64 64 */ 65 class Particle : public Triplet<double>65 class Particle : public xerial::Printable 66 66 { 67 67 public: 68 Particle() 69 : _mass(0) 70 {} 68 71 Particle(double x, double y, double z, double mass) 69 : Triplet<double>(x, y, z), _mass(mass)72 : _coordinate(x, y, z), _mass(mass) 70 73 {} 71 74 virtual ~Particle() {} … … 73 76 Force gravitationalForce(const Particle& other, double G) const 74 77 { 75 Triplet<double> d = *this - other;78 Triplet<double> d = _coordinate - other._coordinate; 76 79 double distSquare = d.x * d.x + d.y * d.y + d.z * d.z; 77 80 double c = G * _mass * other._mass / (distSquare * std::sqrt(distSquare)); … … 101 104 { 102 105 _velocity += _acceleration * dt; // V' = V + A * dt 103 *this+= _velocity * dt; // P' = P + V * dt106 _coordinate += _velocity * dt; // P' = P + V * dt 104 107 } 105 108 … … 118 121 return this == boost::addressof(other); 119 122 } 123 124 static void prepareMPIDatatype(); 120 125 private: 121 double _mass;126 Triplet<double> _coordinate; 122 127 Velocity _velocity; 123 128 Acceleration _acceleration; 129 double _mass; 124 130 }; 125 131 -
sandbox/trunk/pdp/src/Triplet.hpp
r939 r941 25 25 #define __TRIPLET_HPP20061016161105 26 26 27 #include "xerial/util/Printable.hpp"28 27 #include "xerial/util/Message.hpp" 29 28 #include "xerial/util/Format.hpp" … … 32 31 */ 33 32 template <class T> 34 struct Triplet : public xerial::Printable33 struct Triplet 35 34 { 36 35 T x;


