added timing logic, CLI option
git-svn-id: svn://anubis/gvsu@329 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
112dbe3ad3
commit
69c6c86c36
@ -6,6 +6,7 @@
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <mpi.h>
|
||||
#include <sys/time.h> /* struct timeval, gettimeofday() */
|
||||
#include <iostream>
|
||||
#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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user