Difference between revisions of "Team Hortons"

From CDOT Wiki
Jump to: navigation, search
(Standard Template Library)
Line 19: Line 19:
 
These algorithms provide a ''functional'' way to work on collections, and are very common in several programming languages.
 
These algorithms provide a ''functional'' way to work on collections, and are very common in several programming languages.
  
<code>
+
<pre><code>
 
#include <iostream>
 
#include <iostream>
 
#include <algorithm>
 
#include <algorithm>
Line 44: Line 44:
  
 
   cout << "== FINDING AN ELEMENT ==" << endl;
 
   cout << "== FINDING AN ELEMENT ==" << endl;
   vector<int>::iterator elFound = find_if(myVector.begin(), myVector.end(), [](int i) { return i > 4 && i % 6 == 0; });
+
   vector&lt;int>::iterator elFound = find_if(myVector.begin(), myVector.end(), [](int i) { return i > 4 && i % 6 == 0; });
 
   cout << "The element " << *elFound << " is the first that satisfies i > 4 && i % 6 == 0" << endl << endl;
 
   cout << "The element " << *elFound << " is the first that satisfies i > 4 && i % 6 == 0" << endl << endl;
  
 
   return 0;
 
   return 0;
 
}
 
}
</code>
+
</code></pre>
  
 
<pre style="color: red">
 
<pre style="color: red">
Line 56: Line 56:
 
What algorithms are provided?
 
What algorithms are provided?
 
</pre>
 
</pre>
 
  
 
== MCSTL ==
 
== MCSTL ==

Revision as of 13:23, 1 October 2017

Once upon a time there was a team. In their programs, they never used floats. They only used double doubles.


Parallelization of the C++ Standard Library: Intel Parallel STL, MCSTL, and C++17

We will do something. Eventually.


Standard Template Library

The Standard Template Library (STL) for C++ is a library that provides a set of classes and functions for C++, like iterators and vectors. The STL is divided in four parts: algorithms, containers, functors, and iterators. For this project, we will focus on the algorithms library.

The algorithms library provides many functions to be used for ranges of elements, and use iterators or pointers to navigate through them. Some of these algorithms are:

  • all_of - Tests if a condition is true for all the elements in the range
  • for_each - Applies a function to all elements in the range
  • find - Finds a value in the range
  • sort - Sorts the elements in the range

These algorithms provide a functional way to work on collections, and are very common in several programming languages.

<code>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
  vector<int> myVector = { 10, 6, 7, 8, 5, 4, 1, 2, 3, 9 };

  // Sorting the elements
  sort(myVector.begin(), myVector.end(), [](int a, int b) { return b < a; });

  cout << "== FOR EACH ==" << endl;
  for_each(myVector.begin(), myVector.end(), [](int i) { cout << "Element: " << i << endl; });
  cout << endl;


  cout << "== COUNTING NUMBERS LARGER THAN 6 ==" << endl;
  long nLt6 = count_if(myVector.begin(), myVector.end(), [](int i) { return i > 6; });
  cout << "There are " << nLt6 << " numbers larger than 6 in the vector" << endl << endl;


  cout << "== FINDING AN ELEMENT ==" << endl;
  vector<int>::iterator elFound = find_if(myVector.begin(), myVector.end(), [](int i) { return i > 4 && i % 6 == 0; });
  cout << "The element " << *elFound << " is the first that satisfies i > 4 && i % 6 == 0" << endl << endl;

  return 0;
}
</code>
What is it?
Sequential execution
What algorithms are provided?

MCSTL

What is it?
How do we install it?
Is it free?
What algorithms are provided?


Intel Parallel STL

What is it?
How do we install it?
Is it free?
What algorithms are provided?


Policy-based execution for C++17

What is it?
How do we install it?
What algorithms are provided?


Benchmark

Benchmark results: C++17, Intel Parallel STL, MCSTL


Sources


Group Members

  1. Henrique Salvadori Coelho
  2. Olga Belavina


Progress

-5%