X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=course%2Fsemester2%2Fpprog%2Fassignment1%2Fsingle-thread%2Fnbody.h;fp=course%2Fsemester2%2Fpprog%2Fassignment1%2Fsingle-thread%2Fnbody.h;h=a0415748087f88678912345c023ea00923774475;hb=83cf58f62ddc5ce9fe44de27327fde27f767ebb6;hp=fc19d059f32179f243909a5262adc5ebf09b9605;hpb=19e590cc4f7dbc186cad9418bf5a2321bfa3fe1a;p=matches%2Fhonours.git diff --git a/course/semester2/pprog/assignment1/single-thread/nbody.h b/course/semester2/pprog/assignment1/single-thread/nbody.h index fc19d059..a0415748 100644 --- a/course/semester2/pprog/assignment1/single-thread/nbody.h +++ b/course/semester2/pprog/assignment1/single-thread/nbody.h @@ -17,10 +17,33 @@ #define SINGLE_THREADED -//These macros will be undefined by the multithreaded versions -#define Simulation_Run(argc, argv) (Graphics_Run(argc, argv)) //Sets up the simulation; in multithreaded versions, will spawn threads +// --- The below macros will be undefined by the multithreaded versions, and replaced with functions --- // + +//Sets up the simulation; in multithreaded versions, will spawn threads +#define Simulation_Run(argc, argv) \ +if (options.draw_graphics) \ + Graphics_Run(argc, argv); \ +else \ +{ \ + while (ExitCondition() == false) \ + { BeforeDraw(); AfterDraw(); } \ +} + #define QuitProgram(error) (runstate = (error == true) ? QUIT : QUIT_ERROR) //Prepares to exit program, is thread safe in multithreaded versions +//Macro to be overwritten in multithreaded versions, called before the graphics is allowed to draw anything +#define BeforeDraw() \ +if (options.verbosity != 0 && universe.steps % options.verbosity == 1) \ + DisplayStatistics(); \ +System_Compute(&universe); + + + +//Macro to be overwritten in multithreaded versions, called after the graphics has finished drawing. +#define AfterDraw() + +// --- Constants and other Macros --- // + #define M_PI 3.14159265358979323846264338327950288 /* pi */ #define G 6.67428E-11 #define DELTA_T 0.05 @@ -71,9 +94,11 @@ typedef struct const char * output; // file to write final positions / velocities of bodies to const char * program; // program name unsigned num_threads; // number of worker threads to spawn (must be greater than 1 for any to be spawned) + unsigned nested_threads; // number of threads to nest computations with (must be greater than 1 for any to be spawned) unsigned num_steps; // number of steps to run before stopping (run indefinately if equal to zero) unsigned timeout; // number of seconds to run before stopping (run indefinately if equal to zero) bool draw_graphics; // whether or not to actually draw graphics + bool pedantic_graphics; // whether the graphics thread will synchronise with the computation thread (true) or just draw as fast as possible (false) bool print_positions; // print positions of bodies to stdout on every step unsigned verbosity; // print statistics every number of steps indicated by this variable clock_t start_clock; // clock cycles done when simulation starts