From: Sam Moore Date: Sun, 9 Sep 2012 11:37:21 +0000 (+0800) Subject: Parallel Programming - Trivial X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=19e590cc4f7dbc186cad9418bf5a2321bfa3fe1a;p=matches%2Fhonours.git Parallel Programming - Trivial Dear Git, It has been a while since I sent you a personal message. I hope this hasn't offended you. A Deer, Sam --- diff --git a/course/semester2/pprog/assignment1/mthread/nbody.c b/course/semester2/pprog/assignment1/mthread/nbody.c index 42b97cf4..4acf28f2 100644 --- a/course/semester2/pprog/assignment1/mthread/nbody.c +++ b/course/semester2/pprog/assignment1/mthread/nbody.c @@ -87,16 +87,11 @@ void * Compute_Thread(void * arg) // The main computation loop while (true) { - - if (runstate != RUN) pthread_exit(NULL); //Check whether the thread needs to exit - - - //Check whether the program should quit due to steps being computed, or a timeout if (ExitCondition()) { QuitProgram(false); - continue; // The check at the start of the next loop will stop the thread + pthread_exit(NULL); } if (options.draw_graphics == false && options.verbosity != 0 diff --git a/course/semester2/pprog/assignment1/openmp/nbody.c b/course/semester2/pprog/assignment1/openmp/nbody.c index 69988922..6eb9ed4a 100644 --- a/course/semester2/pprog/assignment1/openmp/nbody.c +++ b/course/semester2/pprog/assignment1/openmp/nbody.c @@ -60,13 +60,14 @@ void Simulation_Run(int argc, char ** argv) Compute(); } + //printf("Left compute loop\n"); } #pragma omp section { if (options.draw_graphics) Graphics_Run(argc, argv); - printf("Got to bit after Graphics_Run()\n"); + //printf("Got to bit after Graphics_Run()\n"); } } diff --git a/course/semester2/pprog/assignment1/single-thread/graphics.c b/course/semester2/pprog/assignment1/single-thread/graphics.c index 1b4fcb31..7a7d2134 100644 --- a/course/semester2/pprog/assignment1/single-thread/graphics.c +++ b/course/semester2/pprog/assignment1/single-thread/graphics.c @@ -110,34 +110,17 @@ void Graphics_Display() //Check whether the program should quit due to steps being computed, or a timeout if (ExitCondition()) { - glutLeaveMainLoop(); + //printf("Leave graphics loop\n"); + glutLeaveMainLoop(); return; } - #ifdef SINGLE_THREADED if (options.verbosity != 0 && universe.steps % options.verbosity == 1) DisplayStatistics(); System_Compute(&universe); #endif - - - //Check whether the runstate has been set to quit the program - switch (runstate) - { - case RUN: - break; - case QUIT: - glutLeaveMainLoop(); - return; - break; - case QUIT_ERROR: - glutLeaveMainLoop(); - return; - break; - } - if (options.draw_graphics == false) return; @@ -170,7 +153,7 @@ void Graphics_Keyboard(unsigned char theKey, int mouseX, int mouseY) { if (theKey == 'x' || theKey == 'X') { - glutLeaveMainLoop(); + QuitProgram(false); return; } diff --git a/course/semester2/pprog/assignment1/single-thread/nbody.c b/course/semester2/pprog/assignment1/single-thread/nbody.c index 67c36d3b..c54661f8 100644 --- a/course/semester2/pprog/assignment1/single-thread/nbody.c +++ b/course/semester2/pprog/assignment1/single-thread/nbody.c @@ -234,6 +234,6 @@ void DisplayStatistics() */ bool ExitCondition(void) { - return ((options.timeout > 0.00 && ((unsigned)(time(NULL) - options.start_time.tv_sec) >= options.timeout)) + return (runstate != RUN || (options.timeout > 0.00 && ((unsigned)(time(NULL) - options.start_time.tv_sec) >= options.timeout)) || (options.num_steps > 0 && universe.steps > options.num_steps)); }