Changes

Jump to: navigation, search

GPU621/CamelCaseTeam

832 bytes added, 21:40, 28 July 2021
Usage of C++11 Threading - added serial version
=== Usage of C++11 Threading ===
 
==== Serial Version ====
<syntaxhighlight lang="cpp">
#include <iostream>
#include <chrono>
 
int main() {
const int iteration = 100000000;
int count = 0;
std::chrono::steady_clock::time_point ts = std::chrono::steady_clock::now();
for (count = 0; count < iteration; count++) {}
std::chrono::steady_clock::time_point te = std::chrono::steady_clock::now();
auto t = std::chrono::duration_cast<std::chrono::milliseconds>(te - ts);
std::cout << "Serial - Counting to: " << count << " - elapsed time: " << t.count() << " ms" << std::endl;
}
</syntaxhighlight>
 
<syntaxhighlight lang="cpp">
Serial - Counting to: 100000000 - elapsed time: 122 ms
</syntaxhighlight>
 
==== Parallel Version ====
<syntaxhighlight lang="cpp">
</syntaxhighlight>
The above code shows a simple demonstration on the performance of using C11 Thread library where it counts the number of iteration in a large amount. The thread library requires another library to produce a critical section in the form of mutex which allows for signals the section of the code that is under critical so that the thread must run and finish its task before rejoining with the other threads. This is similar to the OpenMP's #pragma omp critical directive but OpenMP does not require an additional library to perform this function. Taking the average of 10 runs for each number of threads, there is a slight increase in performance as the number of threads increases as well. When comparing to the serial version, the threading suffers in performance which is due to calling many headers and creation of threads.
== OpenMP Threading ==
16
edits

Navigation menu