finished hw5
git-svn-id: svn://anubis/gvsu@228 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
446b8464b3
commit
ec5eb17457
@ -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}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user