Skip to content

Commit

Permalink
made tbb link directory consistent with the modules
Browse files Browse the repository at this point in the history
  • Loading branch information
lformaggia committed Apr 21, 2024
1 parent 5749981 commit 2aa4eaa
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Examples/src/Parallel/MPI/SendRecv/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ CXX=mpic++
CXXFLAGS+=-Wno-suggest-override -Wno-cast-function-type
DEBUG=no
parallel_cpp:
$(MAKE) CPPFLAGS+="-DCPP_PARALLEL" LDLIBS+="-ltbb" DEBUG=no
$(MAKE) CPPFLAGS+="-DCPP_PARALLEL" LDLIBS+="-L$(mkTbbLib) -ltbb" DEBUG=no
2 changes: 1 addition & 1 deletion Examples/src/Parallel/OpenMP/Sort/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ CXXFLAGS+=-fopenmp
LDFLAGS+=-fopenmp
DEBUG=no
parallel_cpp:
$(MAKE) CPPFLAGS+="-DCPP_PARALLEL" LDLIBS+="-ltbb" DEBUG=no
$(MAKE) CPPFLAGS+="-DCPP_PARALLEL" LDLIBS+="-L$(mkTbbLib) -ltbb" DEBUG=no
10 changes: 9 additions & 1 deletion Examples/src/STL/RangesAndViews/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ join_numbers(std::string_view const &csv)
| std::views::join; // [ 1, 0, 1, 1, 1, 2 ]
std::vector<int> numbers;
for(auto const &d : digits)
/*
The expression d - '0' is converting the character d to its corresponding
integer value. In ASCII, the characters '0' to '9' are represented by the
values 48 to 57. So, subtracting the ASCII value of '0' (which is 48) from
the ASCII value of a digit character gives you the integer value of that
digit. For example, if d is the character '7', then d - '0' is 55 - 48 which
equals 7.
*/
numbers.emplace_back(d - '0');
return numbers;
}
Expand Down Expand Up @@ -149,7 +157,7 @@ main()
{
// Partition a vector into odd end even
std::ostream_iterator<int> out{
std::cout, " "}; // an output iterator with a space as separator
std::cout, ", "}; // an output iterator with a space as separator
std::vector<int> v{-3, 7, 9, 0, 2, 1, 4, 3, 7, 6, 5, 8, 9};
std::cout << "Original vector: \t";
std::ranges::copy(v, out); // the use of copy to print!
Expand Down
2 changes: 1 addition & 1 deletion Examples/src/STL/Reduce/Makefile.inc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
LDLIBS+=-ltbb -L $(PACS_ROOT)/lib -lpacs
LDLIBS+=-L$(mkTbbLib) -ltbb -L $(PACS_ROOT)/lib -lpacs
export RELEASE=YES
2 changes: 1 addition & 1 deletion Examples/src/STL/Variant/main_variant.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "SimpleVisitor.hpp"
#include "manyVariants.hpp"
#include <algorithm>
#include <iostream>
#include <slgorithm>
#include <string>
#include <tuple>
#include <type_traits>
Expand Down
23 changes: 14 additions & 9 deletions Examples/src/StringLiteralsAndViews/main_stringLiterals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <locale>
#include <string>
#include <string_view> // since c++17
#include <typeinfo>
#include <typeinfo>

/*! @ brief Function to check if 'text' starts with 'prefix'
*
Expand Down Expand Up @@ -73,27 +73,32 @@ main()
// And now a little experiment (try to understand why)
std::cout << "The size of the character e is" << sizeof('e') << std::endl;
std::cout << "The size of the character è is" << sizeof('è') << std::endl;
std::cout << "Why??\n";
std::cout << "Why??\n";
// I store e and è in a char
char e_normal{'e'};
// char e_accented{'è'}; // this is a multibyte character I get a compiler
// error becouse of narrowing
char e_accented = 'è'; // Here I have implicit convertion from multibyte (int) to char
char e_accented =
'è'; // Here I have implicit convertion from multibyte (int) to char
std::cout << "Printing the characters e and è stored in a char: " << e_normal
<< " " << e_accented << std::endl;
using namespace std::string_literals;
std::string e_accented_str = "è"s; // the s not needed I can realy to implicit conversion
std::string e_accented_str =
"è"s; // the s not needed I can realy to implicit conversion
std::string e_normal_str = "e"s;
std::cout << "Printing the size of a c++ string storing e and è= "
<< e_normal_str.size() << " and " << e_accented_str.size() << std::endl;
<< e_normal_str.size() << " and " << e_accented_str.size()
<< std::endl;
std::cout << "Printing è stored in a std::string: ";
std::cout << e_accented_str[0] << "," << e_accented_str[1] << std::endl;
// Handling multybyte character strings is not easy
// I can use a wide string but the following code is not working on my PC
// Better use std::string and not single characters.

std::u8string utf8_str = u8"è";// this is a utf-8 string
wchar_t e_u8accented = utf8_str[0];// here I extract the character è
std::u8string utf8_str = u8"è"; // this is a utf-8 string
wchar_t e_u8accented = utf8_str[0]; // here I extract the character è
// that I store in a wchar_t (4 bytes long).
std::wcout << L"Printing the character è stored in a wchar_t: " << e_u8accented
<< std::endl; // but still it does not work
std::wcout << L"Printing the character è stored in a wchar_t: "
<< e_u8accented << std::endl; // but still it does not work
return 0;
}
2 changes: 1 addition & 1 deletion Examples/src/Templates/Interpolation/Makefile.inc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Necessary only if you use parallel algorithms
LDLIBS+=-ltbb
LDLIBS+=-L$(mkTbbLib) -ltbb
26 changes: 18 additions & 8 deletions Examples/src/Utilities/range_to_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,28 @@ namespace Utilities
/*!
* @brief A function that converts a range or a view to a vector
*
* Unfortunately c++ has not yet utilities to convert a range to a vector (or other containers)
* Here we provide a simple implementation
* @note More general implementation may be found in https://timur.audio/how-to-make-a-container-from-a-c20-range
* Unfortunately c++ has not yet utilities to convert a range to a vector (or
* other containers) Here we provide a simple implementation
* @note More general implementation may be found in
* https://timur.audio/how-to-make-a-container-from-a-c20-range
* @note Since c++23 we have std::ranges::to<T> to convert a view range into a
* non-view range (a container), so this utility is obsolete.
* @param r The range
* @return A vector containing the elements of the range
*/
auto ranges_to_vector(std::ranges::range auto&& r) {
auto
ranges_to_vector(std::ranges::range auto &&r)
{
// A note: you can replace auto&& above with const auto &.
// auto&& creates a forwarding reference, but no need of it here!
// Anyway, if you prefer auto&& it is fine.
std::vector<std::ranges::range_value_t<decltype(r)>> v;
// If the range has the method size() we reserve the memory to speed up the copy
if constexpr(std::ranges::sized_range<decltype(r)>) {
v.reserve(std::ranges::size(r));
}
// If the range has the method size() we reserve the memory to speed up the
// copy
if constexpr(std::ranges::sized_range<decltype(r)>)
{
v.reserve(std::ranges::size(r));
}
std::ranges::copy(r, std::back_inserter(v));
return v;
}
Expand Down

0 comments on commit 2aa4eaa

Please sign in to comment.