finished hw5
git-svn-id: svn://anubis/gvsu@228 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
1 parent
446b8464b3
commit
ec5eb17457
2 files changed
+30
-8
No files matched your search
@@ -1,8 +1,9 @@
|
||||
|
||||
/* Josh Holtrop
|
||||
* 2008-10-15
|
||||
* 2008-11-05
|
||||
* CS 677
|
||||
* Grand Valley State University
|
||||
* Instrumented to get serial vs. parallel run times
|
||||
*/
|
||||
|
||||
#include <omp.h>
|
||||
@@ -28,6 +29,10 @@ void usage(char * progname)
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
struct timeval start_time, switch_time, end_time;
|
||||
|
||||
gettimeofday(&start_time, NULL); /* Start timing */
|
||||
|
||||
if (argc < 1)
|
||||
usage(argv[0]);
|
||||
|
||||
@@ -37,8 +42,7 @@ int main(int argc, char * argv[])
|
||||
int D[2][num_verts][num_verts];
|
||||
convertToMatrix(v, num_verts, (int *) &D[0]);
|
||||
|
||||
struct timeval before, after;
|
||||
gettimeofday(&before, NULL); /* Start timing */
|
||||
gettimeofday(&switch_time, NULL); /* Start timing */
|
||||
|
||||
/* Run Floyd's Algorithm on D */
|
||||
for (int k = 1; k <= num_verts; k++)
|
||||
@@ -62,7 +66,7 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
}
|
||||
|
||||
gettimeofday(&after, NULL); /* Stop timing */
|
||||
gettimeofday(&end_time, NULL); /* Stop timing */
|
||||
|
||||
#ifdef PRINT_RESULT
|
||||
cout << "Result:" << endl;
|
||||
@@ -80,10 +84,13 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
#endif
|
||||
|
||||
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;
|
||||
double time_start = start_time.tv_sec + start_time.tv_usec / 1000000.0;
|
||||
double time_switch = switch_time.tv_sec + switch_time.tv_usec / 1000000.0;
|
||||
double time_end = end_time.tv_sec + end_time.tv_usec / 1000000.0;
|
||||
double serial = time_switch - time_start;
|
||||
double parallel = time_end - time_switch;
|
||||
cout << "Serial execution time: " << serial << " seconds" << endl;
|
||||
cout << "Parallel execution time: " << parallel << " seconds" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user