A user level multi-threaded Particle simulator
Supervisor: Joe Cordina
Observer: Kurt Debattista
User Level Multi-threaded Particle simulator 2Joe Cordina
APT Advanced practical task serve the
purpose of allowing students to design, implement and document a medium to large project Student initiative Understand task + design Research into possible solutions Work alone under supervisor’s guidance
User Level Multi-threaded Particle simulator 3Joe Cordina
Overview
Designing and implementing a user-level multi-threaded particle-in-a-box simulator.
User Level Multi-threaded Particle simulator 4Joe Cordina
Literature Operating Systems II and
Concurrent and Distributed Systems Slides
Any basic mathematics textbook Any basic physics textbook
User Level Multi-threaded Particle simulator 5Joe Cordina
Assessment
50% Design/Implementation 30% Documentation/Inception
Report 20% Presentation/Interview
User Level Multi-threaded Particle simulator 6Joe Cordina
Main issues of APT Implementation
Learn how to use Mesh Provide a multi-threaded particle
simulator 2D view of particles Provide example scenarios Calculate basic physics constants Benchmark your algorithms
User Level Multi-threaded Particle simulator 7Joe Cordina
Mesh Mesh is an advanced very fast
user-level multi-threaded library written in C for CERN (Linux).
It is user-level and thus we will try not to make use of system calls as much as possible.
Memory requirements concerns will be of major focus.
User Level Multi-threaded Particle simulator 8Joe Cordina
Mesh (cont.) Your main header files are Mesh.h and
Scheduler.h Main function provided by void Main(Thread* p, int argc, char** argv);
void Exit(int code);
A large selection of function calls are available to allow thread manipulation
Note that threads can also have a priority
User Level Multi-threaded Particle simulator 9Joe Cordina
Mesh (cont.) #define Thread_Constructor(F,X...)
Scheduler_ThreadConstructor((ThreadMain)(F),X) void Thread_Destructor(Thread*); void Thread_Stop(void); void Thread_Exit(void); void Thread_NewPriority(int priority); void Thread_SetPriority(Thread* p,int priority); int Thread_GetPriority(void); void Thread_Yield(void); void Thread_Preempt(void); void Thread_Join(Thread* process,...); void Thread_Spawn(Thread*,int priority); void Thread_Run(Thread*); void Thread_Runs(Thread* process,...); void Thread_Par(Thread* process,...); void Thread_PriPar(Thread* process,int priority,...); void Thread_SleepUntil(RealTime t); void Thread_Sleep(RealTime t); Thread* Scheduler_ThreadConstructor(ThreadMain main,int stack_size,int
narguments,...);
User Level Multi-threaded Particle simulator 10Joe Cordina
Particle Simulator Using the threads package you will
simulate the behavior of physical particles in a box.
Threads are ideal where each thread performs small amounts of calculation
Thus define box dimensions and let the particles loose in it starting from a random position.
User Level Multi-threaded Particle simulator 11Joe Cordina
Particle Simulator (cont.) Particles in physics have a well defined
behavior Assume that all particles are point
particles When they collide with a wall their angle
of reflection equals angle of incidence. Each particle has a mass and a velocity
(speed with direction)
User Level Multi-threaded Particle simulator 12Joe Cordina
Particle Simulator (cont.) Motion is governed by
sx = x + v * t * cos a
sy = y + v * t * sin a
where sx is distance in x direction sy is distance in y direction v is velocity
t is time a is the direction angle
User Level Multi-threaded Particle simulator 13Joe Cordina
Particle Simulator (cont.) Particles can also collide with each other Yet particles have also momentum and
physics say that initial momentum should equal final momentum in a collision.
Equations given with handouts Be careful when calculating theta to get
final angle One of the main task is an efficient
collision detection between the particles
User Level Multi-threaded Particle simulator 14Joe Cordina
2D view of particles You will be using the svgalib
man svgalib will tell you all Compile using gcc –lvga
vga_init();
vga_setmode(G640x480x256); Then you can use
int vga_drawpixel(int x, int y);
User Level Multi-threaded Particle simulator 15Joe Cordina
2D view of particles The display should be
synchronized to 60 frames a second (Bonus).
Make your program decrease the frames per second depending on the load in the computer.
For timing you can use the RealTime Library.
User Level Multi-threaded Particle simulator 16Joe Cordina
Basic Physics constants You can calculate the average speed of the
particles, the speed distribution and the velocity distribution.
You can calculate the temperature visible produced by your particles in real-time and you can compare it to the ideal one.
The mean Kinetic Energy has to remain constant in a closed box
When numbers are very large <K> =(mvx
2) / N
User Level Multi-threaded Particle simulator 17Joe Cordina
Bonus Material Construct multiple scenarios
Multiple boxes next to each other where each border can store part of the energy of one collision and then pass it on to the next particle that hits it
A leaky box, where if a particle has energy above a certain value, it will escape away
3D equations and visualization of the system Hot walls which transfer constant energy to the particles
but particles which have larger energy will still escape Dampening effect in the box Others you might think of or discussed with me Optimisation techniques on the algorithms Producing graphs of physics constants with time
User Level Multi-threaded Particle simulator 18Joe Cordina
Benchmarking Use the RealTime library to be able
to benchmark the efficiency of your algorithms.
This will give you time delays in the order of s.
User Level Multi-threaded Particle simulator 19Joe Cordina
Documentation Inception report (Friday 1st March)
Analysis/Design Work plan
Report Detailed analysis of problem Discussion of solution (+ others considered) Detailed description of data structures and
algorithms used
User Level Multi-threaded Particle simulator 20Joe Cordina
Presentation 15 minute presentation
Material Content Knowledge of subject Clarity
Interview Answer questions related to APT
User Level Multi-threaded Particle simulator 21Joe Cordina
Interaction Expect to report to supervisor
every other week: Friday Who cannot attend must mail in
progress report + work in progress demo
First meeting Friday 1st March
User Level Multi-threaded Particle simulator 22Joe Cordina
The end
All the best! Good luck! Work hard!