A user level multithreaded Particle simulator Supervisor Joe

  • Slides: 22
Download presentation
A user level multi-threaded Particle simulator Supervisor: Joe Cordina Observer: Kurt Debattista

A user level multi-threaded Particle simulator Supervisor: Joe Cordina Observer: Kurt Debattista

APT n Advanced practical task serve the purpose of allowing students to design, implement

APT n Advanced practical task serve the purpose of allowing students to design, implement and document a medium to large project n n Student initiative Understand task + design Research into possible solutions Work alone under supervisor’s guidance User Level Multi-threaded Particle simulator Joe Cordina 2

Overview n Designing and implementing a userlevel multi-threaded particle-in-a-box simulator. User Level Multi-threaded Particle

Overview n Designing and implementing a userlevel multi-threaded particle-in-a-box simulator. User Level Multi-threaded Particle simulator Joe Cordina 3

Literature n n n Operating Systems II and Concurrent and Distributed Systems Slides Any

Literature n n n Operating Systems II and Concurrent and Distributed Systems Slides Any basic mathematics textbook Any basic physics textbook User Level Multi-threaded Particle simulator Joe Cordina 4

Assessment n n n 50% Design/Implementation 30% Documentation/Inception Report 20% Presentation/Interview User Level Multi-threaded

Assessment n n n 50% Design/Implementation 30% Documentation/Inception Report 20% Presentation/Interview User Level Multi-threaded Particle simulator Joe Cordina 5

Main issues of APT n Implementation n n n Learn how to use Mesh

Main issues of APT n Implementation n n n Learn how to use Mesh Provide a multi-threaded particle simulator 2 D view of particles Provide example scenarios Calculate basic physics constants Benchmark your algorithms User Level Multi-threaded Particle simulator Joe Cordina 6

Mesh n n n Mesh is an advanced very fast user-level multi-threaded library written

Mesh n n n 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 Joe Cordina 7

Mesh (cont. ) n n Your main header files are Mesh. h and Scheduler.

Mesh (cont. ) n n 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); n n 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 Joe Cordina 8

Mesh (cont. ) n n n n n #define Thread_Constructor(F, X. . . )

Mesh (cont. ) n n n n n #define Thread_Constructor(F, X. . . ) Scheduler_Thread. Constructor((Thread. Main)(F), X) void Thread_Destructor(Thread*); void Thread_Stop(void); void Thread_Exit(void); void Thread_New. Priority(int priority); void Thread_Set. Priority(Thread* p, int priority); int Thread_Get. Priority(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_Pri. Par(Thread* process, int priority, . . . ); void Thread_Sleep. Until(Real. Time t); void Thread_Sleep(Real. Time t); Thread* Scheduler_Thread. Constructor(Thread. Main main, int stack_size, int narguments, . . . ); User Level Multi-threaded Particle simulator Joe Cordina 9

Particle Simulator n n n Using the threads package you will simulate the behavior

Particle Simulator n n n 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 Joe Cordina 10

Particle Simulator (cont. ) n n Particles in physics have a well defined behavior

Particle Simulator (cont. ) n n 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 Joe Cordina 11

Particle Simulator (cont. ) Motion is governed by sx = x + v *

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 n User Level Multi-threaded Particle simulator Joe Cordina 12

Particle Simulator (cont. ) n n n Particles can also collide with each other

Particle Simulator (cont. ) n n n 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 Joe Cordina 13

2 D view of particles n n n You will be using the svgalib

2 D view of particles n n n You will be using the svgalib man svgalib will tell you all Compile using gcc –lvga vga_init(); vga_setmode(G 640 x 480 x 256); Then you can use n int vga_drawpixel(int x, int y); User Level Multi-threaded Particle simulator Joe Cordina 14

2 D view of particles n n n The display should be synchronized to

2 D view of particles n n n 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 Real. Time Library. User Level Multi-threaded Particle simulator Joe Cordina 15

Basic Physics constants n n You can calculate the average speed of the particles,

Basic Physics constants n n 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 Joe Cordina 16

Bonus Material n Construct multiple scenarios n n n n Multiple boxes next to

Bonus Material n Construct multiple scenarios n n n n 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 3 D 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 Joe Cordina 17

Benchmarking n n Use the Real. Time library to be able to benchmark the

Benchmarking n n Use the Real. Time 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 Joe Cordina 18

Documentation n Inception report (Friday 1 st March) n n n Analysis/Design Work plan

Documentation n Inception report (Friday 1 st March) n n n Analysis/Design Work plan Report n n n Detailed analysis of problem Discussion of solution (+ others considered) Detailed description of data structures and algorithms used User Level Multi-threaded Particle simulator Joe Cordina 19

Presentation n 15 minute presentation n n Material Content Knowledge of subject Clarity Interview

Presentation n 15 minute presentation n n Material Content Knowledge of subject Clarity Interview n Answer questions related to APT User Level Multi-threaded Particle simulator Joe Cordina 20

Interaction n Expect to report to supervisor every other week: Friday Who cannot attend

Interaction n Expect to report to supervisor every other week: Friday Who cannot attend must mail in progress report + work in progress demo First meeting Friday 1 st March User Level Multi-threaded Particle simulator Joe Cordina 21

The end n n n All the best! Good luck! Work hard! User Level

The end n n n All the best! Good luck! Work hard! User Level Multi-threaded Particle simulator Joe Cordina 22