From 69c6c86c36b1ae2c0b53e6a75c308f8a8d1b26f7 Mon Sep 17 00:00:00 2001 From: josh Date: Sun, 7 Dec 2008 23:41:57 +0000 Subject: [PATCH] added timing logic, CLI option git-svn-id: svn://anubis/gvsu@329 45c1a28c-8058-47b2-ae61-ca45b979098e --- cs677/final/mpi-fractals.cc | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/cs677/final/mpi-fractals.cc b/cs677/final/mpi-fractals.cc index a8f1110..84b9c5f 100644 --- a/cs677/final/mpi-fractals.cc +++ b/cs677/final/mpi-fractals.cc @@ -6,6 +6,7 @@ #include #include +#include /* struct timeval, gettimeofday() */ #include #include "Computation.h" #include "NewtonComputation.h" @@ -38,6 +39,7 @@ int main(int argc, char * argv[]) int nprocs = 0; Computation * computation = NULL; int fractal_type = 0; + bool display_times = false; SDL_Surface * screen; Uint32 * pixels; @@ -57,6 +59,10 @@ int main(int argc, char * argv[]) { fractal_type = atoi(strlen(argv[i]) > 2 ? argv[i] + 2 : argv[++i]); } + else if (!strcmp(argv[i], "-times")) + { + display_times = true; + } } getSizes(&my_rank, &world_size, &nprocs); @@ -94,13 +100,23 @@ int main(int argc, char * argv[]) { if (redraw) { + struct timeval before, after; window_vals[0] = 0.0; window_vals[1] = x_center; window_vals[2] = y_center; window_vals[3] = zoom; sendWindowVals(&window_vals[0], world_size); + gettimeofday(&before, NULL); draw(my_rank, world_size, nprocs, width, height, pixels, taskVals, computation); + gettimeofday(&after, NULL); + if (display_times) + { + double time_before = before.tv_sec + before.tv_usec / 1000000.0; + double time_after = after.tv_sec + after.tv_usec / 1000000.0; + double diff = time_after - time_before; + cout << "Elapsed time: " << diff << " seconds." << endl; + } redraw = false; } SDL_UpdateRect(screen, 0, 0, 0, 0); @@ -148,7 +164,7 @@ int main(int argc, char * argv[]) for (;;) { // DEBUG: - cout << "MPI node " << my_rank << " waiting for command." << endl; +// cout << "MPI node " << my_rank << " waiting for command." << endl; /* wait for a redraw or quit command */ MPI_Recv(&window_vals[0], 4, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, NULL); @@ -158,8 +174,8 @@ int main(int argc, char * argv[]) y_center = window_vals[2]; zoom = window_vals[3]; // DEBUG: - cout << "MPI node " << my_rank << " received (" - << x_center << ", " << y_center << "), zoom " << zoom << endl; +// cout << "MPI node " << my_rank << " received (" +// << x_center << ", " << y_center << "), zoom " << zoom << endl; draw(my_rank, world_size, nprocs, width, height, NULL, taskVals, computation); } @@ -232,7 +248,7 @@ void draw(int rank, int world_size, int nprocs, int width, int height, Uint32 * pixels, Uint32 * taskVals, Computation * computation) { // DEBUG: - cout << "In draw() with rank " << rank << endl; +// cout << "In draw() with rank " << rank << endl; MPI_Status mpi_status; if (world_size == 1) { @@ -292,6 +308,7 @@ void draw(int rank, int world_size, int nprocs, int width, int height, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, NULL); if (pixel_num < 0) /* exit if we are done */ break; +#pragma omp parallel for for (int i = 0; i < TASK_SIZE; i++) { int this_pixel_num = pixel_num + i; @@ -311,7 +328,7 @@ void draw(int rank, int world_size, int nprocs, int width, int height, void sendWindowVals(double * winVals, int world_size) { // DEBUG: - cout << "Master sending out new window values" << endl; +// cout << "Master sending out new window values" << endl; for (int to_proc = 1; to_proc < world_size; to_proc++) { MPI_Send(winVals, 4, MPI_DOUBLE, to_proc,