Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge #10

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0cddf5a
Update README.md
lformaggia Aug 14, 2023
6bb57fa
Merge branch 'pacs-course:master' into AMSC
lformaggia Aug 15, 2023
065bfa9
Merge branch 'master' of github.com:pacs-course/pacs-examples into AMSC
lformaggia Aug 15, 2023
880aa8e
Merge branch 'pacs-course:master' into AMSC
lformaggia Sep 11, 2023
463c0bc
updated README.md
lformaggia Aug 18, 2023
19b85c5
changed README
lformaggia Aug 18, 2023
39250f8
minor fix
lformaggia Sep 11, 2023
a64615c
changed repo address
lformaggia Sep 11, 2023
475b8d4
corrected Makefile.user for AMSC, and bettered a code
lformaggia Sep 12, 2023
eb6d21c
few fixes
lformaggia Sep 13, 2023
b0faba7
Update explanation.tex
FrancescoPesce Sep 14, 2023
aeb747e
fixed CONTENT.md
lformaggia Sep 19, 2023
9158523
Bettered a readme file
lformaggia Sep 21, 2023
c611142
few fixes
lformaggia Sep 29, 2023
b8606ce
minor modifications
lformaggia Nov 8, 2023
e6934d2
corrected a bug
lformaggia Nov 23, 2023
cd3f0fb
corrected another bug
lformaggia Nov 23, 2023
947e2f7
corrected yet another bug
lformaggia Nov 23, 2023
54cb731
Merge pull request #1 from FrancescoPesce/patch-1
lformaggia Aug 13, 2024
c1a9072
updated modules
lformaggia Aug 13, 2024
3438525
Merge github.com:pacs-course/pacs-examples into pacs-course-AMSC
lformaggia Aug 14, 2024
e2b7ca9
Updated modules
lformaggia Aug 14, 2024
25d96c0
Merge branch 'pacs-course-AMSC' into AMSC
lformaggia Aug 14, 2024
140b56c
updated modules
lformaggia Aug 17, 2024
95f6b34
Added utilities for tuples
lformaggia Aug 20, 2024
3e36c59
updated submodule
lformaggia Aug 20, 2024
e48ebc2
bettered a few things
lformaggia Aug 20, 2024
85fd713
updated modules
lformaggia Aug 20, 2024
bab255f
updated modules
lformaggia Aug 20, 2024
7ec6344
Merge remote-tracking branch 'upstream/AMSC' into AMSC
lformaggia Aug 20, 2024
fe7455b
updated a module
lformaggia Aug 20, 2024
348622c
bettered example findiff
lformaggia Sep 16, 2024
65011d7
bettered again
lformaggia Sep 16, 2024
e7498d0
Merge pull request #3 from pacs-course/AMSC
lformaggia Sep 20, 2024
f08487f
Merge pull request #4 from HPC-Courses/Merge
lformaggia Sep 20, 2024
8c08016
Merge branch 'pacs-course:master' into merge
lformaggia Sep 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions Examples/.settings/language.settings.xml

This file was deleted.

2 changes: 1 addition & 1 deletion Examples/CONTENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ In the following, the name of the example is the name of the directory where the

## Utilities ##
- `Utilities` A set of utilities that you may use also in your code. All described in the local `README.md` file.
**You should go in the directory and type**
**You should go in the `Utilities` directory and type**

