Skip to content

Commit 197dfcf

Browse files
authored
Merge pull request #2 from learning-process/intro
2 parents 6992de3 + e2d2f7c commit 197dfcf

File tree

1 file changed

+79
-3
lines changed

1 file changed

+79
-3
lines changed

01-intro.tex

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@
77
\usepackage{graphicx} % For including images
88
\usepackage{amsmath} % For math symbols and formulas
99
\usepackage{hyperref} % For hyperlinks
10+
\usepackage{listings}
11+
\usepackage{xcolor}
12+
\usepackage[T1]{fontenc}
13+
14+
\lstdefinestyle{CStyle}{
15+
language=C, % Set the language to C
16+
basicstyle=\ttfamily\footnotesize\linespread{0.9}\tiny, % Set font style and size
17+
keywordstyle=\color{blue}, % Color of keywords
18+
commentstyle=\color{gray}, % Color of comments
19+
stringstyle=\color{red}, % Color of strings
20+
showstringspaces=false, % Do not mark spaces in strings
21+
breaklines=true, % Enable line breaks at appropriate places
22+
breakatwhitespace=false, % Break lines at any character, not just whitespace
23+
numbers=left, % Show line numbers on the left
24+
numberstyle=\tiny\color{gray}, % Style for line numbers
25+
tabsize=4, % Set tab width
26+
keepspaces=true, % Keep indentation spaces
27+
frame=single, % Add a border around the code
28+
aboveskip=0pt, % Reduce space above the code block
29+
belowskip=0pt, % Reduce space below the code block
30+
xleftmargin=7.5pt, % Add left padding (approx. 2.8mm or 10px)
31+
xrightmargin=15pt, % Add left padding (approx. 2.8mm or 10px)
32+
}
1033

1134
% Title, author, date, and institute (optional)
1235
\title[Parallel Programming. Introduction]{Parallel Programming course. Introduction}
@@ -44,12 +67,65 @@
4467
\end{frame}
4568

4669
% Section
47-
\section{Introduction}
70+
\section{Introduction to MPI}
71+
72+
% "Hello, World" in MPI
73+
\begin{frame}[fragile]{"Hello, World" in MPI}
74+
75+
\lstset{style=CStyle, caption=Basic application written using MPI}
76+
\begin{lstlisting}
77+
#include <mpi.h>
78+
79+
#include <iostream>
80+
81+
int main(int argc, char** argv) {
82+
MPI_Init(&argc, &argv);
83+
84+
int world_size;
85+
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
86+
87+
int world_rank;
88+
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
89+
90+
char processor_name[MPI_MAX_PROCESSOR_NAME];
91+
int len_chars;
92+
MPI_Get_processor_name(processor_name, &len_chars);
93+
94+
MPI_Barrier(MPI_COMM_WORLD);
95+
std::cout << "Processor = " << processor_name << std::endl;
96+
std::cout << "Rank = " << world_rank << std::endl;
97+
std::cout << "Number of processors = " << world_size << std::endl;
98+
99+
MPI_Finalize();
100+
return 0;
101+
}
102+
\end{lstlisting}
48103

49-
% Slide 1
50-
\begin{frame}{Slide}
51104
\end{frame}
52105

106+
\begin{frame}[fragile]{Performance measurement in MPI: \texttt{MPI\_Wtime()}}
107+
\texttt{double MPI\_Wtime(void)}
108+
109+
\begin{itemize}
110+
\item \texttt{MPI\_Wtime()} is a function provided by the MPI standard to measure the wall-clock time (in seconds) since some arbitrary point in the past.
111+
\item This function is often used for performance analysis in parallel programs to measure the execution time of sections of code.
112+
\item It returns a double precision floating-point number representing the current time. The returned time is in seconds.
113+
\item \texttt{MPI\_Wtime()} is local to the process and does not guarantee synchronization between processes, meaning each process may have a different starting time reference.
114+
\end{itemize}
115+
116+
Usage example:
117+
\lstset{style=CStyle}
118+
\begin{lstlisting}
119+
double start = MPI_Wtime();
120+
// Code to time
121+
double end = MPI_Wtime();
122+
double elapsed = end - start;
123+
\end{lstlisting}
124+
125+
Documentation reference: \texttt{\href{https://www.mpich.org/static/docs/v3.2/www3/MPI_Wtime.html}{https://www.mpich.org/static/docs/v3.2/www3/MPI\_Wtime.html}}
126+
\end{frame}
127+
128+
53129
% Thank You Slide
54130
\begin{frame}
55131
\centering

0 commit comments

Comments
 (0)