I have inserted tables and images with the \subsection to make different parts in the report and I wrote it in order but the output is not in order when getting compiled, the subsection does not come after the table I want it to. I have attached the source code below. Any help will be appreciated.
I compared and analysed codes using the MPI library to find out the performance difference between C and Python programs.
\section{Integration}
Finding out the total integration under the curve for a fixed function with limits 0 to 2.
\[ f(x)=\int\limits_0^1 x^2 \]
I have used the Trapezoidal Rule for calculating the same. It is a Numerical technique to find the definite integral of a function.The function is divided into many sub-intervals and each interval is approximated by a Trapezium. Then the area of trapeziums is calculated to find the integral which is basically the area under the curve. The more is the number of trapeziums used, the better is the approximation. \\
Algorithm for calculating the integration under the curve is as follows
\lstset{style=mystyle}
\begin{lstlisting}[language= C, caption= Code snippet from IntegrationMPI.c]
h = (b-a)/n;
local_n = n/size;
local_a = a + my_rank * local_n * h;
local_b = (local_a + local_n) * h;
integral = Trap(local_a, local_b, local_n, h);
if (my_rank == 0){
total = integral;
for (source = 1; source < size; source++){
MPI_Recv(&integral, 1, MPI_FLOAT, source, tag, MPI_COMM_WORLD, &status);
total += integral;
}
}
else {
MPI_Send(&integral, 1, MPI_FLOAT, dest, tag, MPI_COMM_WORLD);
}
\end{lstlisting}
\subsection{For Serial Program in C and Python}
\begin{table}[h!]
\centering
\begin{tabular}{||c|c|c||}
\hline
No. of Trapeziums & Time Taken (s) & Accuracy \\ [0.5ex]
\hline\hline
1000 & 0.001082 & 2.66666867 \\
\hline
2000 & 0.001272 & 2.66666743 \\
\hline
3000 & 0.002326 & 2.66666681 \\
\hline
4000 & 0.003009 & 2.66666675 \\
\hline
5000 & 0.003527 & 2.66666672 \\
\hline
6000 & 0.004466 & 2.66666670 \\
\hline
7000 & 0.004189 & 2.66666669 \\
\hline
8000 & 0.004368 & 2.66666669 \\
\hline
9000 & 0.007463 & 2.66666669 \\
\hline
10000 & 0.007001 & 2.66666669 \\ [1ex]
\hline
\end{tabular}
\caption{Data for Python Code}
\label{table:1}
\end{table}
\begin{table}[h!]
\centering
\begin{tabular}{||c|c|c||}
\hline
No. of Trapeziums & Time Taken (s) & Accuracy \\ [0.5ex]
\hline\hline
1000 & 0.000012 & 2.66662788 \\
\hline
2000 & 0.000030 & 2.66671276 \\
\hline
3000 & 0.000032 & 2.66658711 \\
\hline
4000 & 0.000052 & 2.66660619 \\
\hline
5000 & 0.000058 & 2.66650033 \\
\hline
6000 & 0.000064 & 2.66644287 \\
\hline
7000 & 0.000074 & 2.66667461 \\
\hline
8000 & 0.000084 & 2.66645622 \\
\hline
9000 & 0.000084 & 2.66647649 \\
\hline
10000 & 0.000103 & 2.66674614 \\ [1ex]
\hline
\end{tabular}
\caption{Data for C Code}
\label{table:1}
\end{table}
\begin{figure}[h!]
\centering
\includegraphics[width=1\textwidth]{Images/serial.png}
\caption{Comparison between C and Python serial programs}
\end{figure}
.
\subsection{For MPI Program in C and Python}
\begin{table}[h!]
\centering
\begin{tabular}{||c|c|c||}
\hline
No. of Trapeziums & Time Taken (s) & Accuracy \\ [0.5ex]
\hline\hline
1000 & 0.000549 & 2.66017401 \\
\hline
2000 & 0.000840 & 2.66341850 \\
\hline
3000 & 0.001900 & 2.66450082 \\
\hline
4000 & 0.001127 & 2.66504213 \\
\hline
5000 & 0.002618 & 2.66536696 \\
\hline
6000 & 0.002004 & 2.66558354 \\
\hline
7000 & 0.002583 & 2.66573824 \\
\hline
8000 & 0.002426 & 2.66585428 \\
\hline
9000 & 0.003441 & 2.66594453 \\
\hline
10000 & 0.002971 & 2.66601674 \\ [1ex]
\hline
\end{tabular}
\caption{Data for Python Code}
\label{table:1}
\end{table}
\begin{table}[h!]
\centering
\begin{tabular}{||c|c|c||}
\hline
No. of Trapeziums & Time Taken (s) & Accuracy \\ [0.5ex]
\hline\hline
1000 & 0.000037 & 2.66016173 \\
\hline
2000 & 0.000048 & 2.66345334 \\
\hline
3000 & 0.000072 & 2.66444683 \\
\hline
4000 & 0.000076 & 2.66499472 \\
\hline
5000 & 0.000087 & 2.66526604 \\
\hline
6000 & 0.000070 & 2.66551304 \\
\hline
7000 & 0.000099 & 2.66580105 \\
\hline
8000 & 0.000108 & 2.66578150 \\
\hline
9000 & 0.000111 & 2.66587353 \\
\hline
10000 & 0.000142 & 2.66612148 \\ [1ex]
\hline
\end{tabular}
\caption{Data for C Code}
\label{table:1}
\end{table}
\begin{figure}[h!]
\centering
\includegraphics[width=1\textwidth]{Images/mpi.png}
\caption{Comparison between C and Python MPI programs}
\end{figure}