```
make
Expand Down
14 changes: 8 additions & 6 deletions Examples/Makefile.user
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# This file must be renamed into Makefile.inc in order to work!!
#

# ***** This is the user defined part of the Makefile
# ***** This is the user defined part of the Makefile ****
#
# It is included in almost all Makefiles of the example (a part some particulare cases)
#
# It has been modified so to read some data from environmental variables
# and be compatible with the system of modules used at MOX
# It has been modified so to read some data from environmental variables (if set!)
# and be compatible with the system of modules used at MOX Laboratory
#
# YOU CAN change it to suit your need!!!!
#
Expand All @@ -21,12 +21,14 @@
#

# The directory where the examples reside (you HAVE to change this)
PACS_ROOT?=/home/forma/PacsVirtualMachine/pacs/PACSCourse/Material/Examples
export AMSC_ROOT?=/home/forma/Work/Didattica/HPC_Courses/AMSC-CodeExamples/Examples
# For compatibility with the PACS course. Do not change it
export PACS_ROOT=${AMSC_ROOT}
# The directory with the Eigen (leave blank if they are in a standard directory)
mkEigenInc?=/usr/local/include/eigen3/
EIGEN_DIR=$(mkEigenInc)
#
# Mpi directories for library and include files
# Mpi directories for library and include files (change if needed)
#
mkOpenmpiLib?=/usr/lib/x86_64-linux-gnu
mkOpenmpiInc?=/usr/include
Expand Down Expand Up @@ -63,7 +65,7 @@ CXX = ${mkCxxCompiler}
mkCCompiler?=gcc
CC = ${mkCxxCompiler}

# Since we are only uning c++ I set the linker LINK.o for object files
# Since we are only using c++ I set the linker LINK.o for object files
# so that it uses the c++ compiler. Make has no separate macro for the linker!
LINK.o = $(CXX) $(LDFLAGS) $(TARGET_ARCH)
#
Expand Down
30 changes: 17 additions & 13 deletions Examples/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Examples of the Course on Advanced Programming for Scientific Computing (aka PACS)#
**Mathematical Engineering, Politecnico di Milano**
**Copyright Luca Formaggia 2012-2024**
# Course on Advanced programming for scientific computing #
## Mathematical Engineering, Politecnico di Milano ##
# Course on Advanced Modelling for scientific computing #
## HPC and Big Data, Politecnico di Milano ##
## Copyright Luca Formaggia 2012-2023 ##

## LICENCING ##
The software contained in the subfolders of this directory is free-software released under a GNU General Public Licens (GPL). The details of the licence are availabe in the `COPYRIGHT` file in the root directory.
Expand Down Expand Up @@ -38,7 +40,7 @@ The first operation is to copy the file `Makefile.user` to `Makefile.inc`:

$ cp Makefile.user Makefile.inc

and edit the latter to suit your system. In particular, you have to set `PACS_ROOT` to the root directory (with the full path, i.e. the path should start with `/`).
and edit the latter to suit your system. In particular, you have to set `AMSC_ROOT` to the root directory (with the full path, i.e. the path should start with `/`).
If you do not know it
just type

Expand All @@ -53,18 +55,19 @@ compilation options. But normally you don't need it.

As an example:

PACS_ROOT=/home/myname/pacs/Examples/
AMSC_ROOT=/home/myname/pacs/Examples/

Alternatively, to editing the file, you may set an environmental
variable with the same name using the command

export PACS_ROOT=/home/myname/pacs/Examples/
export AMSC_ROOT=/home/myname/pacs/Examples/

in the `.profile` or in the `.bashrc` file in your home directory (see Note
at the end of the file). The file `Makefile.inc` is included in all the Makefiles and defines and
exports the following make macros:

- `PACS_ROOT` the directory where the Examples resides
- `AMSC_ROOT` the directory where the Examples resides
- `PACS_ROOT` for compatibility with the APSC course
- `CXX` the c++ compiler of choice
- `STANDARD` contains the C++ standard used in compilation
- `MPI_LIBDIR` and `MPI_INCDIR` where to find mpi libraries and header files, respectively
Expand Down Expand Up @@ -155,8 +158,9 @@ env | grep mk

* You do not use the module system. Then you have again two choices
* You set the various macro in your `Makefile.inc` (and possibly the other Makefiles, if needed) by yourself
* You simulate the module environment by creating the environmental variables: you have to put in the `.profile `file in your home directory the corresponding instructions
for the bash (the `~/.profile` file is read by the bash shell every time you do a login). For example, in my `.profile` I have:
* You simulate the module environment by creating the environmental variables: you have to put in the `.bash-profile` (or `.profile `)
file in your home directory the corresponding instructions
for the bash (the `.bash-profile` and `~/.profile` files are sourced by the bash shell every time you do a login). For example, in my `.profile` I have:

-------------------------------------------------------------------------------

Expand Down Expand Up @@ -258,13 +262,13 @@ content is run as if typed on a terminal). Everytime you open a bash
shell the `.bashrc` file is sourced.

What's the difference? Well today people prefer to put everything in
the `.bashrc` file, but in principle envronmental variables
definitions should be put in the `.profile` (or `.bash_profile`),
the `.bashrc` file, but in principle definitions of environmental variables
should be put in the `.bash_profile` (or `.profile`),
while `.bashrc` should be reserved for command alias or customization
that need to change wether you are in a interactive shell (terminal)
that need to change depending whether you are in a interactive shell (i.e. a terminal)
or not (batch job).

A practical difference is that if you change `.profile` (or `.bash_profile`)
A practical difference is that if you change `.bash_profile` (or `.profile`)
the changes become operative only after a new login.
Changes in `.bashrc` becomes active just by opening a new terminal.

Expand Down
13 changes: 11 additions & 2 deletions Examples/src/Bindings/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// parameters are not used
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"

#include <iostream>
#include <typeinfo>
Expand Down Expand Up @@ -52,6 +53,8 @@ foo(int &a)
void
foo(const int &a)
{
auto av=5*a; // ok i can read a
// a=10.// Error! I cannot change a
std::cout << "using void foo(const int&)" << std::endl;
}

Expand All @@ -76,6 +79,7 @@ void
goo(std::vector<int> &&a)
{
std::vector<int> b=std::move(a);
// now a is empty
std::cout << "using void goo(vector<int> &&)" << std::endl;
}

Expand All @@ -87,6 +91,8 @@ goo(std::vector<int> &&a)
void
goo(const std::vector<int> &a)
{
auto av=a[0]; // ok i can read a
// a[0]=10.// Error! I cannot change a
std::cout << "using void goo(const vector<int>&)" << std::endl;
}

Expand All @@ -97,7 +103,10 @@ goo(const std::vector<int> &a)
*/
void
goo(const std::vector<int> &&a)
{
{
auto av=a[0];
// ok i can read a
// a[0]=10.// Error! I cannot change a
std::cout << "using void goo(const vector<int> &&)" << std::endl;
}

Expand Down Expand Up @@ -127,7 +136,7 @@ gvect(T &&x)
T v = std::forward<T>(x);
std::cout << "using void gvect<T>(T&&) with std::forward\n"
<< " created vector size is " << v.size()
<< ". Input vector size is now " << x.size() << std::endl;
<< " Input vector size is now " << x.size() << std::endl;
}

int
Expand Down
6 changes: 3 additions & 3 deletions Examples/src/FloatingPoint/FPExceptions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ When you perform an invalid floating point operation (like the square root
of a negative number) or you have overflows/underflows, the execution
does not stop. Yet in many architectures a flag is raised to indicate
that a **floating point exception** has occurred. You may test if the
flag is raised, and take the appropriate action, if you wish. But it require some work.
flag is raised, and take the appropriate action, if you wish. But it requires some work.

This directory contains two utilities

* `trapfpe.hpp`, a header only utility that you should include in your main source file if you want to be able to activate *abort on major fp exceptions*. To activate this feature, you have to compile your code with the cpp option `-DFPE_ABORT`. If not, you have the default behaviour in case of floating point exceptions. With major floating point exceptions here I mean: invalid operation, divide by zero, overflow.

* `fpeUtilities.[hc]pp` the sources of a little library that introduces some exception classes inherited from std::runtime_error and a function that tests if major fp exception has been raised, and in that case launches the relevant exception, or returns a boolean equal to true. To use this utility you need to link with the libfpe library created in this example.
* `fpeUtilities.[hc]pp` the sources of a little library that introduces some exception classes inherited from std::runtime_error and a function that tests if major fp exception has been raised, and in that case launches the relevant exception, or returns a boolean equal to true. To use this utility you need to link the `libfpe.so` library created by this example.

A test is available, `main_fpe.cpp`, to test the utilities.

Expand All @@ -35,7 +35,7 @@ Remember that you have to make
```
make install
```
to install in the correct directory all headers and library
to install in the correct directory all headers and the library
`libfpe.[a|so]` containing the compiled fpe Utility for use in other
examples.

Expand Down
2 changes: 1 addition & 1 deletion Examples/src/FloatingPoint/FPFailure/explanation.tex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ \section{Wrongly converging sequence}.
\]
It can be easily found, by looking at the roots of the polynomial
\[
x^3-111+1130x^2-3000,
x^3-111x^2+1130x-3000,
\]
that, if the sequence converges, it converges necessarily to either
$5$, $6$, or $100$.
Expand Down
17 changes: 11 additions & 6 deletions Examples/src/FloatingPoint/FinDiff/gnuplot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ set style line 2 lc 2 ps 2
set style line 4 lc 3 ps 1
set format y "%3.1e"
set format x "%3.1e"
plot "single.dat" using 1:3 title "Error float 2" ls 1 with line, "single.dat" using 1:4 title "Roundoff error" ls 2 with points, "single.dat" using 1:5 title "Error float 4" ls 3 with points, "single.dat" using 1:6 title "Error float wd" ls 4 with points
pause mouse
plot "double.dat" using 1:3 title "Error double 2" ls 1 with line, "double.dat" using 1:4 title "Roundoff error" ls 2 with points, "double.dat" using 1:5 title "Error double 4" ls 3 with points, "double.dat" using 1:6 title "Error double wd" ls 4 with points
pause mouse
plot "extended.dat" using 1:3 title "Error extended 2" ls 1 with line, "extended.dat" using 1:4 title "Roundoff error" ls 2 with points, "extended.dat" using 1:5 title "Error extended 4" ls 3 with points, "extended.dat" using 1:6 title "Error ext. wd" ls 4 with points
pause mouse
#plot into three separate windows using gnuplot
set terminal x11 0
set title "Single Precision Errors"
plot "single.csv" using 1:3 title "Error 2nd order" ls 1 with line, "single.csv" using 1:4 title "Roundoff error" ls 2 with points, "single.csv" using 1:5 title "Error 4th order" ls 3 with points, "single.csv" using 1:6 title "Error wd" ls 4 with points
set terminal x11 1
set title "Double Precision Errors"
plot "double.csv" using 1:3 title "Error 2nd order" ls 1 with line, "double.csv" using 1:4 title "Roundoff error" ls 2 with points, "double.csv" using 1:5 title "Error 4th order" ls 3 with points, "double.csv" using 1:6 title "Error wd" ls 4 with points
set terminal x11 2
set title "Extended Precision Errors"
plot "extended.csv" using 1:3 title "Error 2nd order" ls 1 with line, "extended.csv" using 1:4 title "Roundoff error" ls 2 with points, "extended.csv" using 1:5 title "Error 4th order" ls 3 with points, "extended.csv" using 1:6 title "Error wd" ls 4 with points
pause -1
42 changes: 23 additions & 19 deletions Examples/src/FloatingPoint/FinDiff/main_findiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
#include <vector>
#if defined(SINGLE_PRECISION)
using Real = float;
std::string filename("single.dat");
std::string filename("single.csv");
#elif defined(EXTENDED_PRECISION)
using Real = long double;
std::string filename("extended.dat");
std::string filename("extended.csv");
#else
using Real = double;
std::string filename("double.dat");
std::string filename("double.csv");
#endif

// Global values (are outside any scope so I can change them in
// funct and dfunct in just one go)
constexpr Real a = 100.0;
constexpr Real b = 4.0;

// I use lambdas and I exploit the fact that constexpr are capured automatically!
// I use lambdas and I exploit the fact that constexpr are capured
// automatically!
//! \f$ f(x)=a e^{bx}\f$
auto funct= [](auto const & x){return a * std::exp(b * x);};
auto funct = [](auto const &x) { return a * std::exp(b * x); };
//! \f$ f^\prime(x)= ab e^{bx}\f$
auto dfunct= [](auto const & x){return a * b* std::exp(b * x);};

auto dfunct = [](auto const &x) { return a * b * std::exp(b * x); };

//! Tests of accuracy of finite differences
/*!
Expand All @@ -38,16 +38,16 @@ auto dfunct= [](auto const & x){return a * b* std::exp(b * x);};
int
main()
{
// Get roundoff unit
const Real u = 0.5 * std::numeric_limits<Real>::epsilon();
// Get roundoff unit (a use of auto)
const auto u = 0.5 * std::numeric_limits<Real>::epsilon();
std::cout << "Roundoff unit=" << u << std::endl;
// Read some data
GetPot ifl("data.pot");
// Initial spacing
Real h = ifl("h", 0.1);
std::cout << " Initial Spacing " << h << std::endl;
// Number of subdivisions
const unsigned int n = ifl("n", 10);
const auto n = ifl("n", 10u);
std::cout << " Number of subdivisions " << n << std::endl;
// Point where derivative is computed
const Real x = ifl("x", 3.0);
Expand All @@ -70,9 +70,9 @@ main()
spacing.reserve(n);
roundoffErrorEstimate.reserve(n);

Real constexpr half(0.5);
Real constexpr twelvth(1. / 12.);
Real constexpr twothird(2. / 3);
Real constexpr half = 0.5;
Real constexpr twelvth = 1. / 12.;
Real constexpr twothird = 2. / 3;

for(unsigned int i = 0; i < n; ++i)
{
Expand All @@ -99,14 +99,18 @@ main()
}
// Write data
std::ofstream file(filename.c_str());
file.width(15);
file<<"# h\t d2\t e2\t estim\t d4\t without_a diff\n";
auto constexpr max_prec = std::numeric_limits<Real>::max_digits10;
file << "# h,\t diff2,\t error2,\t truncation error,\t error4,\t error "
"without_a diff\n";
file.precision(
max_prec); // do this if you want the data printed in full precision!
// file.precision(8); // do this if you want the data printed in a smaller
// precision!
for(unsigned int i = 0; i < n; ++i)
{
file.width(15);
file << std::scientific<< spacing[i] << "\t" << derNumer[i] << "\t" << Error[i] << "\t"
<< roundoffErrorEstimate[i] << "\t" << Error4[i] << "\t" << Errorcx[i]
<< std::endl;
file << std::scientific << spacing[i] << ",\t" << derNumer[i] << ",\t"
<< Error[i] << ",\t" << roundoffErrorEstimate[i] << ",\t"
<< Error4[i] << ",\t" << Errorcx[i] << std::endl;
}
file.close();
}
Loading
Loading