diff --git a/cs677/hw5/hw.tex b/cs677/hw5/hw.tex index 8a7ad08..0e434c0 100644 --- a/cs677/hw5/hw.tex +++ b/cs677/hw5/hw.tex @@ -48,6 +48,21 @@ $$ S_G = p + (1 - p) T_s = 8 + (1 - 8) \frac{1}{24} = 7.708 $$ } +\item[5.]{ + Output from instrumented Floyd program: \\ +\texttt{ +\$ ./floyd-sequential adjacency.dat \\ +Serial execution time: 0.0248399 seconds \\ +Parallel execution time: 2.01773 seconds + } + + This means that the percent of sequential code is roughly 1.23\% + (for a problem size of $n = 400$). + Using Amdahl's law, the maximum speedup that can be achieved with + this program (for this problem size) is given by + $$ S_{\textrm{max}} = \frac{1}{1.23\%} = 81.25 $$ +} + \end{enumerate} \end{document} diff --git a/cs677/hw5/src/floyd-sequential.cc b/cs677/hw5/src/floyd-sequential.cc index 4bc862f..df8b877 100644 --- a/cs677/hw5/src/floyd-sequential.cc +++ b/cs677/hw5/src/floyd-sequential.cc @@ -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 @@ -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; }