Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Compiling code and using MPI - lecture
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SCITAS
Courses
Compiling code and using MPI
Compiling code and using MPI - lecture
Commits
76400692
Commit
76400692
authored
3 years ago
by
Emmanuel Lanti
Browse files
Options
Downloads
Patches
Plain Diff
Add WIP for serial part
parent
03cff91e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/serial/serial.tex
+153
-12
153 additions, 12 deletions
src/serial/serial.tex
with
153 additions
and
12 deletions
src/serial/serial.tex
+
153
−
12
View file @
76400692
...
...
@@ -4,7 +4,7 @@
\label
{
sec:compilation
}
\intersec
{
deneb
}
\section
{
Basics of compilation
}
\
sub
section
{
Basics of compilation
}
\label
{
sec:basics
}
\begin{frame}
...
...
@@ -56,43 +56,184 @@
\onslide
<
5
>
\addimage
[
width
=
12
cm
]
{
\FIGREP
/
compilation
_
steps
_
4
.pdf
}{
2
cm
}{
1
cm
}
\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.F
90
}
\item
Display warnings with
\cmd
{
-
Wall
}
option and modify
\cmd
{
saxpy.F
90
}
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.F
90
}
with no options and execute it. What
happens?
\item
Make the code compile with
\cmd
{
-
O
0
-
g
-
Werror
-
Wall
-
Wextra
-
fcheck
=
all
}
and run it. What happens?
\item
Try different compilation optimization options
(
\cmd
{
-
O
0
}
to
\cmd
{
-
O
3
}
)
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
{
-
O
0
}
: 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
{
-
O
3
}
is not necessarily faster than
\cmd
{
-
O
2
}
. Test it
!
\end
{
itemize
}
\end
{
frame
}
\begin
{
frame
}
[
exercise
]
\frametitle
{
Compilation
}
\framesubtitle
{
Exercise compilationWith
2
Files
}
\begin
{
itemize
}
\item
Go to the directory
\cmd
{
compilationWith
2
Files
}
\item
The previous code has been split
ted
into two files:
\cmd
{
main.F
90
}
and
\cmd
{
saxpy.F
90
}
\item
c
ompile and execute the code
\item
The previous code has been split into two files:
\cmd
{
main.F
90
}
and
\cmd
{
saxpy.F
90
}
\item
C
ompile 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 compilationWith
2
Files
}
\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
}
(
f
90
)
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
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment