Skip to content
Snippets Groups Projects
Commit 76400692 authored by Emmanuel Lanti's avatar Emmanuel Lanti
Browse files

Add WIP for serial part

parent 03cff91e
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@
\label{sec:compilation}
\intersec{deneb}
\section{Basics of compilation}
\subsection{Basics of compilation}
\label{sec:basics}
\begin{frame}
......@@ -56,43 +56,184 @@
\onslide<5>\addimage[width=12cm]{\FIGREP/compilation_steps_4.pdf}{2cm}{1cm}
\end{frame}
\begin{frame}
\frametitle{Compilation}
\framesubtitle{Let's start from the beginning}
\begin{itemize}
\item There are many compilers for different languages (here C, C++, and
Fortran)
\begin{itemize}
\item GNU (\cmd{gcc}, \cmd{g++}, \cmd{gfortran})
\item Clang/LLVM
\item Intel (\cmd{icc}, \cmd{icpc}, \cmd{ifort}) and Intel OneAPI (\cmd{icx}, \cmd{icpx}, \cmd{ifx})
\item IBM (\cmd{xlc}, \cmd{xlc++}, \cmd{xlf})
\item etc
\end{itemize}
\item Each vendor has specific options and usage
\end{itemize}
\vfill
\textbf{In the following, we will use GNU compilers, but everything can be
adapted to other vendors}
\end{frame}
\begin{frame}[fragile]
\frametitle{Compiling a single source file}
\framesubtitle{}
\begin{itemize}
\item In general, the command to compile a single source file is
\begin{bashcode}
<compiler> <compiling options> <source file>
\end{bashcode}
\item For example
\begin{bashcode}
gcc -o my_exe code.c
\end{bashcode}
I want to compile the file \cmd{code.c} using the GNU C compiler and with
option \cmd{-o my_exe} (rename the executable to \cmd{my_exe} instead
of the default \cmd{a.out})
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Compilation}
\framesubtitle{Compilation options}
Many compilation options can be used to manipulate, optimize or debug such as:
\begin{itemize}
\begin{itemize}
\item "Manipulation": \cmd{-o}, \cmd{-c}, etc.
\item "Optimization": \cmd{-On}, \cmd{-fastmath}, etc.
\item "Debug": \cmd{-g}, \cmd{-V} \cmd{-traceback} (gcc), etc.
\item Option summary for GNU: \url{https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html\#Option-Summary}
\item "Debug": \cmd{-g}, \cmd{-Wall}, \cmd{-fcheck=all} etc.
\item Option summary for GNU: \url{https://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html\#Invoking-GCC}
\end{itemize}
\end{frame}
\begin{frame}[exercise]
\frametitle{Compilation}
\framesubtitle{Exercise simpleCompilation}
The following code performs a simple saxpy, \ie{} $\vec{z} = \alpha \vec{x} + \vec{y}$
\begin{itemize}
\item Load gcc module with \cmd{module load gcc}
\item Go to the directory \cmd{simpleCompilation}
\item Compile the code \cmd{saxpy.F90}
\item Display warnings with \cmd{-Wall} option and modify \cmd{saxpy.F90} in order to suppress these warnings
\item Execute the code
\item Use \cmd{-D} option in the compilation to define the macro \cmd{MY_MACRO} and check the results during the execution
\item Try different compilation options for optimization, and compare the timing displayed from the corresponding runs
\item Compile the code \cmd{saxpy.F90} with no options and execute it. What
happens?
\item Make the code compile with \cmd{-O0 -g -Werror -Wall -Wextra
-fcheck=all} and run it. What happens?
\item Try different compilation optimization options (\cmd{-O0} to
\cmd{-O3}) and compare the timing displayed from the corresponding
runs
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Discussion}
\framesubtitle{Exercise simpleCompilation}
\begin{itemize}
\item Compilers greatly help you to debug and optimize your code. Use them
properly!
\item We advise you to begin by disabling optimizations and activating warnings
\begin{itemize}
\item \cmd{-O0}: turn off most optimizations (default with GCC)
\item \cmd{-Wall -Wextra}: activate most of the warnings
\item \cmd{-Werror}: treat warnings as errors
\item \cmd{-fcheck=all}: enable all run-time checks
\end{itemize}
\item Some errors can be easily avoided using the proper flags!
\item Once Everything is correct, remove those options and try optimization
flags
\item \cmd{-O3} is not necessarily faster than \cmd{-O2}. Test it!
\end{itemize}
\end{frame}
\begin{frame}[exercise]
\frametitle{Compilation}
\framesubtitle{Exercise compilationWith2Files}
\begin{itemize}
\item Go to the directory \cmd{compilationWith2Files}
\item The previous code has been splitted into two files: \cmd{main.F90} and \cmd{saxpy.F90}
\item compile and execute the code
\item The previous code has been split into two files: \cmd{main.F90} and \cmd{saxpy.F90}
\item Compile and execute the code. Hint, use the \cmd{-c} option.
\item Check the results compared to the \cmd{simpleCompilation} exercise
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Discussion}
\framesubtitle{Exercise compilationWith2Files}
\begin{itemize}
\item With multiple source files, one must compile them separately and link
them together at the end
\item The \cmd{-c} option compiles, but does not link
\item Remember to pass all the options to each file!
\item This quickly becomes cumbersome as the number of files increases. We
will see possible solutions later.
\end{itemize}
\end{frame}
\begin{frame}[t, fragile]
\frametitle{Libraries}
\framesubtitle{}
\begin{itemize}
\item Libraries are a collection of pre-compiled pieces of code that can be
reused in other programs
\item One almost always uses libraries in our programs, \eg{}
\cmd{iostream}, \cmd{vector} in C++, \cmd{stdio} in C
\pause
\item In general, a library consists of a header file, \cmd{cmath.h}, and a
binary object, \cmd{libm.so}
\item At compile time (pre-processing) you provide the headers
\item At linking time you provide the object files
\end{itemize}
\end{frame}
% \begin{frame}[t, fragile]
% \frametitle{Libraries}
% \framesubtitle{}
% \begin{itemize}
% \item Libraries are a collection of pre-compiled pieces of code that can be
% reused in other programs
% \item One almost always uses libraries in our programs, \eg{}
% \cmd{iostream}, \cmd{vector} in C++, \cmd{stdio} in C
% \end{itemize}
% %\onslide<2->\cxxfile[title={libraryExample/calc.c}]{examples/libraryExample/calc.c}
% \onslide<3->\begin{bashcode}
% $> gcc calc.c -o calc
% /usr/bin/ld: /tmp/ccYgTli3.o: in function `square_root':
% calc.c:4: undefined reference to `sqrt'
% collect2: error: ld returned 1 exit status
% \end{bashcode}%$
% \end{frame}
\begin{frame}[fragile]
\frametitle{Libraries}
\framesubtitle{Include header files}
\begin{itemize}
\item When you have an \cmd{#include} or \cmd{use} (f90) in your code, the
compiler must know where to look for them
\item It has some default paths it will always look in, \eg{} system paths
and current path, but you can supply your own with the \cmd{-I} option
\end{itemize}
\textbf{Example}:
\begin{itemize}
\item Let's assume the \cmd{mylibrary.h} header is located in
\cmd{~/mycode/includes/mylibrary.h}
\item The source code that uses it is located in
\cmd{~/mycode/src/source.cpp}
\item Here you have two options:
\begin{enumerate}
\item You put the library path in the source file, \ie{} \cmd{#include
"../includes/mylibrary.h"}
\item You simply use \cmd{#include "mylibrary.h"} and tell the compiler (pre-processor)
where to look for it
\begin{bashcode}
gcc -I~/mycode/includes source.cpp
\end{bashcode}
\end{enumerate}
\end{itemize}
\end{frame}
\begin{frame}[t,fragile]
\frametitle{Compilation}
\framesubtitle{Link to libraries}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment