parallel version with timing working

git-svn-id: svn://anubis/gvsu@207 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-10-25 21:41:26 +00:00
parent da35425d51
commit ba20205706

View File

@ -1,4 +1,6 @@
#include <sys/time.h> /* gettimeofday() */
#include <omp.h>
#include <iostream> #include <iostream>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -60,12 +62,25 @@ int main(int argc, char * argv[])
delete[] bmp_data; delete[] bmp_data;
unsigned char * edge_data = new unsigned char[width * height * 3]; unsigned char * edge_data = new unsigned char[width * height * 3];
struct timeval before, after;
gettimeofday(&before, NULL); /* Start timing */
applyEdgeDetection(padded_data, edge_data, width, height, threshold_level); applyEdgeDetection(padded_data, edge_data, width, height, threshold_level);
gettimeofday(&after, NULL); /* Stop timing */
/* Write the output BMP image */
BMP outputImage(outputFileName.c_str(), BMP outputImage(outputFileName.c_str(),
width, width,
height, height,
edge_data); edge_data);
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;
delete[] padded_data; delete[] padded_data;
delete[] edge_data; delete[] edge_data;
} }
@ -96,6 +111,7 @@ void applyEdgeDetection(unsigned char * padded_data, unsigned char * edge_data,
(unsigned char (*)[height+2][width+2]) padded_data; (unsigned char (*)[height+2][width+2]) padded_data;
unsigned char (*out)[height][width][3] = unsigned char (*out)[height][width][3] =
(unsigned char (*)[height][width][3]) edge_data; (unsigned char (*)[height][width][3]) edge_data;
#pragma omp parallel for
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)