parallel version with timing working
git-svn-id: svn://anubis/gvsu@207 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
da35425d51
commit
ba20205706
@ -1,4 +1,6 @@
|
||||
|
||||
#include <sys/time.h> /* gettimeofday() */
|
||||
#include <omp.h>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -60,12 +62,25 @@ int main(int argc, char * argv[])
|
||||
delete[] bmp_data;
|
||||
|
||||
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);
|
||||
|
||||
gettimeofday(&after, NULL); /* Stop timing */
|
||||
|
||||
/* Write the output BMP image */
|
||||
BMP outputImage(outputFileName.c_str(),
|
||||
width,
|
||||
height,
|
||||
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[] 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 (*out)[height][width][3] =
|
||||
(unsigned char (*)[height][width][3]) edge_data;
|
||||
#pragma omp parallel for
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user