Commit 81767780 authored by drnull03's avatar drnull03

Added comparision table

parent e202d13d
No preview for this file type
......@@ -46,13 +46,18 @@ int main(int argc, char** argv) {
MPI_Scatterv(X, counts, displs, MPI_INT, local_X, local_size, MPI_INT, 0, MPI_COMM_WORLD);
// Print received elements
printf("Process %d received: ", world_rank);
for (int i = 0; i < local_size; i++)
printf("%d ", local_X[i]);
printf("\n");
// Compute local average
// barrier is used to make sure all processes start timing at the same moment
MPI_Barrier(MPI_COMM_WORLD);
double start_time = MPI_Wtime();
// compute local average
double local_sum = 0;
for (int i = 0; i < local_size; i++)
local_sum += local_X[i];
......@@ -67,9 +72,17 @@ int main(int argc, char** argv) {
double global_sum = 0;
MPI_Reduce(&local_sum, &global_sum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
// barrier ensures all processes finish computation before stopping timer
MPI_Barrier(MPI_COMM_WORLD);
double end_time = MPI_Wtime();
// ----------------------------------------------------------
if (world_rank == 0) {
double global_avg = global_sum / N;
printf("Global average = %f\n", global_avg);
printf("Execution time with %d processes = %f seconds\n",
world_size, end_time - start_time);
}
free(local_X);
......
Notice how increasing the number of processes make the program slower and that is because
Tcomm time is big compared to the array size.
to take advantage of this we should make the array bigger then we can notice the difference and speed up
we also notice we make more processes then the number of cores in the system the program gets way slower.
\documentclass{article}
\begin{document}
\begin{table}[h]
\centering
\caption{Execution Time with Different Numbers of Processes}
\begin{tabular}{|c|c|}
\hline
\textbf{Number of Processes} & \textbf{Execution Time (s)} \\
\hline
1 & 0.000014 \\
\hline
2 & 0.000052 \\
\hline
4 & 0.000062 \\
\hline
8 & 0.000184 \\
\hline
10 & 0.000651 \\
\hline
\end{tabular}
\label{tab:time}
\end{table}
\end{document}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment