Changeset 939
- Timestamp:
- 10/17/06 17:46:07 (7 years ago)
- Location:
- sandbox/trunk/pdp
- Files:
-
- 86 added
- 5 modified
- 1 moved
-
README (modified) (1 diff)
-
build/vc71/Debug (added)
-
build/vc71/N-body.sln (moved) (moved from sandbox/trunk/pdp/build/vc71/N-body/N-body.sln) (2 diffs)
-
build/vc71/N-body/N-body.vcproj (modified) (3 diffs)
-
build/vc71/Release (added)
-
build/vc71/Replication (added)
-
build/vc71/Replication/Replication.vcproj (added)
-
build/vc71/antlr (added)
-
build/vc71/antlr/antlr.vcproj (added)
-
build/vc71/lib (added)
-
build/vc71/xerial_util (added)
-
build/vc71/xerial_util/xerial_util.vcproj (added)
-
src/MPIInitializer.cpp (added)
-
src/MPIInitializer.hpp (added)
-
src/N-body.cpp (modified) (1 diff)
-
src/N-body.hpp (modified) (7 diffs)
-
src/Triplet.hpp (modified) (2 diffs)
-
src/xerial (added)
-
src/xerial/common (added)
-
src/xerial/common/xerial.hpp (added)
-
src/xerial/common/xerial_last.hpp (added)
-
src/xerial/common/xerial_types.hpp (added)
-
src/xerial/detail (added)
-
src/xerial/detail/MemoryChunkAllocator.hpp (added)
-
src/xerial/exception (added)
-
src/xerial/exception/AssertionFailure.cpp (added)
-
src/xerial/exception/AssertionFailure.hpp (added)
-
src/xerial/exception/Exception.cpp (added)
-
src/xerial/exception/Exception.hpp (added)
-
src/xerial/exception/ExceptionUtil.hpp (added)
-
src/xerial/exception/InvalidNumberFormatException.cpp (added)
-
src/xerial/exception/InvalidNumberFormatException.hpp (added)
-
src/xerial/exception/InvalidParameterException.cpp (added)
-
src/xerial/exception/InvalidParameterException.hpp (added)
-
src/xerial/exception/OutOfRangeException.cpp (added)
-
src/xerial/exception/OutOfRangeException.hpp (added)
-
src/xerial/exception/UnsupportedOperation.cpp (added)
-
src/xerial/exception/UnsupportedOperation.hpp (added)
-
src/xerial/exception/assert.hpp (added)
-
src/xerial/log (added)
-
src/xerial/log/LogConfiguration.g (added)
-
src/xerial/log/LogConfigurationLexer.cpp (added)
-
src/xerial/log/LogConfigurationLexer.hpp (added)
-
src/xerial/log/LogConfigurationLexerTokenTypes.hpp (added)
-
src/xerial/log/LogConfigurationLexerTokenTypes.txt (added)
-
src/xerial/log/LogConfigurationParser.cpp (added)
-
src/xerial/log/LogConfigurationParser.hpp (added)
-
src/xerial/log/LogConfigurationTreeParser.cpp (added)
-
src/xerial/log/LogConfigurationTreeParser.hpp (added)
-
src/xerial/log/Logger.cpp (added)
-
src/xerial/log/Logger.hpp (added)
-
src/xerial/util (added)
-
src/xerial/util/Collection.hpp (added)
-
src/xerial/util/Format.hpp (added)
-
src/xerial/util/Integer.cpp (added)
-
src/xerial/util/Integer.hpp (added)
-
src/xerial/util/Iterable.hpp (added)
-
src/xerial/util/List.hpp (added)
-
src/xerial/util/Message.cpp (added)
-
src/xerial/util/Message.hpp (added)
-
src/xerial/util/NonConstructable.cpp (added)
-
src/xerial/util/NonConstructable.hpp (added)
-
src/xerial/util/NonCopyable.hpp (added)
-
src/xerial/util/Printable.cpp (added)
-
src/xerial/util/Printable.hpp (added)
-
src/xerial/util/STLUtil.hpp (added)
-
src/xerial/util/ScopedPointer.hpp (added)
-
src/xerial/util/Singleton.hpp (added)
-
src/xerial/util/StringUtil.cpp (added)
-
src/xerial/util/StringUtil.hpp (added)
-
src/xerial/util/Vector.hpp (added)
-
src/xerial/util/antlr (added)
-
src/xerial/util/antlr/AntlrHelper.hpp (added)
-
src/xerial/util/cui (added)
-
src/xerial/util/cui/OptionParser.cpp (added)
-
src/xerial/util/cui/OptionParser.hpp (added)
-
src/xerial/util/detail (added)
-
src/xerial/util/detail/IteratorImpl.hpp (added)
-
src/xerial/util/detail/STLIteratorWrapper.hpp (added)
-
src/xerial/util/hash_map.hpp (added)
-
src/xerial/util/io (added)
-
src/xerial/util/io/FileUtil.cpp (added)
-
src/xerial/util/io/FileUtil.hpp (added)
-
src/xerial/util/stl (added)
-
src/xerial/util/thread (added)
-
src/xerial/util/thread/CompareAndSwap.cpp (added)
-
src/xerial/util/thread/CompareAndSwap.hpp (added)
-
src/xerial/util/thread/LightMutex.hpp (added)
-
src/xerial/util/thread/Lock.hpp (added)
-
src/xerial/util/thread/ScopeGuard.hpp (added)
-
src/xerial/util/ustring.cpp (added)
-
src/xerial/util/ustring.hpp (added)
Legend:
- Unmodified
- Added
- Removed
-
sandbox/trunk/pdp/README
r936 r939 1 2 3 * required libraries 4 - Boost C++ Library (http://www.boost.org) 5 - MPICH library 6 7 -
sandbox/trunk/pdp/build/vc71/N-body.sln
r936 r939 1 1 Microsoft Visual Studio Solution File, Format Version 8.00 2 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "N-body", "N-body.vcproj", "{A053B03E-06E7-4AA8-AD0E-B5017B668233}" 2 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "N-body", "N-body\N-body.vcproj", "{A053B03E-06E7-4AA8-AD0E-B5017B668233}" 3 ProjectSection(ProjectDependencies) = postProject 4 {6B5B4036-E8C8-4C33-85C0-AA519562D9AC} = {6B5B4036-E8C8-4C33-85C0-AA519562D9AC} 5 EndProjectSection 6 EndProject 7 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Replication", "Replication\Replication.vcproj", "{8730E6B6-A280-4DD1-ABDA-7C4631F40635}" 8 ProjectSection(ProjectDependencies) = postProject 9 {6B5B4036-E8C8-4C33-85C0-AA519562D9AC} = {6B5B4036-E8C8-4C33-85C0-AA519562D9AC} 10 EndProjectSection 11 EndProject 12 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xerial_util", "xerial_util\xerial_util.vcproj", "{6B5B4036-E8C8-4C33-85C0-AA519562D9AC}" 13 ProjectSection(ProjectDependencies) = postProject 14 {A31A9E8B-57D0-4C84-824C-17EAE8F6AE3A} = {A31A9E8B-57D0-4C84-824C-17EAE8F6AE3A} 15 EndProjectSection 16 EndProject 17 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "antlr", "antlr\antlr.vcproj", "{A31A9E8B-57D0-4C84-824C-17EAE8F6AE3A}" 3 18 ProjectSection(ProjectDependencies) = postProject 4 19 EndProjectSection … … 16 31 {A053B03E-06E7-4AA8-AD0E-B5017B668233}.Release.ActiveCfg = Release|Win32 17 32 {A053B03E-06E7-4AA8-AD0E-B5017B668233}.Release.Build.0 = Release|Win32 33 {8730E6B6-A280-4DD1-ABDA-7C4631F40635}.Debug.ActiveCfg = Debug|Win32 34 {8730E6B6-A280-4DD1-ABDA-7C4631F40635}.Debug.Build.0 = Debug|Win32 35 {8730E6B6-A280-4DD1-ABDA-7C4631F40635}.Release.ActiveCfg = Release|Win32 36 {8730E6B6-A280-4DD1-ABDA-7C4631F40635}.Release.Build.0 = Release|Win32 37 {6B5B4036-E8C8-4C33-85C0-AA519562D9AC}.Debug.ActiveCfg = Debug|Win32 38 {6B5B4036-E8C8-4C33-85C0-AA519562D9AC}.Debug.Build.0 = Debug|Win32 39 {6B5B4036-E8C8-4C33-85C0-AA519562D9AC}.Release.ActiveCfg = Release|Win32 40 {6B5B4036-E8C8-4C33-85C0-AA519562D9AC}.Release.Build.0 = Release|Win32 41 {A31A9E8B-57D0-4C84-824C-17EAE8F6AE3A}.Debug.ActiveCfg = Debug|Win32 42 {A31A9E8B-57D0-4C84-824C-17EAE8F6AE3A}.Debug.Build.0 = Debug|Win32 43 {A31A9E8B-57D0-4C84-824C-17EAE8F6AE3A}.Release.ActiveCfg = Release|Win32 44 {A31A9E8B-57D0-4C84-824C-17EAE8F6AE3A}.Release.Build.0 = Release|Win32 18 45 EndGlobalSection 19 46 GlobalSection(ExtensibilityGlobals) = postSolution -
sandbox/trunk/pdp/build/vc71/N-body/N-body.vcproj
r936 r939 23 23 MinimalRebuild="TRUE" 24 24 BasicRuntimeChecks="3" 25 RuntimeLibrary="5" 25 RuntimeLibrary="1" 26 TreatWChar_tAsBuiltInType="TRUE" 27 ForceConformanceInForLoopScope="TRUE" 28 RuntimeTypeInfo="TRUE" 26 29 UsePrecompiledHeader="0" 27 30 WarningLevel="3" … … 32 35 <Tool 33 36 Name="VCLinkerTool" 37 AdditionalDependencies="cxxd.lib mpi.lib xerial_utild.lib" 34 38 OutputFile="$(OutDir)/N-body.exe" 35 39 LinkIncremental="2" 40 AdditionalLibraryDirectories="../lib" 41 IgnoreAllDefaultLibraries="FALSE" 36 42 GenerateDebugInformation="TRUE" 37 43 ProgramDatabaseFile="$(OutDir)/N-body.pdb" … … 114 120 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> 115 121 <File 122 RelativePath="..\..\..\src\MPIInitializer.cpp"> 123 </File> 124 <File 125 RelativePath="..\..\..\src\MPIInitializer.hpp"> 126 </File> 127 <File 116 128 RelativePath="..\..\..\src\N-body.cpp"> 117 129 </File> -
sandbox/trunk/pdp/src/N-body.cpp
r936 r939 21 21 // $Author$ 22 22 //-------------------------------------------------- 23 #include <mpi.h> 24 #include <iostream> 23 25 #include "N-body.hpp" 26 #include "MPIInitializer.hpp" 27 #include <boost/random.hpp> 28 #include "xerial/util/cui/OptionParser.hpp" 29 #include "xerial/log/Logger.hpp" 30 #include "xerial/util/Message.hpp" 31 #include "xerial/util/Format.hpp" 32 #include "xerial/util/StringUtil.hpp" 33 #include "xerial/util/Integer.hpp" 34 #include "xerial/common/xerial_last.hpp" 35 36 XERIAL_LOGGER(_logger, NBodySimulator) 37 38 std::string 39 Particle::toString() const 40 { 41 return XERIAL_MESSAGE(Triplet<double>::toString() << format(" m=%1%, v=%2%, a=%3%") % _mass % _velocity.toString() % _acceleration.toString()); 42 } 43 44 NBodySimulator::NBodySimulator(Vector<Particle>& particle, double gravity) 45 : _particle(particle), _gravity(gravity), _time(0) 46 { 47 48 } 49 50 NBodySimulator::~NBodySimulator() 51 { 52 53 } 54 55 void 56 NBodySimulator::naiveUpdate(double dt) 57 { 58 for(Vector<Particle>::iterator i = _particle.begin(); i != _particle.end(); ++i) 59 { 60 // update the acceleration of each particle by computing mutual gravitational force between it and the other particles 61 i->updateAcceleration(_particle.begin(), _particle.end(), _gravity); 62 i->move(dt); // update the location 63 } 64 _time += dt; 65 } 66 67 void 68 NBodySimulator::naiveSimulation(double dt, size_t times) 69 { 70 for(size_t step=0; step<times; ++step) 71 { 72 XERIAL_DEBUG(_logger, "step " << step); 73 naiveUpdate(dt); 74 XERIAL_DEBUG(_logger, "\n" << StringUtil::join(_particle, "\n")); 75 } 76 } 77 78 void 79 NBodySimulator::parallelSimulation(double dt, size_t times) 80 { 81 int numParticle = _particle.size(); 82 MPI::COMM_WORLD.BCast(&numParticle, ) 83 84 for(size_t step=0; step<times; ++step) 85 { 86 XERIAL_DEBUG(_logger, "step " << step); 87 naiveUpdate(dt); 88 XERIAL_DEBUG(_logger, "\n" << StringUtil::join(_particle, "\n")); 89 } 90 } 24 91 25 92 93 int main(int argc, char** argv) 94 { 95 MPIInitializer m(argc, argv); 96 int processID = MPI::COMM_WORLD.Get_rank(); 97 98 XERIAL_INFO(_logger, "process id = " << processID); 99 enum 100 { 101 OPT_HELP, 102 OPT_VERBOSE, 103 OPT_DISTRIBUTE, 104 OPT_STEP, 105 OPT_NUM_PARTICLE 106 }; 107 OptionParser opt; 108 opt.add(Option(OPT_HELP, "h", "help", "display help messages")); 109 opt.add(Option(OPT_VERBOSE, "v", "verbose", "display verbose log messages")); 110 opt.add(Option(OPT_DISTRIBUTE, "d", "distribute", "distribute mode")); 111 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)")); 113 114 try 115 { 116 opt.getContext(argc, argv); 117 if(opt.isSet(OPT_HELP)) 118 { 119 cerr << opt.createHelpMessage() << endl; 120 return RETURN_WITH_SUCCESS; 121 } 122 123 // prepare random particles 124 boost::mt19937 mt; 125 boost::uniform_real<double> randomNumberRange(0, 10000); 126 boost::variate_generator<boost::mt19937, boost::uniform_real<double> > die(mt, randomNumberRange); 127 Vector<Particle> randomParticle; 128 int numParticle = Integer::parseInt(opt.getValue(OPT_NUM_PARTICLE, "10")); 129 for(int i=0; i<numParticle; i++) 130 { 131 Particle p(die(), die(), die(), die()); 132 p.setVelocity(Velocity(die(), die(), die())); 133 XERIAL_DEBUG(_logger, p); 134 randomParticle.add(p); 135 } 136 NBodySimulator simulator(randomParticle); 137 138 int step = Integer::parseInt(opt.getValue(OPT_STEP, "100")); 139 if(opt.isSet(OPT_DISTRIBUTE)) 140 simulator.parallelSimulation(1, step); 141 else 142 simulator.naiveSimulation(1, step); 143 144 } 145 catch(InvalidParameterException& e) 146 { 147 cerr << e.what(); 148 cerr << opt.createHelpMessage() << endl; 149 } 150 catch(exception& e) 151 { 152 cerr << e.what(); 153 } 154 155 } 156 -
sandbox/trunk/pdp/src/N-body.hpp
r936 r939 28 28 #include <vector> 29 29 #include "Triplet.hpp" 30 #include <boost/utility/addressof.hpp> 31 #include "xerial/util/Printable.hpp" 32 #include "xerial/util/Vector.hpp" 30 33 31 34 /* 32 * The class Universe defines global constant values ;35 * The class Universe defines global constant values. 33 36 */ 34 37 class Universe … … 41 44 struct Force : public Triplet<double> 42 45 { 46 Force() : Triplet<double>(0, 0, 0) {} 43 47 Force(double fx, double fy, double fz) : Triplet<double>(fx, fy, fz) {} 44 48 … … 55 59 typedef Triplet<double> Velocity; 56 60 typedef Triplet<double> Acceleration; 57 58 61 59 62 /** … … 79 82 // double r = std::sqrt(distSquare); 80 83 // double F = (Universe::gravity() * _mass * other._mass) / (r * r); 81 // return Force(F * (dx / r), F * (dy / r), F * (dz / r)); 84 // return Force(F * (dx / r), F * (dy / r), F * (dz / r)); // dx / r = cosign of the angle between F and x axis 82 85 } 83 86 … … 88 91 for(ParticleIter i = begin; i != end; ++i) 89 92 { 90 if(this != i)93 if(this != boost::addressof(*i)) 91 94 force.push_back(gravitationalForce(*i, G)); 92 95 } 93 96 Force currentForce = Force::superposition(force.begin(), force.end()); 94 _acceleration = currentForce / _mass; // F = ma 97 _acceleration = currentForce / _mass; // F = ma i.e. a = F / m 95 98 } 96 99 … … 108 111 const Acceleration& getAcceleration() const { return _acceleration; } 109 112 void setAcceleration(const Acceleration& a) { _acceleration = a; } 113 114 std::string toString() const; 115 116 bool operator==(const Particle& other) const 117 { 118 return this == boost::addressof(other); 119 } 110 120 private: 111 121 double _mass; … … 114 124 }; 115 125 126 class NBodySimulator 127 { 128 public: 129 NBodySimulator(xerial::Vector<Particle>& particle, double gravity = Universe::gravity()); 130 virtual ~NBodySimulator(); 131 132 void naiveSimulation(double dt, size_t times); 133 void parallelSimulation(double dt, size_t times); 134 135 protected: 136 void naiveUpdate(double dt); 137 138 private: 139 xerial::Vector<Particle>& _particle; 140 double _time; 141 double _gravity; 142 }; 143 116 144 117 145 #endif //__NBODY_HPP20061016161026 -
sandbox/trunk/pdp/src/Triplet.hpp
r936 r939 25 25 #define __TRIPLET_HPP20061016161105 26 26 27 #include "xerial/util/Printable.hpp" 28 #include "xerial/util/Message.hpp" 29 #include "xerial/util/Format.hpp" 27 30 /* 28 31 * Triplet class represents a 3-dimensional vector 29 32 */ 30 33 template <class T> 31 struct Triplet 34 struct Triplet : public xerial::Printable 32 35 { 33 36 T x; … … 59 62 return Triplet(x / val, y / val, z / val); 60 63 } 64 65 std::string toString() const 66 { 67 using namespace xerial; 68 return XERIAL_MESSAGE(format("(%1%, %2%, %3%)") % x % y % z); 69 } 61 70 }; 62 71


